/* ============================================================
   style.css — steampunk brass UI
   ============================================================ */

:root {
  --bg0: #14100a;
  --bg1: #241a10;
  --panel: #2a1d12;
  --panel2: #342416;
  --brass: #b08d57;
  --gold: #c9a227;
  --copper: #c87533;
  --cream: #f5e6c4;
  --ink: #1c130a;
  --danger: #a33c2a;
  --serif: Georgia, "Times New Roman", "Microsoft YaHei", serif;
  --sans: "Segoe UI", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; height: 100%;
  font-family: var(--sans);
  color: var(--cream);
  background: radial-gradient(120% 90% at 50% 30%, var(--bg1) 0%, var(--bg0) 70%);
  overflow: hidden;
}

body { display: flex; flex-direction: column; }

.hidden { display: none !important; }
.spacer { flex: 1; }

/* ---------- bars ---------- */

#topbar, #modebar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 14px;
  background: linear-gradient(180deg, #3a2917, #2a1d12);
  border-bottom: 2px solid #6e5226;
  flex: 0 0 auto;
}

#modebar { background: linear-gradient(180deg, #2e2013, #241a10); padding: 6px 14px; }

.brand {
  font-family: var(--serif);
  font-size: 1.25rem; font-weight: bold;
  color: var(--gold);
  letter-spacing: 1px;
  text-shadow: 0 1px 0 #000;
  white-space: nowrap;
}

button, .filebtn {
  font-family: var(--serif);
  font-size: 1rem;
  color: var(--ink);
  background: linear-gradient(180deg, #d9b46a, #a87f3f);
  border: 1px solid #6e5226;
  border-radius: 8px;
  padding: 8px 16px;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.35), 0 2px 4px rgba(0,0,0,.5);
  white-space: nowrap;
}
button:hover, .filebtn:hover { filter: brightness(1.1); }
button:active { transform: translateY(1px); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: linear-gradient(180deg, #e9c87e, #b8923f); font-weight: bold; }
button.danger { background: linear-gradient(180deg, #c4664f, #8e3a28); color: #fff2e8; }

select, input, textarea {
  font-family: var(--sans);
  font-size: 1rem;
  color: var(--cream);
  background: #1d140c;
  border: 1px solid #6e5226;
  border-radius: 8px;
  padding: 8px 10px;
}
select { max-width: 34vw; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--gold); }

.segmented { display: flex; }
.segmented button {
  border-radius: 0; margin: 0; border-right-width: 0;
  background: linear-gradient(180deg, #4a3621, #382818);
  color: #cdb48a;
}
.segmented button:first-child { border-radius: 8px 0 0 8px; }
.segmented button:last-child { border-radius: 0 8px 8px 0; border-right-width: 1px; }
.segmented button.sel {
  background: linear-gradient(180deg, #d9b46a, #a87f3f);
  color: var(--ink); font-weight: bold;
}

#countWrap { display: flex; align-items: center; gap: 8px; font-family: var(--serif); }
#countInput { width: 72px; text-align: center; font-size: 1.1rem; }

#remainBadge {
  font-family: var(--serif);
  color: var(--gold);
  border: 1px dashed #6e5226;
  border-radius: 8px;
  padding: 6px 12px;
}

/* ---------- stage ---------- */

#stage { position: relative; flex: 1 1 auto; min-height: 0; }
#canvasWrap, #canvasWrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
#canvasWrap { z-index: 1; }   /* sits above the picked-names panel */
#btnSpin, #hint, #toast, #groupTray { z-index: 6; }

#btnSpin {
  position: absolute;
  left: 50%; bottom: 4vh;
  transform: translateX(-50%);
  width: 128px; height: 128px;
  border-radius: 50%;
  font-size: 1.6rem; font-weight: bold; letter-spacing: 2px;
  color: var(--ink);
  background: radial-gradient(circle at 35% 30%, #f2d894, #c9962f 55%, #8a6420);
  border: 4px solid #6e5226;
  box-shadow: 0 0 28px rgba(201,162,39,.45), inset 0 2px 6px rgba(255,255,255,.5), 0 6px 14px rgba(0,0,0,.6);
}
#btnSpin:hover { box-shadow: 0 0 40px rgba(201,162,39,.7), inset 0 2px 6px rgba(255,255,255,.5), 0 6px 14px rgba(0,0,0,.6); }
#btnSpin:active { transform: translateX(-50%) scale(.96); }

#hint {
  position: absolute; left: 50%; top: 16px;
  transform: translateX(-50%);
  background: rgba(20, 12, 4, .9);
  border: 1px solid var(--gold);
  border-radius: 10px;
  padding: 10px 20px;
  font-family: var(--serif); font-size: 1.1rem;
  color: var(--cream);
  opacity: 0; pointer-events: none;
  transition: opacity .3s;
  max-width: 80vw; text-align: center;
}
#hint.show { opacity: 1; }

#toast {
  position: absolute; left: 50%; top: 12vh;
  transform: translateX(-50%);
  background: rgba(26, 16, 6, .92);
  border: 2px solid var(--gold);
  border-radius: 12px;
  padding: 14px 30px;
  font-family: var(--serif); font-size: clamp(1.4rem, 4vw, 2.4rem);
  color: var(--gold);
  opacity: 0; pointer-events: none;
  transition: opacity .2s;
}
#toast.show { opacity: 1; }

/* ---------- overlays ---------- */

.overlay {
  position: fixed; inset: 0; z-index: 40;
  display: flex; align-items: center; justify-content: center; flex-direction: column;
  background: rgba(8, 5, 2, .82);
  backdrop-filter: blur(3px);
}

.winner-card {
  text-align: center;
  padding: 4vh 6vw;
  border: 3px double var(--gold);
  border-radius: 18px;
  background:
    radial-gradient(140% 120% at 50% 0%, #3a2a16 0%, #221709 70%);
  box-shadow: 0 0 60px rgba(201,162,39,.35);
  animation: pop .45s cubic-bezier(.2, 1.6, .4, 1);
  max-width: 92vw; max-height: 86vh; overflow: auto;
}
@keyframes pop { from { transform: scale(.6); opacity: 0; } }

.winner-label {
  font-family: var(--serif);
  letter-spacing: 8px;
  color: var(--copper);
  font-size: clamp(1rem, 2.5vw, 1.6rem);
  margin-bottom: 1vh;
}

#winnerNames div {
  font-family: var(--serif);
  font-weight: bold;
  font-size: clamp(3rem, 11vw, 8.5rem);
  line-height: 1.15;
  background: linear-gradient(180deg, #f7e7b8, #c9a227 75%, #8a6420);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 4px 18px rgba(0,0,0,.55);
}
#winnerNames.many div { font-size: clamp(1.8rem, 6vw, 4rem); }

.winner-hint {
  margin-top: 2.5vh;
  color: #9b8260;
  font-style: italic;
}

/* groups board */

#groupsBoard {
  display: grid;
  grid-template-columns: repeat(var(--cols, 4), minmax(180px, 1fr));
  gap: 18px;
  padding: 3vh 3vw;
  width: 100%;
  max-width: 1500px;
  max-height: 80vh;
  overflow: auto;
}

.group-panel {
  background: linear-gradient(180deg, #32271a, #241a10);
  border: 2px solid #6e5226;
  border-radius: 14px;
  padding: 12px 14px;
  min-height: 30vh;
  box-shadow: 0 4px 16px rgba(0,0,0,.5);
}
.group-panel h3 {
  margin: 0 0 10px;
  font-family: var(--serif);
  color: var(--gold);
  border-bottom: 1px solid #6e5226;
  padding-bottom: 6px;
  display: flex; justify-content: space-between; align-items: center;
  font-size: 1.3rem;
}
.group-panel .gcount {
  font-size: .9rem; color: var(--copper);
  border: 1px solid #6e5226; border-radius: 10px; padding: 1px 9px;
}
.group-panel ul { list-style: none; margin: 0; padding: 0; }
.group-panel li {
  font-family: var(--serif);
  font-size: clamp(1.1rem, 2.2vw, 1.7rem);
  color: var(--cream);
  background: rgba(201,162,39,.1);
  border: 1px solid rgba(201,162,39,.35);
  border-radius: 8px;
  padding: 6px 12px;
  margin: 6px 0;
}
.group-panel li.land { transition: transform .45s cubic-bezier(.2, 1.3, .4, 1), opacity .3s; }

.big-btn { margin-top: 2.5vh; font-size: 1.3rem; padding: 12px 44px; }
#btnGroupsDone {
  position: absolute; bottom: 3.5vh; left: 50%;
  transform: translateX(-50%); z-index: 30;
}

/* ---------- side panels on the stage ---------- */

/* (already-picked names are now 3D brass plaques inside the scene) */

#groupTray {
  position: absolute;
  top: 14px; right: 14px;
  background: rgba(30, 20, 9, .88);
  border: 2px solid #6e5226;
  border-radius: 12px;
  padding: 10px 16px;
  max-width: 280px;
  box-shadow: 0 4px 18px rgba(0,0,0,.55);
}
#groupTray h4 {
  margin: 0 0 6px;
  font-family: var(--serif);
  color: var(--copper);
  letter-spacing: 1px;
  font-size: 1rem;
}
#trayList { margin: 0; padding-left: 24px; }
#trayList li {
  font-family: var(--serif);
  font-size: 1.5rem;
  color: var(--gold);
  margin: 3px 0;
}

/* manual pick modal */
.chipbox {
  display: flex; flex-wrap: wrap; gap: 7px;
  max-height: 26vh; overflow: auto;
  margin-bottom: 14px;
  padding: 8px;
  border: 1px solid #4a3621; border-radius: 8px;
}
.chip.pick { cursor: pointer; }
.chip.pick:hover { filter: brightness(1.25); }
.chip.pick.sel {
  background: linear-gradient(180deg, #d9b46a, #a87f3f);
  color: var(--ink); font-weight: bold;
  border-color: var(--gold);
}
.chip.pick.out { opacity: .65; border-style: dashed; }

/* name tag flying from the wheel to the picked panel */
.float-tag {
  position: fixed; left: 0; top: 0; z-index: 70;
  pointer-events: none;
  font-family: var(--serif);
  font-weight: bold;
  font-size: 1.7rem;
  color: var(--ink);
  background: linear-gradient(180deg, #e9c87e, #b8923f);
  border: 2px solid #6e5226;
  border-radius: 10px;
  padding: 8px 22px;
  box-shadow: 0 8px 28px rgba(0,0,0,.6);
  will-change: transform;
}
.float-tag.fly {
  transition: transform .95s cubic-bezier(.3, .7, .25, 1);
}

/* ---------- card shuffle (divide-all) ---------- */

#deckArea {
  position: fixed; inset: 0; z-index: 1;
  perspective: 1300px;
}
.scard {
  position: absolute; left: 0; top: 0;
  height: 40px; width: 150px;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--serif);
  font-size: 1.05rem;
  color: var(--cream);
  white-space: nowrap;
  overflow: hidden;
  padding: 2px 8px;
  background: linear-gradient(160deg, #5a4226, #392a16);
  border: 1.5px solid var(--gold);
  border-radius: 9px;
  box-shadow: 0 4px 12px rgba(0,0,0,.55);
  will-change: transform;
  transform-style: preserve-3d;
}
.scard.anim { transition: transform .85s cubic-bezier(.35, .75, .3, 1), opacity .4s, width .4s; }

.gcol-label {
  position: absolute;
  transform: translate(-50%, 0);
  font-family: var(--serif);
  font-weight: bold;
  font-size: 1.45rem;
  color: var(--gold);
  text-shadow: 0 2px 6px #000;
  border-bottom: 2px solid #6e5226;
  padding: 0 18px 3px;
}

.hintrow { margin-bottom: 8px; }
button.small { font-size: .85rem; padding: 4px 12px; }

/* ---------- history ---------- */

#historyList {
  list-style: none; margin: 0 0 14px; padding: 0;
  max-height: 56vh; overflow: auto;
  border: 1px solid #4a3621; border-radius: 8px;
}
.hentry { padding: 10px 14px; border-bottom: 1px solid #3a2a18; }
.hhead { display: flex; gap: 10px; align-items: center; margin-bottom: 4px; }
.htime { color: #9b8260; font-size: .85rem; }
.hmode {
  font-family: var(--serif);
  color: var(--ink);
  background: linear-gradient(180deg, #d9b46a, #a87f3f);
  border-radius: 9px;
  padding: 1px 10px;
  font-size: .85rem;
}
.hcls { color: var(--copper); font-size: .9rem; }
.hnames { color: var(--cream); font-size: 1.02rem; line-height: 1.45; }
.hgroup { padding: 2px 0; }
.hgroup b { color: var(--gold); font-family: var(--serif); margin-right: 6px; }

#winnerNames div { white-space: nowrap; }

/* pinball sorting machine */

#pinfallOverlay { background: rgba(8, 5, 2, .94); }
#pinfallCanvas { position: absolute; inset: 0; width: 100%; height: 100%; }
#btnPinfallDone {
  position: absolute; top: 2.5vh; bottom: auto; left: 50%;
  transform: translateX(-50%); z-index: 2;
}

/* ---------- modals ---------- */

.modal {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  background: rgba(8, 5, 2, .7);
}

.modal-card {
  background: linear-gradient(180deg, #342416, #241a10);
  border: 2px solid #8a6d3b;
  border-radius: 16px;
  padding: 22px 26px;
  width: min(480px, 94vw);
  max-height: 90vh; overflow: auto;
  box-shadow: 0 10px 50px rgba(0,0,0,.7);
}
.modal-card.wide { width: min(900px, 94vw); }
.modal-card h2 {
  margin: 0 0 14px;
  font-family: var(--serif);
  color: var(--gold);
  border-bottom: 1px solid #6e5226;
  padding-bottom: 8px;
}
.modal-card h3 { font-family: var(--serif); color: var(--copper); margin: 4px 0 8px; }

.manage-grid { display: grid; grid-template-columns: 230px 1fr; gap: 20px; }
@media (max-width: 720px) { .manage-grid { grid-template-columns: 1fr; } }

#savedList {
  list-style: none; margin: 0 0 10px; padding: 0;
  max-height: 38vh; overflow: auto;
  border: 1px solid #4a3621; border-radius: 8px;
}
#savedList li {
  padding: 9px 12px; cursor: pointer;
  border-bottom: 1px solid #3a2a18;
  font-family: var(--serif);
}
#savedList li:hover { background: #3a2a18; }
#savedList li.sel { background: #4a3621; color: var(--gold); }

.field { display: block; margin-bottom: 12px; font-family: var(--serif); color: var(--copper); }
.field input, .field textarea, .field select { display: block; width: 100%; margin-top: 5px; }
.field textarea { resize: vertical; min-height: 110px; }

.check { display: block; margin: 14px 0; font-size: 1.05rem; cursor: pointer; }
.check input { width: 20px; height: 20px; vertical-align: -4px; margin-right: 8px; }

.hintline { color: #9b8260; font-style: italic; margin-bottom: 8px; min-height: 1.2em; }

#chips {
  display: flex; flex-wrap: wrap; gap: 7px;
  max-height: 26vh; overflow: auto;
  margin-bottom: 14px;
}
.chip {
  background: #45331d;
  border: 1px solid #8a6d3b;
  border-radius: 16px;
  padding: 4px 10px;
  font-size: .95rem;
  cursor: default;
  user-select: none;
}
.chip b { color: var(--copper); margin-left: 7px; cursor: pointer; font-weight: bold; }
.chip b:hover { color: #ff8c5a; }
.chip.dup { border-color: #c4664f; background: #4d2418; }

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.filebtn { position: relative; display: inline-block; }
.filebtn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

input[type="range"] { accent-color: var(--gold); width: 100%; padding: 0; }
#durLabel { color: var(--gold); margin-left: 8px; }
