:root {
  --paper: #fbf4e3;
  --ink: #2c241c;
  --muted: #6f6156;
  --lead: #3a2a18;
  --gold: #b88942;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(circle at top, #f8f0de 0%, #e5d4b8 36%, #c7ae88 100%);
  color: var(--ink);
  font-family: Georgia, "Times New Roman", serif;
  touch-action: none;
  user-select: none;
}

body {
  overscroll-behavior: none;
}

.shell {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  position: relative;
}

.title {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  background: rgba(248, 239, 220, 0.72);
  box-shadow: 0 1px 0 rgba(120, 84, 35, 0.18);
  font-size: clamp(18px, 2.8vw, 28px);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-align: center;
  z-index: 10;
  white-space: nowrap;
}

.verse {
  position: absolute;
  top: max(56px, calc(env(safe-area-inset-top) + 44px));
  left: 50%;
  transform: translateX(-50%);
  max-width: min(32rem, calc(100vw - 32px));
  font-size: clamp(13px, 2.3vw, 18px);
  line-height: 1.3;
  color: #7f5b24;
  text-align: center;
  z-index: 10;
}

.progress-track {
  position: absolute;
  top: max(88px, calc(env(safe-area-inset-top) + 76px));
  left: 50%;
  transform: translateX(-50%);
  width: min(200px, 50vw);
  height: 6px;
  background: rgba(120, 84, 35, 0.15);
  border-radius: 3px;
  overflow: hidden;
  z-index: 10;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #b88942, #d4a64a);
  border-radius: 3px;
}

.window {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 3px;
  width: min(80vmin, 70vw, 55vh);
  aspect-ratio: 1;
  background: var(--lead);
  border-radius: 50%;
  padding: 5px;
  box-shadow:
    0 4px 20px rgba(79, 48, 18, 0.2),
    inset 0 0 30px rgba(0, 0, 0, 0.15),
    inset 0 2px 8px rgba(255, 255, 255, 0.12);
  position: relative;
  z-index: 5;
}

.pane {
  all: unset;
  display: block;
  position: relative;
  border-radius: 3px;
  cursor: pointer;
  overflow: hidden;
}

.pane:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
  border-radius: 5px;
}

.soot-layer {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background: rgba(30, 20, 10, 0.88);
  opacity: 0;
}

.heat-layer {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  box-shadow: inset 0 0 12px rgba(242, 165, 85, 0.7);
  opacity: 0;
}

.smoke-layer {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background: rgba(56, 41, 33, 0.5);
  opacity: 0;
}

.glass-shine {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background: radial-gradient(circle at 30% 25%, rgba(255, 255, 255, 0.22), transparent 60%);
}

.marker {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 24%;
  height: 24%;
  transform: translate(-50%, -50%) rotate(45deg);
  border: 2px solid rgba(245, 229, 181, 0.9);
  pointer-events: none;
  opacity: 0;
  z-index: 2;
  font-size: 0;
  line-height: 0;
}

/* Soot levels */
.pane.soot-4 > .soot-layer { opacity: 0.88; }
.pane.soot-3 > .soot-layer { opacity: 0.66; }
.pane.soot-2 > .soot-layer { opacity: 0.44; }
.pane.soot-1 > .soot-layer { opacity: 0.22; }
.pane.soot-0 > .soot-layer { opacity: 0; }

/* Heat levels */
.pane.heat-3 > .heat-layer { opacity: 0.7; }
.pane.heat-2 > .heat-layer { opacity: 0.47; }
.pane.heat-1 > .heat-layer { opacity: 0.23; }
.pane.heat-0 > .heat-layer { opacity: 0; }

/* Smoked */
.pane.smoked > .smoke-layer { opacity: 0.5; }
.pane.smoked { filter: brightness(0.7); }

/* Target markers */
.pane.target > .marker { opacity: 0.3; }
.pane.target.visible > .marker { opacity: 0.9; }

.tool-btn {
  appearance: none;
  border: none;
  outline: none;
  margin: 0;
  display: block;
  padding: 0.5rem 1.2rem;
  border-radius: 999px;
  background: rgba(126, 166, 168, 0.85);
  color: #2a3d3e;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(13px, 2vw, 16px);
  cursor: pointer;
  transition: background 0.2s, transform 0.15s;
  z-index: 10;
}

.tool-btn:active {
  transform: scale(0.95);
}

.tool-btn.active {
  background: rgba(80, 120, 122, 0.95);
  box-shadow: 0 0 12px rgba(100, 160, 165, 0.45);
  color: #ebe4c3;
}

.hint {
  position: absolute;
  bottom: max(18px, calc(env(safe-area-inset-bottom) + 8px));
  left: 50%;
  transform: translateX(-50%);
  max-width: min(32rem, calc(100vw - 32px));
  font-size: clamp(13px, 2.3vw, 18px);
  line-height: 1.3;
  color: var(--muted);
  text-align: center;
  transition: opacity 400ms ease;
  z-index: 10;
}

.ending {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  background: rgba(251, 243, 227, 0.4);
}

.ending-inner {
  padding: 1.5rem 2rem;
  border-radius: 18px;
  background: rgba(248, 239, 220, 0.92);
  box-shadow: 0 12px 28px rgba(79, 48, 18, 0.14);
  text-align: center;
}

.ending-text {
  font-size: clamp(16px, 2.5vw, 22px);
  color: #5d4525;
  margin-bottom: 1rem;
}

.replay-btn {
  appearance: none;
  border: none;
  outline: none;
  margin: 0;
  display: inline-block;
  padding: 0.5rem 1.2rem;
  border-radius: 999px;
  background: rgba(184, 137, 66, 0.85);
  color: #3a2a18;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(13px, 2vw, 16px);
  cursor: pointer;
  transition: background 0.2s, transform 0.15s;
}

.replay-btn:active {
  transform: scale(0.95);
}

.hidden {
  display: none !important;
}

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