:root {
  --primary: #e67e22;
  --secondary: #2c3e50;
  --accent: #27ae60;
  --bg: #14161c;
  --bg-2: #1c1f28;
  --card: #232733;
  --card-2: #2b2f3d;
  --text: #eef1f6;
  --muted: #97a0b4;
  --danger: #e74c3c;
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  height: 100%;
  overscroll-behavior-y: none;
}

#app { min-height: 100%; }

.screen {
  min-height: 100vh;
  padding: calc(16px + var(--safe-top)) 18px calc(24px + var(--safe-bottom));
  max-width: 640px;
  margin: 0 auto;
  animation: fade .25s ease;
}
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- Top bars ---------- */
.topbar, .tabbar { display: flex; align-items: center; gap: 8px; }
.topbar { margin-bottom: 16px; }
.topbar h2 { font-size: 1.15rem; flex: 1; text-align: center; }
.topbar .spacer, .icon-btn { width: 40px; }
.icon-btn {
  background: var(--card); color: var(--text); border: none;
  width: 40px; height: 40px; border-radius: 12px; font-size: 1.1rem; cursor: pointer;
}
.settings-gear { position: absolute; top: calc(14px + var(--safe-top)); right: 18px; }

/* ---------- Home ---------- */
.home { position: relative; }
.hero { text-align: center; padding: 40px 0 24px; }
.hero-logo { font-size: 4rem; }
.hero h1 { font-size: 2rem; margin-top: 8px; }
.tagline { color: var(--muted); margin-top: 6px; }

.home-actions { display: grid; gap: 14px; margin-top: 10px; }
.big-card {
  display: flex; flex-direction: column; gap: 4px; align-items: flex-start;
  text-align: left; padding: 22px; border: none; cursor: pointer;
  border-radius: var(--radius); color: #fff; box-shadow: 0 8px 24px rgba(0,0,0,.3);
}
.big-card:disabled { opacity: .5; }
.big-card.create { background: linear-gradient(135deg, var(--primary), #d35400); }
.big-card.join { background: linear-gradient(135deg, var(--accent), #1e8449); }
.bc-icon { font-size: 2rem; }
.bc-title { font-size: 1.25rem; font-weight: 700; }
.bc-sub { font-size: .85rem; opacity: .9; }

.resume-card, .hunt-row {
  width: 100%; margin-top: 14px; background: var(--card); border: none; color: var(--text);
  padding: 16px; border-radius: 12px; cursor: pointer; text-align: left;
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
}
.section { margin-top: 26px; }
.section h3 { margin-bottom: 10px; color: var(--muted); font-size: .95rem; }
.my-hunts { display: grid; gap: 8px; }
.hr-code { color: var(--primary); font-weight: 700; font-size: .8rem; }

/* ---------- Banners ---------- */
.banner { padding: 12px 14px; border-radius: 12px; margin: 10px 0; font-size: .92rem; }
.banner.warn { background: #3a2e18; border: 1px solid #7a5a1e; }
.banner.ok { background: #17351f; border: 1px solid #256b3a; }
.banner.err { background: #3a1d1d; border: 1px solid #7a2e2e; }
.banner.hint-banner { background: #2a2f45; border: 1px solid #465; }
.banner p { margin: 6px 0; color: var(--muted); }

/* ---------- Forms ---------- */
.form { display: flex; flex-direction: column; gap: 6px; }
.form label { font-weight: 600; margin-top: 12px; font-size: .9rem; }
.form input, .form textarea, .form select, .ans {
  width: 100%; background: var(--card); border: 1px solid #333a49; color: var(--text);
  padding: 13px; border-radius: 12px; font-size: 1rem; font-family: inherit;
}
.form input[type=color] { height: 46px; padding: 4px; }
.form .hint, .hint { color: var(--muted); font-size: .82rem; }
.colors { display: flex; gap: 10px; margin-top: 8px; }
.colors > div { flex: 1; display: flex; flex-direction: column; }

.btn {
  border: none; border-radius: 12px; padding: 14px; font-size: 1rem; font-weight: 600;
  cursor: pointer; margin-top: 12px; color: #fff; background: var(--card-2);
}
.btn.primary { background: linear-gradient(135deg, var(--primary), #d35400); }
.btn.ghost { background: transparent; border: 1px solid #3a4150; color: var(--text); }
.btn.danger { color: #fff; background: var(--danger); }
.btn.danger.ghost { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn.small { padding: 8px 14px; font-size: .85rem; display: inline-block; width: auto; }
.btn.tiny { padding: 7px 10px; font-size: .8rem; margin-top: 8px; width: auto; }
.btn.big { padding: 18px; font-size: 1.1rem; }
.btn:disabled { opacity: .5; }

.test-result { margin-top: 10px; font-size: .9rem; }
.test-result.ok { color: var(--accent); }
.test-result.err { color: var(--danger); }
.loading { color: var(--muted); text-align: center; padding: 30px; }
.empty { color: var(--muted); text-align: center; padding: 24px; }

/* ---------- Editor tabs ---------- */
.tabbar { overflow-x: auto; gap: 6px; margin-bottom: 16px; padding-bottom: 4px; }
.tab {
  flex: 0 0 auto; background: var(--card); border: none; color: var(--muted);
  padding: 10px 14px; border-radius: 20px; font-size: .85rem; cursor: pointer; white-space: nowrap;
}
.tab.active { background: var(--primary); color: #fff; }

/* ---------- Steps editor ---------- */
.step-list { display: grid; gap: 8px; margin-bottom: 14px; }
.step-item { display: flex; align-items: center; gap: 10px; background: var(--card); padding: 12px; border-radius: 12px; }
.step-num { width: 26px; height: 26px; background: var(--primary); border-radius: 50%; display: grid; place-items: center; font-size: .8rem; font-weight: 700; }
.step-info { flex: 1; display: flex; flex-direction: column; }
.step-info small { color: var(--muted); }
.step-ctrls button { background: var(--card-2); border: none; color: var(--text); width: 32px; height: 32px; border-radius: 8px; margin-left: 4px; cursor: pointer; }
.step-ctrls .del { color: var(--danger); }

/* ---------- Overlay / sheet ---------- */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: flex-end; z-index: 50; }
.sheet {
  background: var(--bg-2); width: 100%; max-width: 640px; margin: 0 auto;
  max-height: 92vh; border-radius: 20px 20px 0 0; display: flex; flex-direction: column;
  padding-bottom: var(--safe-bottom); animation: slideup .25s ease;
}
@keyframes slideup { from { transform: translateY(100%); } to { transform: none; } }
.sheet-head { display: flex; align-items: center; padding: 16px; border-bottom: 1px solid #2a2f3d; }
.sheet-head h3 { flex: 1; }
.sheet .form { padding: 16px; overflow-y: auto; }
.sheet-foot { display: flex; gap: 10px; padding: 14px 16px; border-top: 1px solid #2a2f3d; }
.sheet-foot .btn { flex: 1; margin: 0; }

.list-editor { display: grid; gap: 6px; }
.lrow, .prow { display: flex; gap: 6px; align-items: center; }
.lrow input, .prow input { flex: 1; }
.rm { background: var(--card-2); border: none; color: var(--danger); width: 40px; border-radius: 10px; cursor: pointer; }
.pairs, .subq { display: grid; gap: 10px; }
.sqrow { background: var(--card); padding: 10px; border-radius: 12px; display: grid; gap: 6px; }
.rm-subq { background: none; border: none; color: var(--danger); font-size: .8rem; cursor: pointer; text-align: left; }

/* ---------- Share ---------- */
.share { text-align: center; }
.share-lead { color: var(--muted); margin-bottom: 16px; }
.qr-wrap { display: flex; justify-content: center; padding: 16px; background: #fff; border-radius: 16px; width: fit-content; margin: 0 auto; }
.qr-wrap canvas { display: block; }
.code-big { font-size: 2.4rem; font-weight: 800; letter-spacing: 6px; color: var(--primary); margin: 18px 0 6px; }
.share-link { color: var(--muted); word-break: break-all; font-size: .85rem; }
.share-btns { display: grid; gap: 8px; margin-top: 18px; }

/* ---------- Monitor ---------- */
.monitor { display: grid; gap: 12px; }
.team-card { background: var(--card); padding: 14px; border-radius: 12px; }
.team-head { display: flex; justify-content: space-between; margin-bottom: 8px; }
.progress { height: 8px; background: var(--card-2); border-radius: 8px; overflow: hidden; }
.progress-bar { height: 100%; background: var(--accent); transition: width .3s; }
.dots { display: flex; flex-wrap: wrap; gap: 5px; margin: 10px 0; }
.dot { width: 12px; height: 12px; border-radius: 50%; background: var(--card-2); }
.dot.on { background: var(--accent); }

/* ---------- Player: join ---------- */
.join-illus { font-size: 3rem; text-align: center; margin: 10px 0; }
.code-input { text-transform: uppercase; letter-spacing: 4px; text-align: center; font-size: 1.4rem; font-weight: 700; }
.found { margin-top: 20px; background: var(--card); padding: 16px; border-radius: 14px; }
.found h3 { color: var(--primary); }
.steps-count { color: var(--muted); margin: 6px 0 10px; }

/* ---------- Player: hub ---------- */
.hub-progress { margin-bottom: 16px; }
.hub-progress span { color: var(--muted); font-size: .85rem; }
.hub-progress .progress { margin-top: 6px; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tile {
  background: var(--card); border: none; color: var(--text); border-radius: 14px;
  padding: 18px 12px; display: flex; flex-direction: column; align-items: center; gap: 6px; cursor: pointer;
  min-height: 120px; justify-content: center; text-align: center;
}
.tile.done { background: linear-gradient(135deg, #1e3a2a, #15251b); }
.tile-icon { font-size: 1.8rem; }
.tile-num { font-size: .75rem; color: var(--muted); }
.tile-title { font-size: .9rem; font-weight: 600; }

/* ---------- Player: step ---------- */
.step-type { color: var(--muted); font-size: .85rem; margin-bottom: 4px; }
.step-body h2 { margin-bottom: 10px; }
.step-img { width: 100%; border-radius: 14px; margin: 10px 0; }
.step-desc { line-height: 1.5; margin-bottom: 14px; white-space: pre-wrap; }
.ans { margin-bottom: 8px; }
.choice { display: flex; align-items: center; gap: 10px; background: var(--card); padding: 13px; border-radius: 12px; margin-bottom: 8px; cursor: pointer; }
.choice input { width: auto; }
.match-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.match-row span { flex: 1; }
.match-row select { flex: 1; }
.order-list { display: grid; gap: 8px; }
.order-item { display: flex; justify-content: space-between; align-items: center; background: var(--card); padding: 12px 14px; border-radius: 12px; }
.ord-ctrls button { background: var(--card-2); border: none; color: var(--text); width: 34px; height: 34px; border-radius: 8px; margin-left: 4px; }
.subq-play { background: var(--card); padding: 12px; border-radius: 12px; margin-bottom: 10px; }
.subq-play p { margin-bottom: 6px; }

/* ---------- Final ---------- */
.final { text-align: center; }
.confetti { font-size: 4rem; margin: 30px 0 10px; }
.final h1 { color: var(--primary); }
.final-img { width: 100%; border-radius: 16px; margin: 16px 0; }
.final-msg { line-height: 1.6; margin: 16px 0; white-space: pre-wrap; }
.final-stats { display: flex; justify-content: center; gap: 20px; color: var(--muted); margin: 14px 0; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: calc(24px + var(--safe-bottom)); left: 50%; transform: translateX(-50%) translateY(100px);
  background: #2b2f3d; color: #fff; padding: 12px 20px; border-radius: 12px; font-size: .9rem;
  opacity: 0; transition: all .3s; z-index: 100; max-width: 90%; text-align: center;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
.toast.err { background: var(--danger); }
