:root {
  --bg: #16130f;
  --bg-2: #221c17;
  --ink: #1a1410;
  --paper: #f6efe4;
  --paper-2: #fffaf3;
  --gold: #e7b85a;
  --red: #d24a3a;
  --red-deep: #8e241c;
  --text: #f6efe4;
  --muted: #b3a394;
  --line: rgba(246, 239, 228, 0.14);
  --ok: #8fbf9a;
  --danger: #e07a6a;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
  --sans: "Noto Sans TC", sans-serif;
  --serif: "Noto Serif TC", serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(900px 420px at 50% -10%, rgba(231, 184, 90, 0.16), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
}

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, p { margin: 0; }

.boot, .login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.boot { color: var(--muted); }

.login-card, .panel, .card, .stage, .dialog {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow);
}

.login-card {
  width: min(440px, 100%);
  padding: 28px 24px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--gold);
  font-size: 12px;
  letter-spacing: 0.16em;
}

.login-card h1, .brand h1 {
  font-family: var(--serif);
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.lead, .fine, .muted { color: var(--muted); }
.lead { margin: 10px 0 18px; }
.fine { margin-top: 12px; font-size: 13px; }
.err { color: var(--danger); margin-top: 12px; }
.pending { color: var(--gold); margin-top: 12px; }

.app {
  width: min(980px, calc(100% - 28px));
  margin: 0 auto;
  padding: 22px 0 72px;
}

.top {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-end;
  margin-bottom: 16px;
}

.brand { display: flex; gap: 10px; align-items: center; min-width: 0; }
.brand h1 {
  font-size: clamp(1.6rem, 3vw, 2.1rem);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 52vw;
}

.back {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  font-size: 28px;
  line-height: 1;
}

.header-actions, .row, .dialog-actions, .prize-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.who { color: var(--muted); font-size: 14px; }

.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
  overflow: auto;
}

.tabs button {
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 8px 14px;
  white-space: nowrap;
}

.tabs button.on {
  color: var(--ink);
  background: var(--gold);
  font-weight: 700;
}

.btn {
  border: 0;
  border-radius: 999px;
  padding: 10px 16px;
  background: var(--paper);
  color: var(--ink);
  font-weight: 700;
}

.btn.primary { background: var(--gold); }
.btn.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
  font-weight: 500;
}
.btn.danger { background: transparent; color: var(--danger); border: 1px solid rgba(224, 122, 106, 0.45); }
.btn.wide { width: 100%; }
a.btn { text-decoration: none; display: inline-block; }
.btn:disabled { opacity: 0.45; cursor: default; }

.panel { padding: 18px; }
.stack { display: grid; gap: 12px; }

.card {
  padding: 16px 16px 14px;
  display: grid;
  gap: 6px;
}

.card h2 { margin: 0; font-size: 1.25rem; font-family: var(--serif); }
.card .meta { color: var(--muted); font-size: 14px; }

label.field, .field { display: grid; gap: 6px; }
label.field span, .field span { color: var(--muted); font-size: 13px; }

input[type="text"], input[type="number"], textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.22);
  border-radius: 12px;
  padding: 10px 12px;
  outline: none;
}

textarea { min-height: 280px; resize: vertical; line-height: 1.7; }

input:focus, textarea:focus { border-color: rgba(231, 184, 90, 0.7); }

.prize-row {
  display: grid;
  grid-template-columns: 1.1fr 1.4fr 88px auto;
  gap: 8px;
  align-items: end;
}

.stage-wrap { display: grid; gap: 14px; justify-items: center; }

.chips { display: flex; gap: 8px; width: 100%; overflow: auto; padding-bottom: 2px; }
.chip {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  border-radius: 16px;
  padding: 10px 12px;
  min-width: 108px;
  text-align: left;
}
.chip b { display: block; font-size: 15px; }
.chip span { color: var(--muted); font-size: 12px; }
.chip.on { border-color: var(--gold); background: rgba(231, 184, 90, 0.12); }
.chip.done { opacity: 0.55; }

.stage {
  width: min(760px, 100%);
  min-height: 300px;
  background: radial-gradient(90% 80% at 50% 0%, var(--paper-2), var(--paper) 72%);
  color: var(--ink);
  border: 0;
  display: grid;
  align-content: center;
  justify-items: center;
  text-align: center;
  position: relative;
  overflow: hidden;
  padding: 36px 18px 32px;
}

.kicker { letter-spacing: 0.18em; font-size: 13px; color: #8a6a32; margin-bottom: 8px; }
.stage-name {
  font-family: var(--serif);
  font-weight: 700;
  font-size: clamp(42px, 8vw, 92px);
  line-height: 1.15;
  letter-spacing: 0.06em;
  max-width: 100%;
  word-break: break-word;
}
.stage-sub { margin-top: 10px; color: #6d5b48; }
.stage.spinning .stage-name { animation: flicker 0.12s linear infinite; }
.stage.landed .stage-name { animation: land 420ms cubic-bezier(.2, 1.4, .4, 1); }

@keyframes flicker { 50% { opacity: 0.55; } }
@keyframes land {
  from { transform: scale(0.86); filter: blur(2px); }
  to { transform: none; filter: none; }
}

.burst { position: absolute; inset: 0; pointer-events: none; }
.burst i {
  position: absolute;
  left: 50%;
  top: 42%;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  opacity: 0;
}
.burst.go i { animation: burst 720ms ease-out forwards; }
@keyframes burst {
  0% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(calc(-50% + var(--x)), calc(-50% + var(--y))) rotate(160deg) scale(0.6); }
}

.draw-btn {
  width: min(100%, 440px);
  border: 0;
  border-radius: 999px;
  padding: 18px 24px;
  background: radial-gradient(120% 140% at 50% 0%, #f07164, var(--red) 52%, var(--red-deep));
  color: white;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  box-shadow: 0 14px 32px rgba(210, 74, 58, 0.32);
}
.draw-btn:disabled {
  background: #3a332c;
  color: #8c8174;
  box-shadow: none;
}

.keyhint { color: var(--muted); font-size: 13px; }
.check { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 14px; }
.check input { accent-color: var(--gold); }

.recent { width: min(760px, 100%); color: var(--muted); font-size: 14px; }
.recent b { color: var(--text); font-weight: 600; }

.winner {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.winner strong { font-family: var(--serif); font-size: 1.2rem; }
.group { margin-top: 8px; }
.group h3 { margin: 16px 0 0; font-size: 1rem; color: var(--gold); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  background: var(--paper);
  color: var(--ink);
  border-radius: 999px;
  padding: 10px 16px;
  box-shadow: var(--shadow);
  z-index: 20;
  max-width: min(520px, calc(100% - 24px));
}
.toast.bad { background: #3a221e; color: #ffd2cb; }

.scrim {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.46);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 30;
}
.dialog { width: min(420px, 100%); padding: 18px; background: #2a241e; }
.dialog p { margin-bottom: 12px; }
.dialog-actions { justify-content: flex-end; margin-top: 14px; }

.join-box {
  width: min(760px, 100%);
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 14px;
  align-items: center;
  background: var(--paper);
  color: var(--ink);
  border-radius: 22px;
  padding: 14px;
}
.join-box canvas { width: 168px; height: 168px; border-radius: 12px; background: #fffaf3; }
.join-box .btn.ghost { color: var(--ink); border-color: rgba(26, 20, 16, 0.28); }
.code-lg {
  font-family: var(--serif);
  font-size: 2rem;
  letter-spacing: 0.18em;
  margin: 2px 0;
}
.join-url { word-break: break-all; color: #6d5b48; font-size: 13px; }
.phone-names { color: #6d5b48; font-size: 13px; margin-top: 6px; }

.guest {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
  padding: 18px 16px 28px;
}
.guest-top h1 {
  font-family: var(--serif);
  font-size: clamp(1.8rem, 7vw, 2.6rem);
  margin-top: 2px;
}
.guest-me { color: var(--gold); margin-top: 4px; }
.guest-stage { min-height: 42vh; }
.tap {
  width: 100%;
  min-height: 46vh;
  border: 0;
  border-radius: 28px;
  background: #3a332c;
  color: #d9cbb8;
  font-size: clamp(2rem, 10vw, 4rem);
  font-weight: 700;
  letter-spacing: 0.12em;
}
.tap.go {
  background: radial-gradient(120% 140% at 50% 0%, #ffe08a, #e7b85a 42%, #d24a3a);
  color: #1a1410;
  animation: pulse 0.35s ease-in-out infinite;
}
.tap:disabled { opacity: 0.85; }
@keyframes pulse { 50% { transform: scale(0.985); } }
.name-form { display: grid; gap: 12px; }
.name-form input { font-size: 1.4rem; padding: 16px; background: #2a241e; }

body.project .tabs,
body.project .who,
body.project #renameBtn,
body.project .keyhint,
body.project .recent,
body.project .join-box { display: none; }
body.project .stage { min-height: 62vh; }
body.project .stage-name { font-size: clamp(64px, 12vw, 132px); }
body.busy .tabs button,
body.busy #projectBtn { pointer-events: none; }

@media (max-width: 720px) {
  .top { align-items: flex-start; }
  .header-actions { justify-content: flex-end; }
  .prize-row { grid-template-columns: 1fr 1fr; }
  .prize-row .span-2 { grid-column: 1 / -1; }
  .brand h1 { max-width: 70vw; }
  .join-box { grid-template-columns: 1fr; justify-items: center; text-align: center; }
}

@media (pointer: coarse) {
  .keyhint { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .stage.spinning .stage-name,
  .stage.landed .stage-name,
  .burst.go i,
  .tap.go { animation: none; }
}
