:root {
  --gold: #F2B457;
  --moss: #7FA84E;
  --pine: #3F5A38;
  --clay: #8A5B39;
  --stone: #6E7C8B;
  --dusk: #2C3A4C;
  --cyan: #86C9D6;
  --cream: #F6E9CB;
  --ink: #17202b;
  --plate-bg: rgba(28, 38, 51, 0.86);
}
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; width: 100%; height: 100%;
  overflow: hidden; background: var(--cream); color: var(--cream);
  font-family: 'Silkscreen', monospace;
  -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent;
}
#scene { position: fixed; inset: 0; overflow: hidden; }
#scene canvas { display: block; width: 100% !important; height: 100% !important; touch-action: none; outline: none; }
.hidden { display: none !important; }
.plate {
  background: var(--plate-bg); border: 2px solid var(--ink);
  box-shadow: inset 0 0 0 2px rgba(242, 180, 87, 0.55);
  padding: 4px 8px; color: #f7edd6; font-size: 11px; letter-spacing: 0.06em;
  line-height: 1.35; text-shadow: 1px 1px 0 #101720;
}
.pixel-btn {
  font-family: 'Silkscreen', monospace; font-size: 11px; letter-spacing: 0.06em;
  color: var(--cream); background: var(--dusk); border: 2px solid var(--ink);
  box-shadow: inset 0 0 0 2px rgba(242, 180, 87, 0.6), 2px 2px 0 rgba(10, 16, 22, 0.55);
  padding: 8px 12px; cursor: pointer; text-transform: uppercase; border-radius: 0;
}
.pixel-btn:hover { background: #3a4a5e; }
.pixel-btn:active { transform: translate(1px, 1px); box-shadow: inset 0 0 0 2px rgba(242, 180, 87, 0.6); }
.pixel-btn.wide { display: block; width: 100%; margin-top: 10px; padding: 12px; }

/* HUD */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 20; }
#hud button { pointer-events: auto; }
#brand-corner { position: absolute; top: 12px; left: 12px; }
.wordmark {
  font-family: 'Pixelify Sans', sans-serif; font-weight: 700; line-height: 0.82;
  letter-spacing: 0.015em; text-transform: uppercase; color: var(--cream);
  display: flex; flex-direction: column; align-items: flex-start; white-space: nowrap;
  font-size: clamp(48px, 6.8vw, 86px);
  text-shadow:
    -2px 0 0 #1b2430, 2px 0 0 #1b2430, 0 -2px 0 #1b2430, 0 2px 0 #1b2430,
    -2px -2px 0 #1b2430, 2px -2px 0 #1b2430, -2px 2px 0 #1b2430, 2px 2px 0 #1b2430,
    4px 4px 0 #C0802F, 6px 6px 0 #8A5B39;
  filter: drop-shadow(3px 3px 0 rgba(10, 16, 24, 0.45));
}
.wordmark.corner {
  font-size: clamp(23px, 2.3vw, 30px);
  text-shadow:
    -1px 0 0 #1b2430, 1px 0 0 #1b2430, 0 -1px 0 #1b2430, 0 1px 0 #1b2430,
    -1px -1px 0 #1b2430, 1px -1px 0 #1b2430, -1px 1px 0 #1b2430, 1px 1px 0 #1b2430,
    2px 2px 0 #C0802F, 3px 3px 0 #8A5B39;
  filter: drop-shadow(2px 2px 0 rgba(10, 16, 24, 0.4));
}
#coords { position: absolute; top: calc(12px + clamp(44px, 5.7vw, 64px)); left: 12px; white-space: nowrap; font-size: 10px; background: rgba(28, 38, 51, 0.62); }
#top-right { position: absolute; top: 12px; right: 12px; display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; max-width: 62vw; }
#top-right .btn, #top-right .pb { }
#top-right .pixel-btn { padding: 6px 8px; font-size: 10px; }
#btn-help { min-width: 36px; font-size: 15px; line-height: 1; padding: 5px 9px 7px; }
#btn-mode { color: var(--gold); }
#crosshair { position: absolute; left: 50%; top: 50%; width: 26px; height: 26px; transform: translate(-50%, -50%); opacity: 0.94; }
#crosshair svg { width: 100%; height: 100%; display: block; shape-rendering: crispEdges; }
#status-row { position: absolute; left: 50%; bottom: calc(clamp(58px, 7.5vw, 76px) + 8px); transform: translateX(-50%); width: min(96vw, 620px); display: flex; align-items: flex-end; justify-content: space-between; gap: 8px; pointer-events: none; }
.pips { display: flex; gap: 2px; flex-wrap: nowrap; }
.pips canvas { width: clamp(15px, 2vw, 20px); height: auto; image-rendering: pixelated; display: block; }
#status-center { display: flex; flex-direction: column; align-items: center; gap: 5px; min-width: 0; }
#held-name { font-size: 10px; padding: 3px 9px; white-space: nowrap; }
#toast { position: absolute; left: 50%; bottom: calc(100% + 8px); transform: translateX(-50%); font-size: 10px; padding: 5px 12px; color: #ffe9b8; width: max-content; max-width: min(86vw, 520px); text-align: center; }
#hotbar { position: absolute; left: 50%; bottom: clamp(8px, 1.4vw, 14px); transform: translateX(-50%); display: flex; gap: 4px; padding: 6px; background: var(--dusk); border: 2px solid var(--ink); box-shadow: inset 0 0 0 3px var(--gold), 3px 3px 0 rgba(12, 18, 24, 0.5); pointer-events: auto; }
.slot { position: relative; width: clamp(31px, 4.4vw, 48px); height: clamp(31px, 4.4vw, 48px); background: #263243; border: 2px solid #131c26; box-shadow: inset 0 0 0 1px rgba(246, 233, 203, 0.09); display: grid; place-items: center; cursor: pointer; padding: 0; }
.slot img { width: 92%; height: 92%; object-fit: contain; image-rendering: pixelated; pointer-events: none; }
.slot.selected { outline: 3px solid var(--cream); outline-offset: 1px; z-index: 2; }
.slot .count { position: absolute; right: 1px; bottom: -1px; background: #141c26; color: var(--cream); font-size: clamp(7px, 1vw, 10px); padding: 0 3px 1px; line-height: 1.2; pointer-events: none; }
.slot .key { position: absolute; left: 2px; top: 0; color: rgba(246, 233, 203, 0.5); font-size: 8px; pointer-events: none; }
.slot.empty img { opacity: 0.25; }
#hint { position: absolute; left: 12px; bottom: 12px; font-size: 8px; max-width: 23vw; opacity: 0.9; background: rgba(28, 38, 51, 0.66); }
@media (max-width: 1100px) { #hint { display: none; } }

/* overlays */
.overlay { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 18px; background-color: rgba(18, 26, 36, 0.66); background-image: repeating-linear-gradient(0deg, rgba(246, 233, 203, 0.035) 0 2px, transparent 2px 6px), repeating-linear-gradient(90deg, rgba(246, 233, 203, 0.035) 0 2px, transparent 2px 6px); overflow: auto; }
.start-overlay { display: flex; flex-direction: column; justify-content: space-between; align-items: stretch; gap: 14px; padding: clamp(12px, 2.6vw, 30px); background-color: rgba(18, 26, 36, 0.12); background-image: none; overflow: auto; }
.start-overlay > * { flex: 0 0 auto; }
.start-top { max-width: min(540px, 80vw); }
#start-wordmark { display: flex; margin-bottom: 8px; }
.tagline { display: inline-block; margin: 6px 0 0; padding: 5px 10px; font-family: 'Pixelify Sans', sans-serif; font-size: clamp(15px, 2vw, 20px); color: #f0e3c6; letter-spacing: 0.03em; }
.start-panel { width: min(800px, 96vw); margin: 0 auto; padding: clamp(12px, 2vw, 20px); background: rgba(44, 58, 76, 0.95); border: 3px solid var(--ink); box-shadow: inset 0 0 0 3px var(--gold), 6px 6px 0 rgba(10, 16, 24, 0.5); text-align: center; }
.mode-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 0 auto 14px; }
.mode-card { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; text-align: left; padding: 14px; background: #35465a; border: 2px solid var(--ink); box-shadow: inset 0 0 0 2px rgba(242, 180, 87, 0.5), 3px 3px 0 rgba(10, 16, 24, 0.5); color: var(--cream); cursor: pointer; font-family: 'Silkscreen', monospace; border-radius: 0; }
.mode-card:hover, .mode-card:focus-visible { background: #40536a; outline: 2px solid var(--cream); }
.mode-title { font-family: 'Pixelify Sans', sans-serif; font-size: 24px; letter-spacing: 0.06em; color: var(--gold); }
.mode-desc { font-size: 10px; line-height: 1.5; color: #e7dcc2; letter-spacing: 0.03em; }
.start-controls { border-top: 2px solid rgba(246, 233, 203, 0.18); border-bottom: 2px solid rgba(246, 233, 203, 0.18); padding: 10px 0 8px; margin-bottom: 12px; }
.start-controls p { margin: 4px 0; font-size: 10px; color: #d7ccb4; line-height: 1.5; }
.start-controls b { color: var(--cream); }
.touch-copy { display: none; }
body.touch .touch-copy { display: block; }
body.touch .start-controls p:not(.touch-copy) { display: none; }
.start-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.start-status { font-size: 9px; color: #a9b4bd; letter-spacing: 0.1em; }
.menu-panel { width: min(480px, 92vw); max-height: 90vh; overflow: auto; padding: 22px; background: #2c3a4c; border: 3px solid var(--ink); box-shadow: inset 0 0 0 3px var(--gold), 6px 6px 0 rgba(10, 16, 24, 0.55); text-align: center; }
.menu-panel h2 { margin: 0 0 14px; font-family: 'Pixelify Sans', sans-serif; font-size: 30px; letter-spacing: 0.08em; color: var(--cream); text-shadow: 2px 2px 0 #9a6526; }
.menu-note { font-size: 9px; line-height: 1.6; color: #c8bda6; margin: 8px 0; }
#help-body { text-align: left; font-size: 10px; line-height: 1.8; color: #ece1c8; margin-bottom: 8px; }
#help-body .row { display: flex; justify-content: space-between; gap: 12px; border-bottom: 1px dashed rgba(246, 233, 203, 0.18); padding: 3px 0; }
#help-body .row b { color: var(--gold); font-weight: 400; white-space: nowrap; }
#help-body p { margin: 8px 0; color: #c8bda6; }
.inv-panel { width: min(540px, 94vw); }
#inv-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin: 10px 0 4px; }
.inv-cell { position: relative; aspect-ratio: 1 / 1; background: #263243; border: 2px solid #131c26; box-shadow: inset 0 0 0 1px rgba(246, 233, 203, 0.1); display: grid; place-items: center; cursor: pointer; padding: 2px; }
.inv-cell img { width: 90%; height: 90%; object-fit: contain; image-rendering: pixelated; }
.inv-cell.selected { outline: 3px solid var(--cream); outline-offset: 1px; }
.inv-cell .count { position: absolute; right: 2px; bottom: 1px; font-size: 9px; background: #141c26; padding: 0 3px; color: var(--cream); }
.inv-cell .iname { position: absolute; left: 0; right: 0; top: -1px; font-size: 6px; text-align: center; color: rgba(246, 233, 203, 0.55); letter-spacing: 0.02em; }

/* touch */
#touch-ui { position: fixed; inset: 0; z-index: 25; pointer-events: none; }
#stick-base { position: absolute; left: max(16px, env(safe-area-inset-left)); bottom: max(92px, calc(env(safe-area-inset-bottom) + 84px)); width: 108px; height: 108px; background: rgba(44, 58, 76, 0.34); border: 2px solid rgba(23, 32, 43, 0.8); pointer-events: auto; touch-action: none; }
#stick-knob { position: absolute; left: 50%; top: 50%; width: 44px; height: 44px; margin: -22px 0 0 -22px; background: rgba(246, 233, 203, 0.78); border: 2px solid rgba(23, 32, 43, 0.85); }
#stick-knob::before, #stick-knob::after { content: ''; position: absolute; background: #1b2430; pointer-events: none; }
#stick-knob::before { left: 50%; top: 7px; bottom: 7px; width: 2px; margin-left: -1px; }
#stick-knob::after { top: 50%; left: 7px; right: 7px; height: 2px; margin-top: -1px; }
#touch-buttons { position: absolute; right: max(14px, env(safe-area-inset-right)); bottom: max(92px, calc(env(safe-area-inset-bottom) + 84px)); display: grid; grid-template-columns: repeat(2, 58px); gap: 8px; pointer-events: auto; }
.t-btn { width: 58px; height: 58px; background: rgba(44, 58, 76, 0.52); border: 2px solid rgba(23, 32, 43, 0.82); color: var(--cream); font-family: 'Silkscreen', monospace; font-size: 10px; letter-spacing: 0.04em; text-shadow: 1px 1px 0 #101720; touch-action: none; border-radius: 0; }
body.touch #hint { display: none; }
body.touch #status-row { bottom: calc(clamp(50px, 7vw, 64px) + 4px); width: min(94vw, 470px); }
body.touch #hotbar { bottom: max(6px, env(safe-area-inset-bottom)); }
body.touch #brand-corner { width: auto; }
body.touch #coords { top: 58px; font-size: 9px; }

body.touch #coords, body.touch #held-name { display: none; }
@media (max-width: 560px) {
  #coords, #held-name { display: none; }
  #toast { font-size: 9px; padding: 3px 9px; }
  .wordmark.corner { font-size: 20px; }
  .mode-grid { grid-template-columns: 1fr; }
  .start-panel { padding: 14px; }
  #start-wordmark { font-size: 60px; }
  .tagline { font-size: 16px; margin-bottom: 10px; }
  .start-controls p { font-size: 9px; }
  #hint { display: none; }
  #status-row { width: 96vw; }
  .pips { gap: 1px; }
  .pips canvas { width: 13px; }
  #top-right { gap: 4px; max-width: 65vw; }
  #top-right .pixel-btn { font-size: 8px; padding: 5px 6px; }
  #stick-base { width: 96px; height: 96px; }
  #stick-knob { width: 40px; height: 40px; margin: -20px 0 0 -20px; }
  #stick-knob::before { top: 6px; bottom: 6px; }
  #stick-knob::after { left: 6px; right: 6px; }
  #touch-buttons { grid-template-columns: repeat(2, 54px); gap: 6px; }
  .t-btn { width: 54px; height: 54px; font-size: 9px; }
}
@media (max-height: 460px) {
  .start-panel { max-height: 96vh; }
  #start-wordmark { font-size: 40px; }
  .tagline { margin: 0 0 8px; font-size: 14px; }
  .mode-grid { gap: 8px; }
  .mode-card { padding: 9px; }
  .mode-title { font-size: 19px; }
  .start-controls { padding: 6px 0; margin-bottom: 8px; }
  .start-controls p { margin: 2px 0; }
  .start-panel { padding: 10px 14px; }
  #stick-base { width: 92px; height: 92px; bottom: 78px; }
  #touch-buttons { grid-template-columns: repeat(2, 50px); gap: 6px; bottom: 78px; }
  .t-btn { width: 50px; height: 50px; font-size: 9px; }
  #status-row { bottom: 60px; }
}
