/* BlockWorld: colors, panels, slots, start card and touch buttons follow the student's prototype. */
:root {
  color-scheme: dark;
  --accent: #68b94c;
  --accent-ink: #10200d;
  --bg: #182536;
  --surface: #101923;
  --surface-2: #18202b;
  --ink: #ffffff;
  --ink-2: #d4e0ed;
  --line: #ffffff38;
  --panel: #101923d9;
  --slot: #18202bdc;
  --slot-line: #718092;
  --grass: #65ad45;
  --grass-dark: #39752a;
  --sky-blue: #326b9c;
  --buff: #7cf28a;
  --nerf: #ff8f7a;
  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --font-display: var(--font);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: #fff; font-family: var(--font); overflow: hidden;
  overscroll-behavior: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
button { font: inherit; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }

#game {
  position: fixed; inset: 0; display: block; width: 100vw; height: 100vh; height: 100dvh;
  image-rendering: pixelated; cursor: crosshair; touch-action: none;
}

/* ---------- HUD ---------- */
#hud[hidden] { display: none; }
#top {
  position: fixed; top: calc(12px + var(--safe-top)); left: calc(12px + var(--safe-left)); right: calc(12px + var(--safe-right));
  display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; pointer-events: none; z-index: 5;
}
.panel {
  background: var(--panel); border: 2px solid var(--line); border-radius: 8px; padding: 9px 12px;
  font-size: 13px; line-height: 1.45;
}
#vitals { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
#hearts { display: flex; gap: 2px; }
.heart { width: 18px; height: 16px; position: relative; background: var(--heart-empty) center / 100% 100% no-repeat; image-rendering: pixelated; }
.heart::before {
  content: ""; position: absolute; inset: 0; image-rendering: pixelated;
  background: var(--heart-full) center / 100% 100% no-repeat; clip-path: inset(0 0 0 0);
}
.heart.half::before { clip-path: inset(0 50% 0 0); }
.heart.empty::before { display: none; }
.heart.poisoned::before { filter: hue-rotate(95deg) saturate(.8); }
#vitals.hurt { animation: hurt .25s ease; }
@keyframes hurt { 0%, 100% { transform: none; } 30% { transform: translateX(-3px); } 60% { transform: translateX(3px); } }

#effects { display: flex; flex-wrap: wrap; gap: 4px; max-width: 46vw; }
#effects:empty { display: none; }
.fx {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 7px 2px 3px; border-radius: 5px;
  background: #0008; border: 2px solid var(--c); font-size: 11px; font-weight: 700; white-space: nowrap;
}
.fx img { width: 16px; height: 16px; image-rendering: pixelated; }
.fx .tag { font-size: 9px; letter-spacing: .5px; color: var(--buff); }
.fx.nerf .tag { color: var(--nerf); }
.fx.ending { animation: blink .5s steps(2) infinite; }
@keyframes blink { 50% { opacity: .45; } }

.hud-right { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
#clock { display: flex; align-items: center; gap: 9px; }
#sky-icon { width: 26px; height: 26px; border-radius: 4px; display: block; image-rendering: pixelated; }
#sky-icon.sun { background: #ffd45a; box-shadow: inset -4px -4px #f0a92c, 0 0 0 3px #ffd45a55; }
#sky-icon.moon { background: #e9ecf5; box-shadow: inset -6px -2px #b6bdd0, 0 0 0 3px #e9ecf533; }
#sky-icon.dusk { background: #ff9a52; box-shadow: inset -4px -4px #d2602a, 0 0 0 3px #ff9a5255; }
#time-label { font-variant-numeric: tabular-nums; }
#coords { color: #b9c7d6; font-size: 12px; }
.hud-buttons { display: flex; gap: 6px; pointer-events: auto; }
.hud-btn {
  width: 44px; height: 44px; border-radius: 8px; border: 2px solid var(--line); background: var(--panel); color: #fff;
  font-size: 19px; font-weight: 900; display: grid; place-items: center; cursor: pointer; padding: 0;
}
.hud-btn:active { background: #344354; }

#game-toast {
  position: fixed; top: calc(76px + var(--safe-top)); left: 50%; transform: translateX(-50%); z-index: 6;
  background: #101923dd; padding: 8px 14px; border-radius: 6px; opacity: 0; transition: opacity .2s; pointer-events: none;
  font-size: 14px; font-weight: 600; white-space: nowrap; max-width: 92vw; overflow: hidden; text-overflow: ellipsis;
}
#game-toast.show { opacity: 1; }

#help {
  position: fixed; bottom: calc(86px + var(--safe-bottom)); left: 50%; transform: translateX(-50%); text-align: center;
  background: #101923b8; padding: 7px 12px; border-radius: 7px; font-size: 12px; white-space: nowrap; pointer-events: none;
}

#hotbar {
  position: fixed; bottom: calc(18px + var(--safe-bottom)); left: 50%; transform: translateX(-50%); display: flex; gap: 5px; z-index: 5;
}
.slot {
  width: 54px; height: 54px; background: var(--slot); border: 3px solid var(--slot-line); border-radius: 5px;
  display: grid; place-items: center; position: relative; padding: 0; color: #fff; cursor: pointer;
  transition: transform .08s;
}
.slot img { width: 30px; height: 30px; image-rendering: pixelated; pointer-events: none; }
.slot.active { border-color: #fff; transform: translateY(-5px); background: #344354; }
.slot.zero img { opacity: .3; filter: grayscale(1); }
.slot .num { position: absolute; top: 0; left: 4px; font-size: 10px; color: #ddd; }
.slot .count { position: absolute; bottom: 0; right: 4px; font-size: 12px; font-weight: 700; text-shadow: 1px 1px #000; }

#mobile-controls {
  display: none; position: fixed; left: calc(12px + var(--safe-left)); right: calc(12px + var(--safe-right));
  bottom: calc(88px + var(--safe-bottom)); justify-content: space-between; align-items: end; pointer-events: none; z-index: 5;
}
.control-group { display: flex; gap: 9px; pointer-events: auto; }
.touch-btn {
  width: 58px; height: 58px; border: 2px solid #ffffff9c; border-radius: 14px; background: #172536c9; color: #fff;
  font-size: 23px; font-weight: 700; touch-action: none; -webkit-user-select: none; user-select: none; padding: 0;
}
.touch-btn:active, .touch-btn.held { background: #54718f; }
#actions { flex-direction: column; }
#actions .touch-btn { width: 66px; height: 50px; font-size: 12px; letter-spacing: .5px; }
#actions .touch-btn.mode[aria-pressed="true"] { background: #3d6b2f; border-color: #a9f08a; }

@media (max-width: 700px), (pointer: coarse) {
  #help { display: none; }
  #mobile-controls { display: flex; }
}
@media (max-width: 700px) {
  .slot { width: 38px; height: 38px; border-width: 2px; }
  .slot img { width: 22px; height: 22px; }
  .slot .num { font-size: 8px; left: 2px; }
  .slot .count { font-size: 10px; right: 2px; }
  #hotbar { bottom: calc(10px + var(--safe-bottom)); gap: 3px; }
  #mobile-controls { bottom: calc(66px + var(--safe-bottom)); }
  #top { top: calc(7px + var(--safe-top)); left: calc(7px + var(--safe-left)); right: calc(7px + var(--safe-right)); }
  .panel { font-size: 11px; padding: 6px 8px; }
  .heart { width: 13px; height: 12px; }
  .touch-btn { width: 52px; height: 52px; }
  #actions .touch-btn { width: 60px; height: 46px; }
  .hud-btn { width: 40px; height: 40px; font-size: 16px; }
  #game-toast { top: calc(110px + var(--safe-top)); }
}

/* ---------- Start screen ---------- */
#start-screen {
  position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; align-content: center; gap: 12px;
  background: linear-gradient(#10243bc9, #101923ef), linear-gradient(135deg, var(--grass), var(--sky-blue));
  padding: calc(20px + var(--safe-top)) 20px calc(20px + var(--safe-bottom)); overflow: auto;
}
#start-screen[hidden] { display: none; }
#start-screen .install-hint { width: min(440px, 94vw); background: #101923ed; color: #fff; border: 2px solid var(--line); }
#start-card {
  width: min(440px, 94vw); padding: 28px 22px; text-align: center; background: #101923ed;
  border: 3px solid #ffffff55; border-radius: 16px; box-shadow: 0 18px 60px #0008;
}
#start-card h1 { font-size: clamp(34px, 8vw, 54px); margin: 0 0 8px; letter-spacing: 2px; text-shadow: 4px 4px #36552d; font-weight: 900; }
#start-card p { color: var(--ink-2); line-height: 1.5; margin: 8px 0 16px; }
.features { list-style: none; padding: 0; margin: 0 auto 20px; text-align: left; display: grid; gap: 7px; max-width: 330px; font-size: 14px; color: #e6eef6; }
.features li { display: flex; align-items: center; gap: 9px; }
.features .dot { width: 12px; height: 12px; background: var(--c); flex: none; box-shadow: inset -3px -3px #0003; }
#start-actions { display: grid; gap: 12px; justify-items: center; }
#start-actions p { margin: -4px 0 0; font-size: 13px; }
#new-warning { color: #ffd45a !important; }
.start-btn {
  border: 0; border-radius: 9px; background: var(--accent); color: var(--accent-ink); font-size: 20px; font-weight: 900;
  padding: 14px 34px; box-shadow: 0 5px var(--grass-dark); cursor: pointer; min-width: 240px;
}
.start-btn:active { transform: translateY(3px); box-shadow: 0 2px var(--grass-dark); }
.start-btn.secondary { background: #d4e0ed; box-shadow: 0 5px #7d8fa3; }
.start-btn:focus-visible, .game-btn:focus-visible, .slot:focus-visible, .hud-btn:focus-visible { outline: 3px solid #ffd45a; outline-offset: 2px; }
#start-card .fine { font-size: 12px; margin: 18px 0 0; }

/* ---------- Sheets ---------- */
dialog.game-sheet { background: #101923f2; color: #fff; border: 3px solid #ffffff55; max-width: 560px; }
dialog.game-sheet::backdrop { background: #050a12a6; }
.game-sheet h2 { margin: 0 0 6px; font-size: 24px; letter-spacing: 1px; font-weight: 900; text-shadow: 3px 3px #36552d; }
.game-sheet h3 { margin: 18px 0 8px; font-size: 15px; text-transform: uppercase; letter-spacing: 1px; color: #b9c7d6; }
.game-sheet .muted { color: var(--ink-2); font-size: 14px; margin: 0 0 12px; }
.buff { color: var(--buff); } .nerf { color: var(--nerf); }
.game-btn {
  min-height: 44px; padding: 0 18px; border-radius: 9px; border: 2px solid #ffffff55; background: #24364c; color: #fff;
  font-weight: 800; cursor: pointer;
}
.game-btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; box-shadow: 0 4px var(--grass-dark); }
.game-btn:disabled { opacity: .45; cursor: not-allowed; }
.menu { display: grid; gap: 10px; margin-top: 14px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; margin: 10px 0; }
.stats div { background: #ffffff10; border-radius: 8px; padding: 8px 10px; font-size: 12px; color: #b9c7d6; }
.stats b { display: block; font-size: 20px; color: #fff; }
.item-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 8px; }
.item {
  display: grid; justify-items: center; gap: 2px; padding: 8px 4px; border-radius: 8px; border: 2px solid #ffffff22;
  background: var(--slot); color: #fff; cursor: pointer; min-height: 76px; font-size: 11px; line-height: 1.2; position: relative;
}
.item img { width: 30px; height: 30px; image-rendering: pixelated; }
.item .count { position: absolute; top: 3px; right: 6px; font-weight: 800; font-size: 12px; }
.item.in-bar { border-color: #ffffff77; }
.recipe { display: flex; align-items: center; gap: 12px; padding: 10px; border-radius: 10px; background: #ffffff0c; margin-bottom: 8px; }
.recipe img { width: 34px; height: 34px; image-rendering: pixelated; flex: none; }
.recipe .info { flex: 1; min-width: 0; }
.recipe .name { font-weight: 800; }
.recipe .kind { font-size: 10px; font-weight: 800; letter-spacing: 1px; margin-left: 6px; }
.recipe .needs { font-size: 12px; color: #b9c7d6; margin-top: 2px; }
.recipe .needs .short { color: var(--nerf); }
.recipe .owned { font-size: 12px; color: #fff; opacity: .8; }
.howto { padding-left: 18px; line-height: 1.55; color: #e6eef6; }
.howto li { margin-bottom: 6px; }

@media (prefers-reduced-motion: reduce) {
  .slot, #game-toast { transition: none; }
  #vitals.hurt, .fx.ending { animation: none; }
}
