:root {
  color-scheme: light;
  font-family: "Arial Narrow", "Roboto Condensed", Arial, sans-serif;
  --paper: #435159;
  --ink: #f0ece1;
  --bug: #101719;
  --muted: #b8c0bd;
  --line: #77858a;
  --danger: #ee4e45;
  --accent: #1aa69b;
  --gold: #e6aa2f;
}

* { box-sizing: border-box; }

html, body, #game-shell { width: 100%; height: 100%; margin: 0; overflow: hidden; }

body {
  background: var(--paper);
  color: var(--ink);
  overscroll-behavior: none;
  touch-action: none;
  user-select: none;
}

#game-shell { position: relative; isolation: isolate; }

#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
  touch-action: none;
}

.topbar {
  position: absolute;
  z-index: 10;
  top: 0;
  left: 0;
  right: 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: 16px;
  padding: max(16px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) 12px max(18px, env(safe-area-inset-left));
  pointer-events: none;
}

.brand, .icon-button, .top-actions { pointer-events: auto; }

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  width: max-content;
  color: inherit;
  text-decoration: none;
  font-size: 13px;
  line-height: .84;
  font-weight: 900;
  letter-spacing: .12em;
}

.brand-mark { position: relative; display: block; width: 22px; height: 28px; }
.brand-mark i { position: absolute; left: 2px; width: 18px; height: 2px; background: currentColor; transform-origin: right center; }
.brand-mark i:nth-child(1) { top: 6px; transform: rotate(28deg); }
.brand-mark i:nth-child(2) { top: 13px; }
.brand-mark i:nth-child(3) { top: 20px; transform: rotate(-28deg); }

.room-label {
  margin: 1px 0 0;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .23em;
  color: var(--muted);
  text-align: center;
}

.icon-button {
  border: 0;
  border-bottom: 2px solid var(--ink);
  padding: 4px 0 5px;
  background: transparent;
  color: var(--ink);
  font: 800 10px/1 inherit;
  letter-spacing: .13em;
  cursor: pointer;
}

.top-actions {
  justify-self: end;
  display: flex;
  align-items: flex-start;
  gap: 16px;
}

.hint, .toast {
  position: absolute;
  z-index: 8;
  left: 50%;
  bottom: max(24px, calc(env(safe-area-inset-bottom) + 16px));
  transform: translate(-50%, 0);
  padding: 11px 16px 10px;
  border: 1px solid var(--ink);
  background: rgba(52, 65, 72, .94);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .08em;
  text-align: center;
  white-space: nowrap;
  transition: opacity .25s, transform .25s;
  pointer-events: none;
}

.hint.dismissed { opacity: 0; transform: translate(-50%, 8px); }
.danger-hint { border-color: var(--danger); color: #ffaaa3; }
.camera-hint { border-color: var(--gold); color: #f6d273; }
.toast { bottom: 84px; opacity: 0; border: 0; background: var(--ink); color: var(--paper); }
.toast.show { opacity: 1; transform: translate(-50%, -5px); }

.result {
  position: absolute;
  z-index: 30;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(40, 51, 57, .9);
  backdrop-filter: blur(8px);
}

.result[hidden] { display: none; }

.briefing {
  position: absolute;
  z-index: 40;
  inset: 0;
  display: grid;
  place-items: center;
  padding: max(20px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  overflow: auto;
  background: rgba(20, 29, 34, .9);
  backdrop-filter: blur(9px);
}

.briefing[hidden] { display: none; }

.briefing-card {
  width: min(470px, 100%);
  padding: clamp(24px, 5vw, 42px);
  border: 1px solid var(--line);
  background: #344148;
  box-shadow: 0 20px 70px rgba(0, 0, 0, .28);
}

.briefing-kicker {
  margin: 0 0 12px;
  color: var(--gold);
  font-size: 9px;
  font-weight: 900;
  letter-spacing: .28em;
}

.briefing-card h1 {
  margin: 0 0 18px;
  font: 900 clamp(34px, 8vw, 58px)/.87 inherit;
  letter-spacing: -.055em;
}

.briefing-story {
  max-width: 390px;
  margin: 0 0 24px;
  color: #d2d8d5;
  font-size: 14px;
  line-height: 1.45;
}

.briefing-rules {
  display: grid;
  gap: 0;
  margin: 0 0 26px;
  padding: 0;
  list-style: none;
  border-top: 1px solid var(--line);
}

.briefing-rules li {
  display: grid;
  grid-template-columns: 74px 1fr;
  gap: 14px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
  line-height: 1.35;
}

.briefing-rules b { color: var(--gold); font-size: 9px; letter-spacing: .15em; }
.briefing-rules span { color: #d2d8d5; }

.briefing-card > button {
  width: 100%;
  border: 2px solid var(--ink);
  padding: 14px 18px;
  background: var(--ink);
  color: var(--paper);
  font: 900 11px/1 inherit;
  letter-spacing: .14em;
  cursor: pointer;
}

.result-card { text-align: center; animation: arrive .35s ease-out both; }
.result-card p { margin: 18px 0 8px; color: var(--gold); font-size: 10px; font-weight: 900; letter-spacing: .27em; }
.result-card h1 { margin: 0 0 24px; font: 900 clamp(42px, 10vw, 88px)/.83 inherit; letter-spacing: -.07em; }
.result-card button {
  border: 2px solid var(--ink);
  padding: 13px 18px;
  background: var(--ink);
  color: var(--paper);
  font: 900 11px/1 inherit;
  letter-spacing: .14em;
  cursor: pointer;
}

.stolen-gem {
  width: 54px;
  height: 54px;
  margin: auto;
  background: var(--gold);
  clip-path: polygon(50% 0, 90% 25%, 72% 88%, 50% 100%, 28% 88%, 10% 25%);
  animation: gem-pop .8s cubic-bezier(.2,.8,.2,1) both;
}

@keyframes arrive { from { opacity: 0; transform: translateY(10px); } }
@keyframes gem-pop { 0% { transform: scale(.2) rotate(-18deg); } 65% { transform: scale(1.2) rotate(5deg); } }

@media (max-width: 620px) {
  .topbar { grid-template-columns: 1fr 1fr; }
  .room-label { display: none; }
  .hint { max-width: calc(100vw - 32px); white-space: normal; }
  .top-actions { gap: 10px; }
  .icon-button { font-size: 9px; }
  .briefing { place-items: start center; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
