/* =========================================================
   MINI THIEF - UI shell
   Canvas draws the world; this file styles the overlay UI.
   Portrait-first, touch-first, safe-area aware.
   ========================================================= */

:root {
  --bg: #07090e;
  --bg-elev: #12161f;
  --ink: #eef1f7;
  --ink-dim: #9aa4b8;
  --gold: #f5c451;
  --gold-deep: #c8951f;
  --ok: #4ade80;
  --fail: #f87171;
  --stroke: rgba(255, 255, 255, 0.10);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.55);
  --radius: 18px;
  --radius-sm: 12px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --font: "Pretendard", "Apple SD Gothic Neo", "Noto Sans KR", system-ui, -apple-system,
    "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  overscroll-behavior: none;
}

body {
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.app {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background:
    radial-gradient(120% 80% at 50% 0%, #161c29 0%, #07090e 62%, #04050a 100%);
}

/* The stage keeps the 9:16 play area centered and letterboxed. */
.stage {
  position: relative;
  width: 100%;
  height: 100%;
  max-width: calc(100vh * 0.5625);
  max-height: 100vh;
  overflow: hidden;
  background: #05070c;
  box-shadow: var(--shadow-lg);
}

@media (min-aspect-ratio: 10/16) and (min-width: 700px) {
  .stage { border-radius: 26px; border: 1px solid var(--stroke); }
}

.game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* ================= HUD ================= */
.hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  padding: calc(10px + var(--safe-t)) 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
  z-index: 5;
  background: linear-gradient(180deg, rgba(5, 7, 12, 0.85) 0%, rgba(5, 7, 12, 0) 100%);
}
.hud[hidden] { display: none; }

.hud__row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.hud__row--sub { min-height: 46px; }
.hud__left, .hud__right { display: flex; align-items: center; gap: 8px; pointer-events: auto; }

.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  font: 600 13px/1 var(--font-mono);
  letter-spacing: 0.08em;
  white-space: nowrap;
  color: var(--ink-dim);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--stroke);
  backdrop-filter: blur(8px);
}
.chip--timer { color: var(--ink); min-width: 56px; font-size: 15px; font-variant-numeric: tabular-nums; }
.chip--timer.is-warning { color: #fff; background: rgba(248, 113, 113, 0.22); border-color: rgba(248, 113, 113, 0.5); animation: pulse 1s ease-in-out infinite; }

@keyframes pulse { 50% { opacity: 0.55; } }

.icon-btn {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 999px;
  border: 1px solid var(--stroke);
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink);
  font-size: 15px;
  cursor: pointer;
  backdrop-filter: blur(8px);
  transition: transform 0.12s ease, background 0.2s ease;
}
.icon-btn:active { transform: scale(0.92); background: rgba(255, 255, 255, 0.14); }
.icon-btn.is-off { color: var(--ink-dim); opacity: 0.6; }

/* ================= Inventory ================= */
.inventory { display: flex; gap: 8px; pointer-events: auto; }

.slot {
  width: 46px; height: 46px;
  display: grid; place-items: center;
  border-radius: var(--radius-sm);
  border: 1px solid var(--stroke);
  background: rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(8px);
  animation: slot-in 0.32s cubic-bezier(0.18, 0.9, 0.3, 1.2);
}
.slot__glyph { width: 30px; height: 30px; color: var(--gold); }
.slot__count {
  position: absolute; transform: translate(16px, 14px);
  font: 700 10px/1 var(--font-mono); color: var(--ink);
}
@keyframes slot-in {
  from { opacity: 0; transform: translateY(-10px) scale(0.7); }
  to   { opacity: 1; transform: none; }
}

/* ================= Toast ================= */
.toast {
  position: absolute;
  left: 16px; right: 16px;
  bottom: calc(26px + var(--safe-b));
  margin: 0 auto;
  max-width: 420px;
  padding: 13px 18px;
  border-radius: 14px;
  background: rgba(12, 15, 22, 0.88);
  border: 1px solid var(--stroke);
  backdrop-filter: blur(14px);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.45;
  text-align: center;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.22s ease, transform 0.22s ease;
  pointer-events: none;
  z-index: 6;
}
.toast.is-visible { opacity: 1; transform: none; }

/* ================= Screens ================= */
.screen {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: calc(24px + var(--safe-t)) 24px calc(24px + var(--safe-b));
  background: rgba(5, 7, 12, 0.82);
  backdrop-filter: blur(16px);
  animation: screen-in 0.28s ease both;
}
.screen[hidden] { display: none; }

/* Result screens stay translucent so the escape stays visible behind them. */
.screen--result { background: rgba(5, 7, 12, 0.60); backdrop-filter: blur(10px); }

@keyframes screen-in { from { opacity: 0; } to { opacity: 1; } }

.screen__inner {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 26px;
  text-align: center;
}

.brand { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.brand__mark { color: var(--gold); filter: drop-shadow(0 6px 18px rgba(245, 196, 81, 0.35)); }
.brand__title {
  margin: 0;
  font-size: clamp(34px, 11vw, 46px);
  font-weight: 800;
  letter-spacing: 0.16em;
  background: linear-gradient(180deg, #fff 0%, var(--gold) 120%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.brand__tagline { margin: 0; color: var(--ink-dim); font-size: 14px; letter-spacing: 0.02em; }

.screen__actions { display: flex; flex-direction: column; gap: 10px; width: 100%; }

.btn {
  width: 100%;
  min-height: 54px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font: 700 16px/1 var(--font);
  letter-spacing: 0.1em;
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.2s ease, background 0.2s ease;
}
.btn:active { transform: translateY(1px) scale(0.99); }
.btn--primary {
  color: #22160a;
  background: linear-gradient(180deg, var(--gold) 0%, var(--gold-deep) 100%);
  box-shadow: 0 12px 28px rgba(245, 196, 81, 0.22);
}
.btn--primary:hover { filter: brightness(1.06); }
.btn--ghost {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--stroke);
}

.legal-links { display: flex; gap: 8px; font-size: 12px; color: var(--ink-dim); }
.legal-links a { color: var(--ink-dim); text-decoration: none; border-bottom: 1px solid var(--stroke); }
.legal-links a:hover { color: var(--ink); }

/* ================= Result ================= */
.result__badge {
  width: 78px; height: 78px;
  display: grid; place-items: center;
  border-radius: 999px;
  font-size: 34px; font-weight: 700;
  animation: badge-pop 0.45s cubic-bezier(0.18, 0.9, 0.3, 1.35) both;
}
.result__badge--ok { color: #06301a; background: linear-gradient(180deg, #86efac, var(--ok)); box-shadow: 0 16px 40px rgba(74, 222, 128, 0.3); }
.result__badge--fail { color: #3a0b0b; background: linear-gradient(180deg, #fca5a5, var(--fail)); box-shadow: 0 16px 40px rgba(248, 113, 113, 0.3); }
@keyframes badge-pop { from { opacity: 0; transform: scale(0.5); } to { opacity: 1; transform: none; } }

.result__title { margin: 0; font-size: 30px; letter-spacing: 0.18em; font-weight: 800; }
.result__sub { margin: -14px 0 0; color: var(--ink-dim); font-size: 14px; }

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  width: 100%;
  margin: 0;
}
.stats__cell {
  padding: 12px 6px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--stroke);
}
.stats dt { font: 600 10px/1 var(--font-mono); letter-spacing: 0.14em; color: var(--ink-dim); }
.stats dd { margin: 7px 0 0; font: 700 18px/1 var(--font-mono); color: var(--ink); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

/* ================= Level name chip ================= */
.chip--name {
  max-width: 38vw;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-family: var(--font);
  font-weight: 500;
  letter-spacing: 0.01em;
  color: var(--ink-dim);
  font-size: 12px;
  height: 30px;
  background: transparent;
  border-color: transparent;
  padding: 0 2px;
}
.chip--name[hidden] { display: none; }

/* ================= Inventory slot states ================= */
.slot {
  position: relative;
  padding: 0;
  cursor: grab;
  color: var(--gold);
  transition: transform 0.12s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}
.slot:active { cursor: grabbing; transform: scale(0.94); }
.slot.is-armed {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(245, 196, 81, 0.28), 0 8px 22px rgba(245, 196, 81, 0.22);
  background: rgba(245, 196, 81, 0.14);
}

/* ================= Level select ================= */
.screen__inner--wide { max-width: 420px; }

.screen__title {
  margin: 0;
  font-size: 22px;
  letter-spacing: 0.18em;
  font-weight: 800;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  width: 100%;
}

.level-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  min-height: 92px;
  padding: 14px;
  text-align: left;
  border-radius: var(--radius-sm);
  border: 1px solid var(--stroke);
  background: rgba(255, 255, 255, 0.05);
  color: var(--ink);
  cursor: pointer;
  transition: transform 0.12s ease, background 0.2s ease, border-color 0.2s ease;
}
.level-card:hover:not(.is-locked) { background: rgba(245, 196, 81, 0.10); border-color: rgba(245, 196, 81, 0.4); }
.level-card:active:not(.is-locked) { transform: scale(0.98); }
.level-card.is-locked { opacity: 0.45; cursor: not-allowed; }

.level-card__no { font: 700 12px/1 var(--font-mono); letter-spacing: 0.14em; color: var(--gold); }
.level-card__name { font-size: 15px; font-weight: 600; }
.level-card__best { font: 500 11px/1.3 var(--font-mono); color: var(--ink-dim); }

/* ================= Success record ================= */
.result__record {
  margin: -10px 0 0;
  font: 700 13px/1 var(--font-mono);
  letter-spacing: 0.14em;
  color: var(--gold);
  animation: pulse 1.4s ease-in-out infinite;
}
.result__record[hidden] { display: none; }

#btn-next[hidden] { display: none; }

/* ================= Tutorial coach line ================= */
.coach {
  position: absolute;
  left: 16px; right: 16px;
  bottom: calc(96px + var(--safe-b));
  margin: 0 auto;
  max-width: 420px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 16px;
  border-radius: 14px;
  background: rgba(245, 196, 81, 0.14);
  border: 1px solid rgba(245, 196, 81, 0.42);
  backdrop-filter: blur(12px);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.4;
  pointer-events: none;
  z-index: 6;
  animation: coach-in 0.3s ease both;
}
.coach[hidden] { display: none; }
.coach__icon { font-size: 18px; animation: coach-nudge 1.3s ease-in-out infinite; }
.coach__text { flex: 1; }

@keyframes coach-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes coach-nudge { 50% { transform: translateY(-4px); } }

/* ================= Settings ================= */
.setting {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: 'label value' 'range range';
  align-items: center;
  gap: 8px 12px;
  width: 100%;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--stroke);
  background: rgba(255, 255, 255, 0.05);
}
.setting--row { grid-template-columns: 1fr auto; grid-template-areas: 'label value'; }
.setting__label {
  grid-area: label;
  font: 600 11px/1 var(--font-mono);
  letter-spacing: 0.14em;
  color: var(--ink-dim);
  text-align: left;
}
.setting__value {
  grid-area: value;
  font: 700 14px/1 var(--font-mono);
  color: var(--ink);
}
.setting__range {
  grid-area: range;
  width: 100%;
  height: 28px;
  margin: 0;
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}
.setting__range::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
}
.setting__range::-moz-range-track {
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
}
.setting__range::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px; height: 20px;
  margin-top: -7px;
  border-radius: 999px;
  border: none;
  background: linear-gradient(180deg, var(--gold), var(--gold-deep));
  box-shadow: 0 2px 10px rgba(245, 196, 81, 0.4);
}
.setting__range::-moz-range-thumb {
  width: 20px; height: 20px;
  border: none;
  border-radius: 999px;
  background: var(--gold);
}
.setting__note {
  margin: 0;
  font: 500 12px/1 var(--font-mono);
  color: var(--ink-dim);
  letter-spacing: 0.06em;
}

.btn--chip {
  width: auto;
  min-height: 34px;
  padding: 0 14px;
  border-radius: 999px;
  font-size: 12px;
  letter-spacing: 0.06em;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--stroke);
}
.btn--danger {
  color: #ffd9d9;
  background: rgba(248, 113, 113, 0.16);
  border-color: rgba(248, 113, 113, 0.45);
}
.btn--danger:hover { background: rgba(248, 113, 113, 0.26); }
