:root {
  color-scheme: dark;
  --panel: rgba(9, 11, 16, 0.88);
  --stroke: rgba(221, 109, 60, 0.28);
  --text: #f2e7d5;
  --muted: #a9b0ad;
  --accent: #d95f37;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #07090d;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

#game-shell {
  position: relative;
  width: 100vw;
  height: 100vh;
  background: #07090d;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
}

#hud {
  position: absolute;
  top: max(18px, env(safe-area-inset-top));
  left: max(18px, env(safe-area-inset-left));
  width: min(360px, calc(100vw - 36px));
  padding: 16px 18px;
  border: 1px solid var(--stroke);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  box-shadow:
    0 18px 50px rgba(0, 0, 0, 0.42),
    inset 0 0 28px rgba(122, 35, 33, 0.16);
  backdrop-filter: blur(12px);
}

.hud-title {
  color: var(--accent);
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

#hint {
  margin-top: 6px;
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
}

.hud-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 12px;
  color: var(--muted);
  font-size: 13px;
}

.hud-row span {
  min-width: 74px;
  padding: 5px 10px;
  border: 1px solid var(--stroke);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  text-align: center;
}

.stat-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 12px;
}

.stat-row span {
  padding: 4px 7px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.06);
}

#message {
  margin-top: 10px;
  color: #fff2d8;
  font-size: 13px;
  font-weight: 700;
}

.panel {
  position: absolute;
  right: max(22px, env(safe-area-inset-right));
  bottom: max(24px, env(safe-area-inset-bottom));
  width: min(440px, calc(100vw - 44px));
  padding: 18px;
  border: 1px solid var(--stroke);
  border-radius: 8px;
  background: rgba(8, 9, 13, 0.92);
  color: var(--text);
  box-shadow:
    0 18px 48px rgba(0, 0, 0, 0.54),
    inset 0 0 32px rgba(112, 37, 30, 0.18);
  backdrop-filter: blur(12px);
}

.hidden {
  display: none;
}

.panel-title,
#dialogue-speaker {
  color: var(--accent);
  font-size: 15px;
  font-weight: 800;
  text-transform: uppercase;
}

#dialogue-line,
#interior-line,
#munch-instruction,
#result-line,
#result-stats {
  margin-top: 10px;
  font-size: 16px;
  font-weight: 700;
}

#result-line {
  color: #fff2d8;
}

#result-stats {
  color: var(--muted);
  font-size: 13px;
}

#dialogue-choices {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

#interior-actions {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

#dialogue-choices button,
#interior-actions button,
#restart-button {
  min-height: 40px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  background: rgba(35, 31, 34, 0.9);
  color: var(--text);
  font: inherit;
  font-weight: 800;
  text-align: left;
}

#dialogue-choices button {
  padding: 9px 12px;
}

#interior-actions button {
  padding: 9px 12px;
  text-align: left;
}

#interior-actions button:disabled {
  opacity: 0.45;
}

#restart-button {
  margin-top: 14px;
  padding: 9px 14px;
  text-align: center;
}

#munch-panel {
  inset: 0;
  display: grid;
  place-content: center;
  width: auto;
  border: 0;
  border-radius: 0;
  background:
    radial-gradient(circle at 50% 44%, rgba(255, 207, 102, 0.18), transparent 18%),
    radial-gradient(circle at 50% 50%, rgba(152, 35, 26, 0.22), transparent 36%),
    rgba(6, 5, 7, 0.72);
  text-align: center;
}

#munch-panel.hidden {
  display: none;
}

#touch-controls {
  position: absolute;
  left: max(22px, env(safe-area-inset-left));
  bottom: max(22px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: repeat(3, 64px);
  grid-template-rows: repeat(2, 64px);
  gap: 10px;
  touch-action: none;
  user-select: none;
}

.control-button {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 8px;
  background: rgba(10, 11, 15, 0.82);
  color: #fff;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.34);
  font-size: 28px;
  font-weight: 900;
  line-height: 1;
  backdrop-filter: blur(10px);
}

.control-button:active,
.control-button.is-held {
  background: rgba(217, 95, 55, 0.88);
  border-color: rgba(255, 190, 112, 0.72);
  color: #100b0a;
}

.control-up {
  grid-column: 2;
  grid-row: 1;
}

.control-left {
  grid-column: 1;
  grid-row: 2;
}

.control-down {
  grid-column: 2;
  grid-row: 2;
}

.control-right {
  grid-column: 3;
  grid-row: 2;
}

@media (max-width: 640px) {
  #hud {
    top: max(10px, env(safe-area-inset-top));
    left: max(10px, env(safe-area-inset-left));
    width: min(300px, calc(100vw - 20px));
    padding: 10px 11px;
  }

  .hud-title {
    font-size: 16px;
  }

  #hint {
    font-size: 12px;
  }

  .hud-row {
    gap: 6px;
    margin-top: 8px;
    font-size: 11px;
  }

  .hud-row span {
    min-width: 0;
    padding: 4px 7px;
  }

  .stat-row {
    gap: 5px;
    margin-top: 8px;
    font-size: 11px;
  }

  #message {
    margin-top: 8px;
    font-size: 12px;
  }

  .panel {
    right: max(10px, env(safe-area-inset-right));
    bottom: max(12px, env(safe-area-inset-bottom));
    width: min(340px, calc(100vw - 20px));
    padding: 12px;
  }

  #dialogue-line,
  #interior-line,
  #munch-instruction,
  #result-line {
    font-size: 13px;
  }

  #result-stats {
    font-size: 11px;
  }

  #touch-controls {
    left: max(12px, env(safe-area-inset-left));
    bottom: max(12px, env(safe-area-inset-bottom));
    grid-template-columns: repeat(3, 54px);
    grid-template-rows: repeat(2, 54px);
    gap: 8px;
  }

  .control-button {
    width: 54px;
    height: 54px;
    font-size: 23px;
  }
}

@media (min-width: 900px) and (pointer: fine) {
  #touch-controls {
    opacity: 0.9;
  }
}

@media (max-width: 560px) {
  #touch-controls {
    grid-template-columns: repeat(3, 56px);
    grid-template-rows: repeat(2, 56px);
    gap: 8px;
  }

  .control-button {
    width: 56px;
    height: 56px;
    font-size: 24px;
  }
}
