:root {
  color-scheme: dark;
  --page: #24251c;
  --panel: #303327;
  --line: #5c593e;
  --text: #fcf0d7;
  --muted: #ccc2a4;
  --gold: #ffbc59;
  --ink: #302417;
  --paper: #f4d9a4;
  font-family: 'Segoe UI', system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-width: 300px;
  min-height: 100svh;
  background: repeating-linear-gradient(110deg, transparent 0 7px, #17181027 7px 8px),
    radial-gradient(ellipse at 48% 0%, #45432e 0, var(--page) 65%);
  color: var(--text);
}

button { color: inherit; font: inherit; cursor: pointer; }
button:focus-visible { outline: 3px solid #ffe6a6; outline-offset: 3px; }
button:disabled { cursor: default; }

.game {
  width: calc(100% - 52px);
  max-width: min(1160px, calc((100svh - 145px) * 16 / 9));
  min-width: min(760px, calc(100% - 52px));
  margin: 0 auto;
  padding: 22px 0 14px;
}

.topbar, .brand, .reset, .bottom-bar, .inventory, .slots, .slot, .keyboard, .keyboard > span, .health-row, .health-label, .actions, .action {
  display: flex;
  align-items: center;
}

.topbar { justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.brand { gap: 13px; }
.brand h1 { margin: 0; letter-spacing: -.025em; font: 920 clamp(1.4rem, 3vw, 2.2rem)/.98 'Arial Black', 'Segoe UI', sans-serif; text-transform: uppercase; }
.brand p { color: var(--muted); margin: 5px 0 0; font-size: .74rem; letter-spacing: .085em; }

.lantern {
  position: relative;
  display: block;
  width: 37px;
  height: 37px;
  background: #773924;
  border: 2px solid #c18050;
  border-radius: 5px 8px 5px 9px;
  transform: rotate(-6deg);
  box-shadow: 2px 3px #171810aa;
}

.lantern::before {
  content: '';
  position: absolute;
  inset: 9px 11px 7px;
  border: 2px solid var(--gold);
  border-top-width: 4px;
  border-bottom-width: 4px;
  border-radius: 4px;
  box-shadow: inset 0 0 7px #f1b86477;
}

.lantern::after { content: ''; position: absolute; inset: 5px 15px auto; height: 5px; border: 1px solid var(--gold); border-radius: 3px; }
.reset { gap: 6px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 4px 8px 5px 8px; background: #302f23; font-size: .83rem; }
.reset span { color: var(--gold); font-size: 1rem; }
.reset:hover { background: #343d30; }

.stage {
  position: relative;
  isolation: isolate;
  display: grid;
  overflow: hidden;
  aspect-ratio: 16 / 9;
  border: 2px solid #887147;
  border-radius: 8px 13px 7px 11px;
  background: #849481;
  box-shadow: 0 18px 60px #1017119e;
}

canvas { width: 100%; height: 100%; display: block; user-select: none; }
.scene-label, .health-card, .battle-caption, .feedback, .interact { box-shadow: 3px 5px 0 #30241784; }
.scene-label, .health-card {
  position: absolute;
  top: 19px;
  left: 19px;
  padding: 12px 15px;
  border: 2px solid #583d27;
  border-radius: 6px 11px 4px 9px;
  background: linear-gradient(117deg, #ffe8b8, var(--paper) 74%, #eac58d);
  color: var(--ink);
}

.scene-label { transform: rotate(-1.35deg); transform-origin: top left; }
.eyebrow { color: var(--gold); font-size: .65rem; font-weight: 800; letter-spacing: .13em; text-transform: uppercase; margin: 0; }
.scene-label .eyebrow { color: #874523; }
.scene-label h2 { margin: 4px 0; font-size: clamp(1rem, 2vw, 1.35rem); letter-spacing: -.035em; line-height: 1.08; font-weight: 900; }
.scene-label p:last-child { margin: 0; font-size: .86rem; color: #4f3824; }

.interact {
  position: absolute;
  bottom: 5%;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 9px;
  align-items: center;
  padding: 7px 13px 7px 8px;
  max-width: 90%;
  white-space: nowrap;
  border: 1px solid #ffd994;
  border-radius: 6px 8px 5px 9px;
  background: #403322f7;
  font-size: .89rem;
  font-weight: 730;
}

.interact:hover { background: #434132; }

kbd {
  display: inline-grid;
  place-items: center;
  min-width: 1.65em;
  height: 1.65em;
  padding: 0 .25em;
  border: 1px solid #757862;
  border-radius: 5px;
  background: #182019;
  color: #fff5d8;
  font: 700 .78em/1 'Segoe UI', system-ui, sans-serif;
}

.interact kbd { background: var(--gold); color: var(--ink); border-color: #d89f55; }
.feedback {
  position: absolute;
  bottom: 16%;
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: 90%;
  padding: 7px 12px;
  color: #fff1ce;
  background: #222820ee;
  border: 1px solid #e1b9718f;
  border-radius: 8px;
  text-align: center;
  font-size: .8rem;
  pointer-events: none;
}

.bottom-bar { min-height: 56px; margin-top: 12px; justify-content: space-between; gap: 10px; }
.inventory { gap: 13px; }
.inventory > p { color: var(--muted); }
.slots { gap: 6px; padding: 0; margin: 0; list-style: none; }
.slot { gap: 5px; min-height: 33px; padding: 4px 7px; border-radius: 3px 6px 5px 7px; background: #2d2c22; border: 1px solid #56533c; color: #c4bea8; font-size: .75rem; white-space: nowrap; }
.slot.owned { background: #4b3923; border-color: #a57943; color: #fff0cb; box-shadow: 2px 2px #181811; }
.item-icon { position: relative; display: block; width: 18px; height: 18px; opacity: .67; }
.owned .item-icon { opacity: 1; }
.item-icon::before { content: ''; position: absolute; }
.stick::before { inset: 8px 1px 7px; transform: rotate(-43deg); border-radius: 2px; background: #e8ae70; box-shadow: 1px 1px #875636; }
.wire::before { inset: 3px 4px; border: 1px solid #aab6ba; border-radius: 50%; transform: rotate(26deg); box-shadow: inset 1px 0 #69767b, 2px 1px #8d9da1; }
.feather::before { inset: 2px 5px 2px 6px; transform: rotate(36deg); border-radius: 80% 45% 80% 0; background: linear-gradient(90deg, #c78454, #ffdb91); }
.keyboard { gap: 13px; color: var(--muted); font-size: .76rem; }
.keyboard > span { gap: 4px; white-space: nowrap; }

.health-row { position: absolute; inset: 0 0 auto; justify-content: space-between; align-items: stretch; padding: 19px; gap: 14px; }
.health-card { position: static; width: min(31%, 245px); padding: 9px 12px 10px; transform: rotate(-1deg); }
.health-card.enemy { transform: rotate(1deg); }
.health-label { justify-content: space-between; gap: 5px; font-weight: 800; font-size: .85rem; white-space: nowrap; }
.health-label span + span { color: #854222; font-variant-numeric: tabular-nums; }
.round-stamp { align-self: start; padding: 8px 13px; background: #812f22; color: #fff1cc; border: 2px solid #461d16; border-radius: 5px 8px 4px 7px; box-shadow: 2px 4px #211c16aa; transform: rotate(3deg); font-size: .73rem; font-weight: 850; text-transform: uppercase; letter-spacing: .09em; text-align: center; }
.feedback img { width: 30px; height: 26px; margin-inline-end: 6px; object-fit: contain; vertical-align: middle; }
.grid-control { min-width: 115px; margin: 0; color: var(--muted); font-size: .72rem; text-align: center; }
.grid-control strong { display: block; color: var(--gold); margin-top: 3px; }
.turn-fighter { margin: 4px 0; padding: 4px 8px; font: inherit; white-space: nowrap; }
canvas.target-cell { cursor: pointer; }
progress { display: block; width: 100%; height: 7px; margin-top: 7px; border: 0; border-radius: 10px; accent-color: #98bb6b; overflow: hidden; }
progress::-webkit-progress-bar { background: #423e36; }
progress::-webkit-progress-value { border-radius: 10px; background: #98bb6b; }
progress::-moz-progress-bar { border-radius: 10px; background: #98bb6b; }
.enemy progress::-webkit-progress-value { background: #e8895c; }
.enemy progress::-moz-progress-bar { background: #e8895c; }

.battle-caption {
  background: #332a1fee;
  border: 2px solid #e1ba7d;
  border-radius: 5px 9px 5px 8px;
}

.battle-caption strong { color: var(--gold); font-size: .94rem; }
.battle-caption span { color: #eee4d5; min-height: 1.1em; }
.battle-controls { justify-content: center; }
.actions { width: 100%; justify-content: center; gap: 8px; }
.action { justify-content: center; gap: 9px; min-height: 54px; min-width: 0; width: 100%; max-width: 240px; padding: 7px 10px; background: #373b2c; border: 1px solid #786e50; border-radius: 5px 8px 4px 7px; box-shadow: 2px 3px #161711; }
.action span { display: grid; text-align: left; line-height: 1.19; }
.action small { color: #d5d8c7; font-size: .73rem; }
.action.attack { background: var(--gold); border-color: #ffd28d; color: var(--ink); }
.action.attack small { color: #432d17; }
.action:not(:disabled):hover { filter: brightness(1.12); }
.action:disabled { opacity: .53; }
.action.chosen:disabled { opacity: 1; border-color: #ffd798; box-shadow: 0 0 0 2px #ad773e, 2px 3px #161711; }
.action.leave { max-width: 280px; font-weight: 750; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }

@media (pointer: coarse), (max-width: 720px) {
  .keyboard { display: none; }
}

@media (max-width: 560px) {
  .game { width: calc(100% - 20px); min-width: 0; max-width: none; padding-top: 10px; }
  .topbar { margin-bottom: 10px; }
  .stage { border-radius: 9px; }
  .scene-label { top: 6px; left: 6px; padding: 5px 7px; }
  .eyebrow { font-size: .55rem; }
  .scene-label h2, .scene-label p:last-child { font-size: .75rem; margin: 2px 0; }
  .inventory { gap: 5px; flex-wrap: wrap; }
  .inventory > p { display: none; }
  .slots { gap: 3px; }
  .slot { gap: 1px; padding: 4px 3px; font-size: .63rem; }
  .bottom-bar:not(.battle-controls) { flex-wrap: wrap; }
  .health-row { padding: 6px; }
  .health-card { width: 44%; padding: 5px; }
  .round-stamp { display: none; }
  .battle-controls { flex-wrap: wrap; }
  .grid-control { display: flex; gap: 7px; align-items: baseline; justify-content: center; width: 100%; }
  .grid-control strong { margin: 0; }
  .health-label { font-size: .63rem; }
  .health-card progress { height: 5px; margin-top: 4px; }
  .battle-caption { font-size: .63rem; padding: 4px 6px; }
  .battle-caption strong { font-size: .69rem; }
  .action { padding: 6px; gap: 4px; }
  .action strong { font-size: .8rem; }
  .action small { font-size: .6rem; }
  .feedback, .interact { font-size: .66rem; padding: 4px 6px; }
}
