/* Treasure — mobile-first */
:root {
  --bg: #0f1220;
  --bg2: #171b30;
  --bg-glow: #232a52;
  --card: #1e2340;
  --card2: #262c52;
  --text: #eef0ff;
  --muted: #9aa1c9;
  --accent: #f5b942;
  --accent2: #ffd97a;
  --ok: #3ecf8e;
  --bad: #ff5d6c;
  --border: #2c3468;
  --border2: #333c74;
  --border3: #3a4384;
  --shadow: rgba(0, 0, 0, .25);
  --radius: 16px;
  font-size: 16px;
}

html[data-theme="light"] {
  --bg: #eef1f9;
  --bg2: #ffffff;
  --bg-glow: #dbe3f8;
  --card: #ffffff;
  --card2: #e9edf9;
  --text: #1d2342;
  --muted: #5d6588;
  --accent: #f0ad2c;
  --accent2: #a87a0e;
  --ok: #1f9e68;
  --bad: #d93a4c;
  --border: #d8ddf0;
  --border2: #c6cde8;
  --border3: #b4bce0;
  --shadow: rgba(45, 55, 110, .14);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: radial-gradient(1200px 800px at 50% -10%, var(--bg-glow) 0%, var(--bg) 60%);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

#app { max-width: 720px; margin: 0 auto; padding: 20px 16px 48px; }

h1 { font-size: 1.7rem; margin-bottom: 4px; }
h2 { font-size: 1.25rem; margin-bottom: 12px; }
.sub { color: var(--muted); margin-bottom: 20px; font-size: .95rem; }

.logo { font-size: 2rem; text-align: center; margin: 24px 0 4px; letter-spacing: .5px; }
.logo .key { display: inline-block; transform: rotate(-20deg); }
.tagline { text-align: center; color: var(--muted); margin-bottom: 28px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: 0 8px 30px var(--shadow);
}

label { display: block; font-size: .85rem; color: var(--muted); margin: 12px 0 6px; }

input[type=text], input[type=password], input[type=tel], textarea, select {
  width: 100%;
  background: var(--bg2);
  color: var(--text);
  border: 1.5px solid var(--border2);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 1rem;
  outline: none;
  transition: border-color .15s, box-shadow .15s, background .2s;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(245,185,66,.15);
}
textarea { resize: vertical; min-height: 70px; }

input.wrong {
  border-color: var(--bad);
  background: rgba(255,93,108,.08);
  animation: field-shake .4s;
}
input.right { border-color: var(--ok); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 14px 20px;
  margin-top: 16px;
  border: none;
  border-radius: 12px;
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  background: linear-gradient(135deg, var(--accent), #e89f1e);
  color: #241a02;
  transition: transform .1s, filter .15s, opacity .2s;
  touch-action: manipulation;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.secondary { background: var(--card2); color: var(--text); border: 1px solid var(--border3); }
.btn.small { width: auto; padding: 8px 14px; font-size: .85rem; margin-top: 0; }
.btn.danger { background: none; border: 1px solid var(--bad); color: var(--bad); }
.btn.ghost { background: none; border: none; color: var(--muted); width: auto; }

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.mt { margin-top: 16px; }
.center { text-align: center; }
.muted { color: var(--muted); font-size: .9rem; }
.error-text { color: var(--bad); font-size: .9rem; margin-top: 10px; min-height: 1.2em; }

.pin-input {
  font-size: 1.6rem !important;
  text-align: center;
  letter-spacing: .5em;
  font-variant-numeric: tabular-nums;
}

/* --- tabs --- */
.tabs { display: flex; gap: 6px; margin-bottom: 16px; background: var(--bg2); padding: 5px; border-radius: 12px; }
.tabs button {
  flex: 1; padding: 10px; border: none; border-radius: 9px;
  background: none; color: var(--muted); font-size: .95rem; font-weight: 600; cursor: pointer;
}
.tabs button.active { background: var(--card2); color: var(--text); }

/* --- дашборд --- */
.room-card { display: flex; flex-direction: column; gap: 10px; }
.room-card .title-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.room-card h3 { font-size: 1.1rem; }
.badge { font-size: .75rem; padding: 3px 10px; border-radius: 999px; white-space: nowrap; }
.badge.on { background: rgba(62,207,142,.15); color: var(--ok); }
.badge.off { background: rgba(154,161,201,.15); color: var(--muted); }
.pin-chip {
  font-variant-numeric: tabular-nums;
  background: var(--bg2); border: 1px dashed var(--border3);
  padding: 6px 12px; border-radius: 10px; letter-spacing: .2em; font-weight: 700;
  cursor: pointer;
}
.stats-line { color: var(--muted); font-size: .85rem; }

/* --- конструктор --- */
.field-block { position: relative; margin-bottom: 12px; }
.field-block .num {
  position: absolute; top: -8px; left: 10px;
  background: var(--accent); color: #241a02; font-weight: 800; font-size: .75rem;
  padding: 2px 9px; border-radius: 999px;
}
.field-block textarea { padding-top: 16px; }
.field-block .remove {
  position: absolute; top: -8px; right: 8px;
  background: var(--card2); border: 1px solid var(--border3); color: var(--muted);
  border-radius: 999px; width: 24px; height: 24px; cursor: pointer; font-size: .8rem; line-height: 1;
}

.object-picker { display: flex; gap: 10px; }
.object-picker button {
  flex: 1; padding: 14px 6px; border-radius: 12px; cursor: pointer;
  background: var(--bg2); border: 2px solid var(--border2); color: var(--text);
  font-size: .9rem; display: flex; flex-direction: column; gap: 6px; align-items: center;
}
.object-picker button .ico { font-size: 1.8rem; }
.object-picker button.active { border-color: var(--accent); background: rgba(245,185,66,.08); }

/* --- таблица результатов --- */
.results-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.results-table th, .results-table td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); }
.results-table th { color: var(--muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; }
.results-wrap { overflow-x: auto; }
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.status-dot.done { background: var(--ok); }
.status-dot.playing { background: var(--accent); animation: pulse 1.5s infinite; }
@keyframes pulse { 50% { opacity: .35; } }

.live-hint { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: .8rem; }
.live-hint::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); animation: pulse 1.5s infinite; }

/* ============================== ИГРОВОЙ ЭКРАН ============================== */

.quest-header { text-align: center; margin-bottom: 8px; }
.attempts-chip { color: var(--muted); font-size: .85rem; text-align: center; margin-bottom: 12px; }

.scene {
  display: flex; justify-content: center; align-items: flex-end;
  height: 240px; margin: 10px 0 24px;
  perspective: 900px;
}
.scene.shake .obj { animation: shake .55s; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  15% { transform: translateX(-12px) rotate(-2deg); }
  30% { transform: translateX(11px) rotate(2deg); }
  45% { transform: translateX(-9px) rotate(-1.5deg); }
  60% { transform: translateX(7px) rotate(1deg); }
  75% { transform: translateX(-4px); }
  90% { transform: translateX(2px); }
}
@keyframes field-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  50% { transform: translateX(5px); }
  75% { transform: translateX(-3px); }
}

.glow {
  position: absolute; inset: 0; border-radius: inherit;
  opacity: 0; pointer-events: none;
  transition: opacity 1s ease .3s;
}
.open .glow { opacity: 1; }

/* --- СЕЙФ --- */
.obj.safe {
  position: relative; width: 190px; height: 190px;
  background: linear-gradient(145deg, #6b7387, #3c4254);
  border-radius: 18px;
  box-shadow: inset 0 2px 4px rgba(255,255,255,.25), 0 14px 30px rgba(0,0,0,.5);
}
.safe .interior {
  position: absolute; inset: 10px; border-radius: 12px;
  background: radial-gradient(circle at 50% 45%, #4a3406, #17120a 75%);
  display: flex; align-items: center; justify-content: center; font-size: 2.4rem;
  opacity: 0; transition: opacity .4s ease .5s;
}
.open .safe .interior, .safe.opened .interior { opacity: 1; }
.safe .s-door {
  position: absolute; inset: 6px;
  background: linear-gradient(145deg, #7d8598, #474e63);
  border-radius: 14px;
  border: 3px solid #2e3342;
  transform-origin: left center;
  transition: transform 1.4s cubic-bezier(.6, 0, .3, 1) .55s;
  backface-visibility: hidden;
  display: flex; align-items: center; justify-content: center;
}
.open .safe .s-door { transform: rotateY(-115deg); }
.safe .dial {
  width: 74px; height: 74px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #d8dce6, #8a91a3 60%, #565d70);
  border: 4px solid #333947;
  position: relative;
  transition: transform 1.1s cubic-bezier(.5, 0, .5, 1);
}
.open .safe .dial { transform: rotate(720deg); }
.safe .dial::before {
  content: ""; position: absolute; left: 50%; top: 6px;
  width: 4px; height: 16px; margin-left: -2px;
  background: #2a2f3c; border-radius: 2px;
}
.safe .dial::after {
  content: ""; position: absolute; inset: 16px; border-radius: 50%;
  border: 2px dashed #4d5468;
}
.safe .handle {
  position: absolute; right: 16px; top: 50%; margin-top: -22px;
  width: 12px; height: 44px; border-radius: 6px;
  background: linear-gradient(180deg, #cfd4de, #7c8397);
  box-shadow: 0 2px 6px rgba(0,0,0,.4);
}
.safe .glow { background: radial-gradient(circle at 50% 50%, rgba(255,215,120,.5), transparent 65%); }

/* --- СУНДУК (пиратский, SVG-слои) --- */
.obj.chest { position: relative; width: 240px; height: 200px; }
.chest svg { display: block; width: 100%; height: auto; }
.chest .c-body {
  position: absolute; bottom: 0; left: 0; width: 240px; z-index: 2;
  filter: drop-shadow(0 14px 24px rgba(0,0,0,.5));
}
.chest .c-lid {
  position: absolute; top: 0; left: 0; width: 240px; z-index: 3;
  transform-origin: 50% 100%;
  transition: transform 1.3s cubic-bezier(.55, -0.2, .35, 1.1) .45s;
}
.open .chest .c-lid { transform: rotateX(112deg); }
.chest .c-lock {
  position: absolute; left: 50%; top: 76px; transform: translateX(-50%);
  width: 36px; z-index: 4;
  transition: transform .5s, opacity .5s;
}
.open .chest .c-lock { transform: translateX(-50%) translateY(30px) rotate(25deg); opacity: 0; }
.chest .interior {
  position: absolute; bottom: 88px; left: 20px; width: 200px; z-index: 1;
  opacity: 0; transition: opacity .5s ease .8s, transform .6s ease .8s;
  transform: translateY(14px);
}
.open .chest .interior { transform: translateY(0); }
.open .chest .interior { opacity: 1; }
.chest .glow {
  background: radial-gradient(ellipse at 50% 25%, rgba(255,220,120,.65), transparent 60%);
  inset: -46px -24px 0;
}

/* --- ДВЕРЬ --- */
.obj.door-frame {
  position: relative; width: 170px; height: 230px;
  background: linear-gradient(180deg, #5c4630, #3c2c1a);
  border-radius: 8px;
  padding: 10px;
  box-shadow: 0 14px 30px rgba(0,0,0,.5);
}
.door-frame .interior {
  position: absolute; inset: 10px;
  background: radial-gradient(circle at 50% 40%, #ffe9a8, #d8a93f 80%);
  display: flex; align-items: center; justify-content: center; font-size: 2.2rem;
  opacity: 0; transition: opacity .5s ease .4s;
}
.open .door-frame .interior { opacity: 1; }
.door-frame .d-door {
  position: absolute; inset: 10px;
  background: linear-gradient(90deg, #8a5f33, #6d491f);
  border: 2px solid #3c2c1a;
  transform-origin: left center;
  transition: transform 1.5s cubic-bezier(.6, 0, .25, 1) .4s;
  display: flex; align-items: center;
  z-index: 2;
}
.d-door .panel {
  position: absolute; left: 14px; right: 14px; border: 2px solid rgba(60,44,26,.6); border-radius: 4px;
}
.d-door .panel.top { top: 14px; height: 38%; }
.d-door .panel.bottom { bottom: 14px; height: 30%; }
.d-door .knob {
  position: absolute; right: 12px; top: 50%; margin-top: -7px;
  width: 14px; height: 14px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffe9a8, #b8901f);
  box-shadow: 0 2px 5px rgba(0,0,0,.5);
}
.open .door-frame .d-door { transform: rotateY(-105deg); }
.door-frame .glow { background: radial-gradient(circle at 50% 50%, rgba(255,230,150,.55), transparent 70%); }

/* --- финал --- */
.final-card { text-align: center; animation: rise .8s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(24px); } }
.final-card .big { font-size: 3rem; margin-bottom: 8px; }
.final-text { white-space: pre-wrap; line-height: 1.55; margin-top: 10px; }
.final-text a { color: var(--accent2); }

.confetti {
  position: fixed; top: -12px; border-radius: 3px; pointer-events: none; z-index: 50;
  animation: fall linear both;
}
@keyframes fall {
  to { transform: translateY(110vh) rotate(660deg); opacity: .4; }
}

/* --- загрузка / прочее --- */
.loader-screen { display: flex; justify-content: center; padding: 90px 0; }
.spinner {
  width: 44px; height: 44px; border-radius: 50%;
  border: 4px solid var(--border2); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton { border-radius: 12px; background: linear-gradient(90deg, var(--card) 25%, var(--card2) 50%, var(--card) 75%); background-size: 200% 100%; animation: shimmer 1.3s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  background: var(--card2); border: 1px solid var(--border3); color: var(--text);
  padding: 12px 20px; border-radius: 12px; font-size: .92rem;
  box-shadow: 0 10px 30px rgba(0,0,0,.4); z-index: 100;
  animation: rise .3s ease both;
  max-width: 90vw; text-align: center;
}

.theme-toggle {
  position: fixed; right: 14px; bottom: 14px; z-index: 60;
  width: 46px; height: 46px; border-radius: 50%;
  background: var(--card2); border: 1px solid var(--border3);
  font-size: 1.2rem; cursor: pointer;
  box-shadow: 0 6px 18px var(--shadow);
  transition: transform .15s;
}
.theme-toggle:active { transform: scale(.92); }

.switch-row {
  display: flex; align-items: flex-start; gap: 12px;
  margin-top: 16px; cursor: pointer;
  color: var(--text); font-size: .95rem; line-height: 1.4;
}
.switch-row input {
  width: auto; margin-top: 3px;
  accent-color: var(--accent); transform: scale(1.35);
  cursor: pointer;
}

.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; gap: 10px; }
.topbar .brand { font-weight: 800; font-size: 1.05rem; cursor: pointer; }

.lock-timer { color: var(--bad); font-weight: 700; }

/* --- режим «игра на доске» — крупно для проектора/интерактивной доски --- */
#app.board-mode { max-width: 1100px; }
.board-mode .quest-header h1 { font-size: 2.3rem; }
.board-mode .quest-header .muted { font-size: 1.1rem; }
.board-mode .attempts-chip { font-size: 1.05rem; }
.board-mode .scene {
  transform: scale(1.35);
  transform-origin: center bottom;
  margin-top: 46px;
  margin-bottom: 44px;
}
.board-mode .card { padding: 26px 28px; }
.board-mode input[type=text] { font-size: 1.35rem; padding: 16px 18px 16px 18px; }
.board-mode .field-block .num { font-size: .9rem; }
.board-mode .btn { font-size: 1.25rem; padding: 18px 24px; }
.board-mode .final-card h2 { font-size: 1.8rem; }
.board-mode .final-text { font-size: 1.25rem; }
@media (min-width: 900px) {
  .board-mode .fields-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    column-gap: 22px;
  }
}

@media (min-width: 600px) {
  #app { padding-top: 36px; }
  .scene { height: 280px; }
  .obj.safe { width: 220px; height: 220px; }
  .obj.door-frame { width: 195px; height: 265px; }
}
