:root {
  color-scheme: dark;
  --ink: #2d1e2f;
  --cream: #f8e7c5;
  --paper: #fff5df;
  --terracotta: #c86855;
  --berry: #6f3b49;
  --berry-dark: #3f2938;
  --sage: #6f8a5e;
  --sage-dark: #41543e;
  --gold: #e4af55;
  --sky: #92b7a5;
  --shadow: rgba(45, 30, 47, .35);
  --pixel-border: 4px solid var(--ink);
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  color: var(--cream);
  background:
    radial-gradient(circle at 20% 20%, rgba(228, 175, 85, .18), transparent 28rem),
    linear-gradient(160deg, #2c2638 0%, #4a2d3d 48%, #253d38 100%);
  overflow-x: hidden;
}

button, input, select { font: inherit; }
button { cursor: pointer; }

.hidden { display: none !important; }

.page-shell { width: min(1180px, 100%); margin: 0 auto; padding: 22px 26px 18px; }

.brand-bar, .page-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.brand-bar { margin-bottom: 14px; }
.brand-bar h1 { margin: 0; font-family: Georgia, serif; font-size: clamp(32px, 5vw, 56px); line-height: .85; letter-spacing: -.04em; color: #ffd77a; text-shadow: 3px 3px 0 var(--berry-dark); }
.eyebrow, .kicker { margin: 0 0 6px; font-size: 11px; font-weight: 800; letter-spacing: .2em; color: #d5c69d; }
.header-actions { display: flex; align-items: center; gap: 9px; }
.status-pill, .icon-button { border: 2px solid rgba(255,255,255,.18); background: rgba(20,19,29,.36); color: var(--cream); box-shadow: 3px 3px 0 rgba(20,19,29,.45); }
.status-pill { padding: 8px 12px; font-size: 12px; font-weight: 700; }
.icon-button { min-width: 44px; min-height: 38px; }

.game-frame { border: var(--pixel-border); background: #1d1823; box-shadow: 10px 10px 0 rgba(19, 17, 25, .62), 0 18px 60px rgba(0,0,0,.28); }
.canvas-wrap { position: relative; aspect-ratio: 30 / 17; overflow: hidden; }
#gameCanvas { display: block; width: 100%; height: 100%; image-rendering: pixelated; background: #889b67; }
.canvas-vignette { position: absolute; inset: 0; pointer-events: none; box-shadow: inset 0 0 80px rgba(50,27,38,.24); }

.panel { color: var(--ink); background: var(--paper); border: var(--pixel-border); box-shadow: 8px 8px 0 var(--shadow); }
.overlay-panel { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(560px, 88%); padding: 34px; }
.main-menu { text-align: center; background: linear-gradient(#fff5df 0 72%, #ecd6ad 72%); }
.main-menu h2 { margin: 0; font-family: Georgia, serif; font-size: clamp(54px, 9vw, 88px); line-height: .95; color: var(--berry); letter-spacing: -.055em; }
.menu-subtitle { margin: 14px 0 24px; color: #71545a; }
.menu-actions { display: grid; gap: 10px; width: min(310px, 100%); margin: 0 auto; }

.primary-button, .secondary-button, .save-button, .shop-item {
  border: 3px solid var(--ink);
  min-height: 48px;
  font-weight: 800;
  box-shadow: 4px 4px 0 var(--ink);
  transition: transform .12s ease, box-shadow .12s ease, filter .12s ease;
}
.primary-button { color: #fff7e4; background: var(--terracotta); }
.secondary-button { color: var(--ink); background: var(--gold); }
.primary-button:hover, .secondary-button:hover, .save-button:hover, .shop-item:hover { filter: brightness(1.06); transform: translate(-1px, -1px); box-shadow: 5px 5px 0 var(--ink); }
.primary-button:active, .secondary-button:active, .save-button:active, .shop-item:active { transform: translate(2px, 2px); box-shadow: 2px 2px 0 var(--ink); }
.primary-button:disabled, .secondary-button:disabled { opacity: .55; cursor: not-allowed; }
.microcopy { min-height: 20px; margin: 14px 0 0; font-size: 13px; color: #795c5e; }
.controls-copy { margin: 30px -24px -24px; padding: 16px; background: rgba(111,138,94,.15); font-size: 12px; color: #54404a; }

.form-panel { width: min(640px, 92%); max-height: 92%; overflow: auto; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.panel-heading h2, .modal-title-row h2 { margin: 0; font-family: Georgia, serif; font-size: 36px; color: var(--berry); }
.character-preview { width: 88px; height: 88px; border: 3px solid var(--ink); background: linear-gradient(#9ac0ad 0 55%, #7fa269 55%); image-rendering: pixelated; box-shadow: 4px 4px 0 #d3aa67; }
.character-form { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.character-form label { display: grid; gap: 6px; font-size: 13px; font-weight: 800; color: #59414a; }
.character-form input, .character-form select { width: 100%; min-height: 44px; padding: 8px 10px; border: 3px solid var(--ink); background: #fffaf0; color: var(--ink); }
.form-submit { grid-column: 1 / -1; margin-top: 6px; }

.hud { position: absolute; inset: 14px 14px auto 14px; display: flex; align-items: flex-start; gap: 10px; pointer-events: none; }
.hud-card { display: grid; gap: 2px; padding: 9px 12px; color: var(--ink); background: rgba(255,245,223,.94); border: 3px solid var(--ink); box-shadow: 4px 4px 0 rgba(45,30,47,.32); font-size: clamp(10px, 1.4vw, 13px); }
.hud-summary { min-width: 130px; }
.quest-card { min-width: 200px; }
.quest-card strong { color: var(--berry); }
.quest-card span.done { text-decoration: line-through; color: var(--sage-dark); }
.save-button { margin-left: auto; pointer-events: auto; padding: 8px 13px; min-height: 38px; color: var(--cream); background: var(--berry); font-size: 12px; }

.hotbar { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); display: grid; grid-template-columns: repeat(8, 46px); gap: 4px; padding: 6px; background: rgba(63,41,56,.9); border: 3px solid var(--ink); box-shadow: 4px 4px 0 rgba(45,30,47,.4); }
.hotbar-slot, .inventory-slot { position: relative; display: grid; place-items: center; border: 2px solid #8c654f; background: #efd4a7; color: var(--ink); font-size: 23px; }
.item-icon { width: 30px; height: 30px; overflow: visible; image-rendering: pixelated; }
.item-icon .wood { fill: none; stroke: #7b4b2d; }
.item-icon .metal { fill: #9aa3a6; stroke: #3d4549; }
.item-icon .can { fill: #6f9e9b; stroke: #314b50; }
.item-icon .water { fill: #5aa9c7; stroke: none; }
.hotbar-slot { width: 46px; height: 42px; }
.hotbar-slot.selected { outline: 3px solid #fff3a6; background: #f6c85f; transform: translateY(-3px); }
.slot-number { position: absolute; left: 3px; top: 1px; font-size: 9px; font-weight: 900; opacity: .65; }

.interaction-prompt { position: absolute; left: 50%; bottom: 78px; transform: translateX(-50%); max-width: 80%; padding: 9px 14px; border: 3px solid var(--ink); background: rgba(255,245,223,.94); color: var(--ink); box-shadow: 4px 4px 0 rgba(45,30,47,.38); font-size: 13px; font-weight: 800; text-align: center; }
.toast { position: absolute; left: 50%; top: 76px; transform: translateX(-50%); padding: 10px 16px; border: 3px solid var(--ink); background: #f6c85f; color: var(--ink); box-shadow: 4px 4px 0 rgba(45,30,47,.38); font-weight: 800; z-index: 9; }

.dialogue-panel { position: absolute; left: 4%; right: 4%; bottom: 76px; display: grid; grid-template-columns: 76px 1fr; gap: 14px; padding: 14px; border: var(--pixel-border); color: var(--ink); background: rgba(255,245,223,.97); box-shadow: 7px 7px 0 rgba(45,30,47,.45); z-index: 8; }
.portrait { width: 72px; height: 72px; display: grid; place-items: end center; overflow: hidden; border: 3px solid var(--ink); background: #d8b16a; }
.portrait span { display: block; width: 44px; height: 58px; background: linear-gradient(#312c38 0 32%, #b66a4a 32% 45%, #617b50 45%); border: 3px solid var(--ink); border-bottom: 0; }
.dialogue-copy strong { color: var(--berry); }
.dialogue-copy p { margin: 5px 0 10px; line-height: 1.55; }
.dialogue-actions { display: flex; gap: 8px; justify-content: flex-end; }
.dialogue-actions button { border: 2px solid var(--ink); padding: 6px 11px; background: var(--gold); color: var(--ink); font-weight: 800; }

.modal-panel { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(540px, 90%); padding: 22px; z-index: 10; }
.modal-title-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.close-button { border: 3px solid var(--ink); width: 38px; height: 38px; background: var(--terracotta); color: white; font-size: 22px; font-weight: 900; }
.inventory-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 7px; }
.inventory-slot { aspect-ratio: 1; min-width: 0; font-size: clamp(16px, 3vw, 26px); }
.inventory-slot small { position: absolute; right: 3px; bottom: 1px; font-size: 9px; }
.shop-list { display: grid; gap: 12px; }
.shop-item { display: grid; grid-template-columns: 42px 1fr auto; align-items: center; gap: 10px; padding: 10px 13px; text-align: left; color: var(--ink); background: #efd4a7; }
.shop-item span { font-size: 28px; text-align: center; color: #8a614d; }
.shop-item em { font-style: normal; color: var(--berry); }

.page-footer { padding: 14px 2px 0; font-size: 11px; color: #d8c9af; opacity: .86; }
.page-footer p { margin: 0; }

@media (max-width: 720px) {
  .page-shell { padding: 10px; }
  .brand-bar h1 { font-size: 36px; }
  .status-pill { display: none; }
  .overlay-panel { padding: 22px; }
  .character-form { grid-template-columns: 1fr; }
  .form-submit { grid-column: 1; }
  .quest-card { display: none; }
  .hotbar { grid-template-columns: repeat(8, 34px); }
  .hotbar-slot { width: 34px; height: 34px; font-size: 17px; }
  .inventory-grid { grid-template-columns: repeat(4, 1fr); }
  .page-footer { display: block; }
}

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

