@font-face {
  font-family: Magic;
  src: url("./assets/common/game.ttf") format("truetype");
  font-display: swap;
}

:root {
  color-scheme: dark;
  --ink: #f0e9d2;
  --muted: #c4bda8;
  --gold: #edcc7d;
  --gold-dark: #6b4b24;
  --stone: #292b36;
  --stone-light: #4f5061;
  --danger: #ffaaaa;
  --success: #c0e7a8;
  font-family: Magic, "Noto Serif CJK SC", serif;
  color: var(--ink);
  background: #2e221c;
  font-synthesis: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  min-width: 280px;
  min-height: 100svh;
  background: radial-gradient(ellipse at 50% 25%, #1e18102b, #151011dc), url("./assets/common/game_lobby_bg.png") center / 720px 410px;
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  box-shadow: inset 0 0 100px #100c0a80;
  z-index: -1;
}
button, select, input { font: inherit; }
button { cursor: pointer; color: inherit; -webkit-tap-highlight-color: transparent; }
button:disabled { cursor: not-allowed; opacity: 0.5; }
button:focus-visible, select:focus-visible, input:focus-visible, canvas:focus-visible { outline: 2px solid #fff3c6; outline-offset: 4px; }
button, a, input, select { touch-action: manipulation; }
button:not(:disabled):active { transform: translateY(1px); }
button:hover:not(:disabled) { filter: brightness(1.14); }
button { transition: filter 120ms ease; }
h1, h2, h3, p { margin: 0; }
kbd { font-family: inherit; font-size: 0.8em; color: #cdc7b0; }
.muted { color: var(--muted); }
.sprite-icon { width: 32px; height: 32px; image-rendering: pixelated; flex-shrink: 0; vertical-align: middle; }
.text-button { border: 0; background: none; color: #f0d7a4; padding: 8px 0; }
.gold-button, .stone-button {
  border: 1px solid #979198;
  border-radius: 2px;
  background: linear-gradient(#51515c, #353540);
  box-shadow: inset 1px 1px 0 #ffffff2e, inset -1px -1px 0 #0009, 0 2px 0 #171619;
  padding: 10px 16px;
  min-height: 40px;
  color: #fff6dd;
}
.gold-button {
  color: #342618;
  text-shadow: 0 1px #f6e5b87a;
  border-color: #bba169;
  background: linear-gradient(#ddc181, #b38e4a);
  box-shadow: inset 1px 1px 0 #ffedb5, inset -1px -1px 0 #6d4d24, 0 2px 0 #201914;
}
.lobby { width: min(940px, 100%); margin: 0 auto; padding: 8vh 28px 28px; }
.lobby-heading { text-align: center; text-shadow: 0 2px 2px #100c08; }
.language-control { display: flex; align-items: center; justify-content: flex-end; gap: 10px; margin-bottom: 18px; font-size: 13px; color: var(--gold); }
.language-control select { min-height: 38px; padding: 6px 10px; border: 1px solid #a08151; background: #302820; color: var(--ink); }
.language-message { text-align: center; font-size: 12px; color: var(--gold); line-height: 1.6; margin-top: 14px; }
.lobby:lang(en) h1 { font-size: clamp(36px, 8vw, 78px); }
.eyebrow { font-size: 13px; color: var(--gold); letter-spacing: 3px; }
.lobby h1 { margin: 14px 0 10px; font-size: clamp(58px, 9vw, 88px); font-weight: 400; color: #fff1bc; text-shadow: 3px 3px #6b421a, 5px 5px #1d140e; }
.lobby-heading p { color: #e4d5b9; font-size: 15px; }
.tower-choices { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; margin: 38px 0 24px; }
.tower-card {
  display: grid;
  grid-template-columns: 124px 1fr;
  gap: 16px;
  align-content: start;
  padding: 22px;
  border: 2px solid #a08151;
  outline: 1px solid #24180f;
  outline-offset: 3px;
  background: linear-gradient(135deg, #3b3026ed, #231c17f5);
  box-shadow: inset 0 0 0 3px #52422e, 0 12px 22px #160e0966;
  animation: enter 450ms ease-out both;
}
.tower-card:nth-child(2) { animation-delay: 90ms; }
.tower-preview { width: 124px; height: 124px; image-rendering: pixelated; border: 3px solid #95774e; grid-row: span 2; }
.tower-meta { font-size: 10px; letter-spacing: 2px; color: #c4a974; }
.tower-card h2 { font-size: 25px; font-weight: 400; margin: 8px 0; color: #f7dda8; }
.tower-card p { font-size: 13px; line-height: 1.7; color: #d3c3a8; }
.tower-actions { grid-column: 1 / -1; display: grid; gap: 10px; margin-top: 4px; }
.tower-actions button { width: 100%; }
.tower-save { grid-column: 1 / -1; font-size: 11px; min-height: 16px; color: #bea57e; }
.lobby-footer { text-align: center; color: #c2af90; font-size: 12px; line-height: 1.8; }
.lobby-footer > span { letter-spacing: 2px; color: #dfc38b; }
.lobby-footer p { margin-top: 10px; }
.loading { text-align: center; margin: 60px 0; color: var(--gold); }
.error-message { padding: 18px; border: 1px solid #b7856b; background: #302124; color: #ffccc0; line-height: 1.7; }
.game { width: min(1120px, 100%); margin: 0 auto; padding: 20px; }
.game-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0 0 14px; }
.game-heading h1 { color: #ecd4a7; font-size: 17px; font-weight: 400; }
.game-heading button { font-size: 12px; }
.save-status { font-size: 11px; color: #c4bda4; }
.save-status.error { color: var(--danger); }
.game-shell {
  width: 100%;
  display: grid;
  grid-template-columns: 150fr 420fr 150fr;
  aspect-ratio: 720 / 410;
  background: #292733;
  border: 3px solid #3b2a1b;
  outline: 1px solid #927045;
  box-shadow: 0 12px 36px #09080780;
  container-type: inline-size;
}
.status-panel {
  min-width: 0;
  padding: 7% 7%;
  display: flex;
  flex-direction: column;
  gap: 3%;
  background: linear-gradient(#484a57, #353744) center / 90% 97% no-repeat, var(--left-panel, linear-gradient(#535664, #363843)) center / 100% 100%;
  font-size: clamp(10px, 1.6cqw, 18px);
}
.hero-heading { display: flex; align-items: center; gap: 6%; background: #242630; padding: 3% 5%; border: 1px solid #777887; min-height: 12%; }
.hero-heading .sprite-icon { width: 4.4cqw; height: 4.4cqw; }
.hero-heading strong { color: #f2deb5; font-weight: 400; }
.hero-heading small { display: block; margin-top: 4px; font-size: 0.65em; color: #c0bea9; }
.stats { display: grid; gap: 7px; background: #353541; padding: 4%; border: 1px solid #696a77; }
.stat-row { display: grid; align-items: center; grid-template-columns: 18% 1fr auto; gap: 4%; white-space: nowrap; }
.stat-row > span:nth-child(2) { font-size: 0.85em; color: #d0ccbd; }
.stat-row strong { font-size: 1em; font-weight: 400; font-variant-numeric: tabular-nums; }
.hp-row strong { color: #ffcdc8; }
.stat-icon img { width: 100%; image-rendering: pixelated; vertical-align: middle; }
.exp-mark { text-align: center; color: var(--gold); font-size: 0.8em; }
.keys { display: flex; justify-content: space-between; gap: 4px; padding: 5% 2%; background: #343541; border: 1px solid #787787; }
.key-count { display: flex; align-items: center; font-size: 0.9em; min-width: 0; }
.key-count img { width: 1.8cqw; height: 1.8cqw; image-rendering: pixelated; }
.key-count.yellow { color: #ffdf88; }
.key-count.blue { color: #b0d6fa; }
.key-count.red { color: #ffb5ad; }
.equipment { display: grid; gap: 3px; padding: 3%; background: #30313e; border: 1px solid #777887; }
.equipment > div { display: flex; align-items: center; gap: 6px; font-size: 0.76em; min-height: 26px; }
.equipment .sprite-icon { width: 3cqw; height: 3cqw; }
.inspect { background: #292b36; border: 1px solid #777887; padding: 8%; flex: 1; min-height: 0; font-size: 0.76em; line-height: 1.65; }
.inspect-title { display: flex; align-items: center; gap: 4%; margin-bottom: 7px; color: var(--gold); }
.inspect-title .sprite-icon { width: 3.5cqw; height: 3.5cqw; }
.inspect-damage { color: var(--gold); margin-top: 5px; }
.map-frame { position: relative; min-width: 0; background: var(--map-frame, #5f402b) center / 100% 100%; aspect-ratio: 420 / 410; }
.floor-title { position: absolute; inset: 1.4% 0 auto; text-align: center; font-size: 1.8cqw; font-weight: 400; color: #ffe6b5; text-shadow: 1px 1px #1c140a; line-height: 1.2; }
.map { position: absolute; left: 8.095238%; top: 7.07317%; width: 83.809524%; height: 85.853659%; image-rendering: pixelated; touch-action: none; cursor: crosshair; outline-offset: 1px !important; }
.frame-caption { position: absolute; bottom: 2%; inset-inline: 0; text-align: center; letter-spacing: 3px; font-size: 0.82cqw; color: #d2ac79; text-shadow: 1px 1px #28180d; }
.tools-panel { min-width: 0; display: flex; flex-direction: column; gap: 3%; padding: 7% 7%; background: linear-gradient(#484a57, #353744) center / 90% 97% no-repeat, var(--right-panel, #454555) center / 100% 100%; font-size: clamp(10px, 1.5cqw, 16px); }
.tool-shortcuts { display: grid; gap: 6px; }
.tool-button { display: flex; align-items: center; gap: 6%; width: 100%; min-height: 6cqw; padding: 4% 5%; border: 1px solid #90909e; background: linear-gradient(#3f424f, #2e303d); box-shadow: inset 1px 1px #b4aec32e, inset -1px -1px #161820; text-align: left; }
.tool-button > span:last-child { display: flex; flex: 1; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 3px; }
.tool-button > span:last-child, .tool-button > span:last-child > span { min-width: 0; overflow-wrap: anywhere; }
.tool-button .sprite-icon { width: 3.8cqw; height: 3.8cqw; }
.tool-button.locked { color: #aaabb3; }
.tool-button.locked .sprite-icon { opacity: 0.4; filter: grayscale(1); }
.pocket { min-height: 10cqw; flex: 1; display: flex; flex-wrap: wrap; align-content: start; padding: 5%; gap: 4px; background: #272935; border: 1px solid #7b7b8b; }
.pocket > .muted { align-self: center; font-size: 0.8em; line-height: 1.8; }
.pocket-item { position: relative; width: 4cqw; height: 4cqw; background: #3a3c49; border: 1px solid #626371; padding: 0; }
.pocket-item .sprite-icon { width: 100%; height: 100%; }
.pocket-item small { position: absolute; right: 0; bottom: -2px; color: #ffedb1; font-size: 0.7em; text-shadow: 1px 1px #000; }
.menu-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.menu-buttons button { min-height: 3.8cqw; padding: 8% 1%; font-size: 0.86em; }
.menu-buttons kbd { margin-left: 2px; }
.dpad { display: none; }
.game-footer { padding: 16px 0 0; }
.game-message { min-height: 42px; font-size: 14px; text-align: center; color: #f0dab0; line-height: 1.6; }
.keyboard-hint { color: #b9aa90; font-size: 11px; text-align: center; margin-top: 8px; }
.outcome { margin-top: 20px; padding: 20px; border: 1px solid var(--gold); background: #251d15e8; text-align: center; }
.outcome h2 { color: var(--gold); font-weight: 400; margin-bottom: 12px; }
.outcome p { line-height: 1.8; font-size: 14px; }
.outcome button { margin: 12px 6px 0; }
.game-dialog { padding: 0; width: min(540px, calc(100% - 24px)); max-height: calc(100dvh - 32px); border: 3px solid #a18b65; outline: 1px solid #2a211b; color: var(--ink); background: linear-gradient(135deg, #363742, #242631); box-shadow: inset 0 0 0 1px #77717b, 0 14px 80px #000b; }
.game-dialog[open] { display: flex; flex-direction: column; animation: enter 150ms ease-out; }
.game-dialog::backdrop { background: #111017ad; }
.game-dialog h2 { flex: none; padding: 17px 22px 14px; border-bottom: 1px solid #686575; color: var(--gold); font-weight: 400; font-size: 20px; }
.dialog-body { padding: 22px; overflow: auto; overscroll-behavior: contain; line-height: 1.85; font-size: 15px; }
.dialog-actions { padding: 0 22px 20px; display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 10px; flex: none; }
.dialog-actions button { font-size: 14px; }
.conversation { display: flex; align-items: flex-start; gap: 18px; min-height: 96px; }
.conversation .sprite-icon { width: 64px; height: 64px; margin-top: 5px; background: #1a1b23; border: 2px solid #787784; }
.conversation p { white-space: pre-wrap; }
.conversation p, .inventory-item > div, .book-enemy > div { min-width: 0; overflow-wrap: anywhere; }
.choice-list { display: grid; gap: 10px; margin-top: 22px; }
.choice-list button { width: 100%; text-align: left; }
.wide-dialog { width: min(760px, calc(100% - 24px)); }
.book-list { display: grid; gap: 12px; }
.book-enemy { display: grid; grid-template-columns: 48px 1fr auto; gap: 12px; padding: 14px; border: 1px solid #666674; background: #282a35; }
.book-enemy .sprite-icon { width: 48px; height: 48px; }
.book-enemy h3 { font-size: 16px; color: #ecdba7; font-weight: 400; }
.enemy-values { display: flex; flex-wrap: wrap; gap: 0 15px; color: #dbd6c5; font-size: 13px; }
.enemy-ability { font-size: 12px; color: #d6bd96; }
.enemy-damage { text-align: right; align-self: center; font-size: 13px; color: var(--gold); }
.enemy-damage small { display: block; color: #c8c3b4; font-size: 11px; }
.danger { color: var(--danger) !important; }
.safe { color: var(--success) !important; }
.empty-state { color: #c8c4b9; text-align: center; padding: 25px 6px; }
.floor-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; margin-top: 18px; }
.floor-grid button { padding: 10px 2px; }
.floor-grid .current { border-color: #edcf8c; color: var(--gold); background: #5a4b35; }
.inventory-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.inventory-item { display: flex; gap: 10px; align-items: center; padding: 12px; text-align: left; background: #2c2f39; border: 1px solid #737181; }
.inventory-item .sprite-icon { width: 40px; height: 40px; }
.inventory-item strong { display: block; font-weight: 400; color: #f1daa6; font-size: 14px; }
.inventory-item small { color: #bebcad; font-size: 11px; line-height: 1.5; display: block; margin-top: 5px; }
.save-list { display: grid; gap: 9px; }
.save-slot { text-align: left; width: 100%; display: grid; gap: 5px; padding: 13px 15px; font-size: 14px; }
.save-slot small { color: #c2beaf; font-size: 11px; }
.setting-row { display: flex; justify-content: space-between; gap: 20px; align-items: center; padding: 12px 0; border-bottom: 1px solid #51515f; }
.setting-row input { width: 20px; height: 20px; accent-color: #d3b773; }
.setting-row input, .setting-row select { flex-shrink: 0; }
.setting-row select { padding: 6px; border: 1px solid #797480; background: #232530; color: #f5e4bc; }
.help-text p + p { margin-top: 15px; }
.note-entry { padding: 12px 0; border-bottom: 1px solid #555260; }
.note-entry h3 { color: var(--gold); font-size: 13px; font-weight: 400; margin-bottom: 8px; }
.note-entry p { font-size: 14px; white-space: pre-wrap; }
@keyframes enter { from { opacity: 0; transform: translateY(9px); } to { opacity: 1; transform: translateY(0); } }

@media (min-width: 701px) {
  .game { width: min(1120px, calc((100dvh - 160px) * 720 / 410 + 40px)); min-width: 680px; }
}
@media (max-width: 860px) {
  .lobby { padding-top: 40px; }
  .tower-card { grid-template-columns: 88px 1fr; padding: 18px; gap: 12px; }
  .tower-preview { width: 88px; height: 88px; }
  .tower-card h2 { font-size: 22px; }
  .tower-card p { font-size: 12px; }
  .tower-meta { font-size: 9px; }
  .stats { gap: 4px; }
}
@media (pointer: coarse) {
  .dpad { display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); gap: 2px; width: 80%; aspect-ratio: 1; align-self: center; max-height: 115px; }
  .dpad button { border: 1px solid #a49b86; background: linear-gradient(#62606b, #3b3b49); color: #efddbc; padding: 0; touch-action: none; min-width: 0; border-radius: 3px; }
  .dpad [data-direction="up"] { grid-area: 1 / 2; }
  .dpad [data-direction="left"] { grid-area: 2 / 1; }
  .dpad [data-direction="right"] { grid-area: 2 / 3; }
  .dpad [data-direction="down"] { grid-area: 3 / 2; }
  .dpad-center { grid-area: 2 / 2; display: grid; place-items: center; background: #323440; color: #b2aa94; }
  .tools-panel { gap: 2%; }
  .pocket { min-height: 0; }
  .keyboard-hint { display: none; }
}
@media (max-width: 700px) and (orientation: portrait), (max-width: 520px) {
  .lobby { padding: 28px 20px 20px; }
  .lobby h1 { margin: 10px 0; }
  .lobby-heading p { font-size: 12px; }
  .eyebrow { font-size: 10px; letter-spacing: 2px; }
  .tower-choices { grid-template-columns: 1fr; gap: 18px; margin: 24px 0; }
  .tower-card { grid-template-columns: 88px 1fr; gap: 10px 16px; }
  .tower-preview { grid-row: 1 / 3; }
  .tower-card h2 { margin: 6px 0; }
  .tower-actions { grid-template-columns: 1fr 1fr; margin: 0; }
  .tower-actions button { font-size: 13px; padding: 10px 4px; }
  .lobby-footer { font-size: 10px; }
  .game { padding: 8px max(8px, env(safe-area-inset-left)) 14px; width: min(540px, 100%); }
  .game-heading { gap: 5px; margin-bottom: 8px; flex-wrap: wrap; }
  .game-heading h1 { font-size: 13px; }
  .game-heading button { font-size: 11px; }
  .save-status { font-size: 9px; }
  .game-shell { display: flex; flex-direction: column; aspect-ratio: auto; border-width: 2px; }
  .status-panel { display: grid; grid-template-columns: 57px 1fr; gap: 6px 9px; padding: 9px; background: linear-gradient(#484959, #333440); font-size: 12px; }
  .hero-heading { grid-row: span 2; flex-direction: column; padding: 5px 2px; gap: 2px; text-align: center; }
  .hero-heading .sprite-icon { width: 32px; height: 32px; }
  .hero-heading strong { font-size: 11px; }
  .hero-heading small { font-size: 8px; margin-top: 2px; }
  .stats { grid-template-columns: 1fr 1fr; gap: 5px 12px; border: 0; padding: 0; background: none; }
  .stat-row { grid-template-columns: 15px 26px 1fr; gap: 4px; }
  .stat-row strong { text-align: right; }
  .hp-row { grid-column: span 2; }
  .hp-row strong { font-size: 16px; }
  #exp-row { display: none; }
  .keys { grid-column: 2; padding: 5px 8px; }
  .key-count { font-size: 12px; gap: 6px; }
  .key-count img { width: 16px; height: 16px; }
  .equipment, .inspect { display: none; }
  .map-frame { width: 100%; }
  .floor-title { font-size: 3.1cqw; }
  .frame-caption { font-size: 1.5cqw; }
  .tools-panel { display: grid; grid-template-columns: 1fr 102px; gap: 8px 10px; padding: 10px; background: linear-gradient(#494a5b, #333541); font-size: 12px; }
  .tool-shortcuts { grid-template-columns: 1fr 1fr; gap: 6px; grid-column: 1; }
  .tool-button { min-height: 38px; padding: 4px 6px; gap: 4px; font-size: 11px; }
  .tool-button .sprite-icon { width: 25px; height: 25px; }
  .tool-button kbd { display: none; }
  .pocket { display: none; }
  .menu-buttons { grid-column: 1 / -1; grid-template-columns: repeat(4, 1fr); gap: 7px; }
  .menu-buttons button { min-height: 33px; padding: 6px 0; font-size: 12px; }
  .menu-buttons kbd { display: none; }
  .dpad { grid-column: 2; grid-row: 1; width: 102px; height: 102px; max-height: none; display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); gap: 3px; }
  .dpad button { border: 1px solid #a49b86; background: linear-gradient(#65636e, #3b3b49); color: #efddbc; padding: 0; touch-action: none; border-radius: 3px; }
  .dpad [data-direction="up"] { grid-area: 1 / 2; }
  .dpad [data-direction="left"] { grid-area: 2 / 1; }
  .dpad [data-direction="right"] { grid-area: 2 / 3; }
  .dpad [data-direction="down"] { grid-area: 3 / 2; }
  .dpad-center { grid-area: 2 / 2; display: grid; place-items: center; background: #333541; color: #b2aa94; }
  .game-footer { padding-top: 10px; }
  .game-message { font-size: 11px; min-height: 36px; padding-inline: 6px; }
  .keyboard-hint { display: none; }
  .game-dialog h2 { padding: 13px 15px; font-size: 18px; }
  .dialog-body { padding: 15px; font-size: 14px; }
  .dialog-actions { padding: 0 15px 15px; }
  .conversation { gap: 12px; }
  .conversation .sprite-icon { width: 48px; height: 48px; }
  .book-enemy { grid-template-columns: 36px 1fr; gap: 8px; padding: 10px; }
  .book-enemy .sprite-icon { width: 36px; height: 36px; }
  .book-enemy h3 { font-size: 14px; }
  .enemy-values { font-size: 11px; gap: 0 8px; }
  .enemy-damage { grid-column: 2; text-align: left; font-size: 12px; }
  .enemy-damage small { display: inline; margin-left: 12px; }
  .floor-grid { grid-template-columns: repeat(5, 1fr); gap: 7px; }
  .inventory-grid { grid-template-columns: 1fr; }
}
@media (max-width: 360px) {
  .tool-button:lang(en) { flex-direction: column; gap: 2px; padding: 4px 2px; }
  .tool-button:lang(en) > span:last-child { flex: none; justify-content: center; }
}
@media (orientation: landscape) and (max-height: 520px) {
  .game { padding: 4px max(8px, env(safe-area-inset-left)); width: min(100%, calc((100dvh - 64px) * 720 / 410 + 16px)); min-width: 0; }
  .game-heading { margin-bottom: 3px; }
  .game-heading h1 { font-size: 11px; }
  .game-heading button { padding: 3px 0; font-size: 10px; }
  .save-status { font-size: 9px; }
  .game-footer { padding-top: 5px; }
  .game-message { font-size: 10px; min-height: 18px; }
  .keyboard-hint, .inspect, .pocket { display: none; }
  .stats { gap: 3px; }
  .status-panel { gap: 4%; }
  .hero-heading small { display: none; }
  .tool-shortcuts { gap: 3px; }
  .tool-button { min-height: 0; padding: 3px; font-size: 9px; }
  .tool-button .sprite-icon { width: 3cqw; height: 3cqw; }
  .tool-button kbd, .menu-buttons kbd { display: none; }
  .menu-buttons { gap: 4px; }
  .menu-buttons button { min-height: 23px; padding: 2px; font-size: 9px; }
  .dpad { width: 65%; max-height: 85px; margin-top: auto; }
  .game-dialog { max-height: calc(100dvh - 12px); }
  .game-dialog h2 { padding: 10px 20px; font-size: 17px; }
  .dialog-body { padding: 14px 20px; }
  .dialog-actions { padding-bottom: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
