/* Haus Snake — game-only styles. Every selector is prefixed hs- so it never collides with the site. */
:root {
  --hs-cream: #faf0e6;
  --hs-paper: #fffaf3;
  --hs-flour: #f3e6d6;
  --hs-wheat: #e9c9a3;
  --hs-caramel: #d29e6e;
  --hs-crust: #8b5a2b;
  --hs-brown: #5f4b3b;
  --hs-ink: #2c221b;
  --hs-rye: #3d2f25;
  --hs-line: rgba(95, 75, 59, 0.22);
  --hs-serif: "Fraunces", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --hs-sans: "Instrument Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
  --hs-btn: 60px;
  --hs-gap: 8px;
  --hs-safe-t: env(safe-area-inset-top, 0px);
  --hs-safe-r: env(safe-area-inset-right, 0px);
  --hs-safe-b: env(safe-area-inset-bottom, 0px);
  --hs-safe-l: env(safe-area-inset-left, 0px);
}

*, *::before, *::after { box-sizing: border-box; }

html, .hs-body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--hs-cream);
}

.hs-body {
  color: var(--hs-brown);
  font-family: var(--hs-sans);
  font-size: 16px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  position: fixed;
  inset: 0;
}

button, input { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--hs-crust); outline-offset: 3px; }

.hs-sr {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; margin: -1px; padding: 0; border: 0;
}

/* ---------- Layout ---------- */
.hs-app {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas: "bar" "board" "pad";
  gap: 10px;
  padding: calc(10px + var(--hs-safe-t)) calc(12px + var(--hs-safe-r)) max(20px, calc(var(--hs-safe-b) + 14px)) calc(12px + var(--hs-safe-l));
  max-width: 720px;
  margin: 0 auto;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

/* ---------- Score bar ---------- */
.hs-bar {
  grid-area: bar;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: 4px 6px 4px 14px;
  background: var(--hs-paper);
  border: 1px solid var(--hs-line);
  border-radius: 18px;
}
.hs-brand {
  margin: 0 auto 0 0;
  font-family: var(--hs-serif);
  font-weight: 600;
  font-size: 1.15rem;
  color: var(--hs-ink);
  letter-spacing: -0.01em;
  white-space: nowrap;
}
.hs-stat { display: flex; flex-direction: column; align-items: flex-start; min-width: 3.4rem; line-height: 1.05; }
.hs-stat-label { font-size: .68rem; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; color: var(--hs-crust); }
.hs-stat-value { font-size: 1.3rem; font-weight: 700; color: var(--hs-ink); font-variant-numeric: tabular-nums; }
.hs-bar-actions { display: flex; gap: 6px; margin-left: 4px; }
.hs-icon-btn {
  width: 48px; height: 48px; display: grid; place-items: center;
  border-radius: 14px; border: 1.5px solid rgba(44,34,27,.28);
  background: var(--hs-cream); color: var(--hs-ink);
  touch-action: manipulation;
}
.hs-icon-btn svg { width: 24px; height: 24px; }
.hs-icon-btn:disabled { opacity: .45; cursor: default; }
.hs-icon-btn:not(:disabled):active { background: var(--hs-wheat); }
#hs-mute .hs-ico-sound, #hs-mute[data-on="true"] .hs-ico-muted { display: none; }
#hs-mute[data-on="true"] .hs-ico-sound { display: block; }
#hs-pause .hs-ico-play, #hs-pause[data-paused="true"] .hs-ico-pause { display: none; }
#hs-pause[data-paused="true"] .hs-ico-play { display: block; }

@media (max-width: 379px) {
  .hs-brand { display: none; }
  .hs-bar { justify-content: space-between; }
}

/* ---------- Board ---------- */
.hs-board {
  grid-area: board;
  display: grid;
  place-items: center;
  min-height: 0;
  touch-action: none;
  overscroll-behavior: contain;
}
.hs-frame {
  padding: 6px;
  border-radius: 20px;
  background: var(--hs-rye);
  box-shadow: 0 10px 30px -18px rgba(44,34,27,.7);
  touch-action: none;
}
.hs-canvas {
  display: block;
  border-radius: 14px;
  background: var(--hs-cream);
  touch-action: none;
}

/* ---------- D-pad ---------- */
.hs-pad {
  grid-area: pad;
  justify-self: center;
  display: grid;
  grid-template-columns: repeat(3, var(--hs-btn));
  grid-template-rows: repeat(3, var(--hs-btn));
  grid-template-areas: ". up ." "left . right" ". down .";
  gap: var(--hs-gap);
}
.hs-dir {
  display: grid; place-items: center;
  width: var(--hs-btn); height: var(--hs-btn);
  border-radius: 18px;
  border: 0;
  background: var(--hs-brown);
  color: var(--hs-cream);
  box-shadow: inset 0 -3px 0 rgba(0,0,0,.22);
  touch-action: none;
}
.hs-dir svg { width: 30px; height: 30px; }
.hs-dir.is-pressed, .hs-dir:active { background: var(--hs-ink); box-shadow: none; transform: translateY(1px); }
.hs-dir--up { grid-area: up; }
.hs-dir--down { grid-area: down; }
.hs-dir--left { grid-area: left; }
.hs-dir--right { grid-area: right; }

/* Short portrait screens: one row of arrows leaves the board more room */
@media (orientation: portrait) and (max-height: 700px) {
  .hs-pad {
    grid-template-columns: repeat(4, var(--hs-btn));
    grid-template-rows: var(--hs-btn);
    grid-template-areas: "left up down right";
    gap: 12px;
  }
}

/* Landscape phones: board on the left, score + arrows on the right */
@media (orientation: landscape) and (max-height: 600px) {
  .hs-app {
    max-width: none;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas: "board bar" "board pad";
    column-gap: 16px;
    padding-bottom: calc(10px + var(--hs-safe-b));
  }
  .hs-bar { flex-wrap: wrap; justify-content: space-between; width: calc(3 * var(--hs-btn) + 2 * var(--hs-gap)); padding: 6px 8px 6px 12px; }
  .hs-brand { display: none; }
  .hs-pad { align-self: end; margin-bottom: 4px; }
  :root { --hs-btn: 56px; }
}
@media (orientation: landscape) and (max-height: 360px) {
  :root { --hs-btn: 48px; --hs-gap: 6px; }
  .hs-icon-btn { width: 44px; height: 44px; }
}

/* Phones and tablets: swipe in four directions, no on-screen arrows */
@media (hover: none) and (pointer: coarse) {
  .hs-pad { display: none; }
  .hs-app {
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas: "bar" "board";
    padding-bottom: calc(12px + var(--hs-safe-b));
  }
}
@media (hover: none) and (pointer: coarse) and (orientation: landscape) and (max-height: 600px) {
  .hs-app {
    max-width: none;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas: "bar" "board";
    padding-bottom: calc(8px + var(--hs-safe-b));
  }
  .hs-bar {
    width: auto;
    flex-wrap: nowrap;
    justify-content: flex-start;
  }
}

/* ---------- Overlays ---------- */
.hs-overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: calc(16px + var(--hs-safe-t)) calc(16px + var(--hs-safe-r)) calc(24px + var(--hs-safe-b)) calc(16px + var(--hs-safe-l));
  background: rgba(250, 240, 230, .86);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
}
.hs-card {
  width: min(100%, 420px);
  margin: auto 0;
  padding: 26px 22px 22px;
  background: var(--hs-paper);
  border: 1px solid var(--hs-line);
  border-radius: 26px;
  box-shadow: 0 24px 60px -30px rgba(44,34,27,.55);
  text-align: center;
}
@media (prefers-reduced-motion: no-preference) {
  .hs-overlay:not([hidden]) .hs-card { animation: hs-rise .28s cubic-bezier(.2,.7,.2,1); }
  @keyframes hs-rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
}
.hs-kicker { margin: 0 0 .25rem; font-size: .74rem; font-weight: 600; letter-spacing: .18em; text-transform: uppercase; color: var(--hs-crust); }
.hs-title { margin: 0; font-family: var(--hs-serif); font-weight: 600; font-size: clamp(2.1rem, 9vw, 2.8rem); line-height: 1.05; letter-spacing: -0.02em; color: var(--hs-ink); }
h2.hs-title { font-size: clamp(1.8rem, 7.5vw, 2.3rem); }
.hs-sub { margin: .4rem 0 1.1rem; font-family: var(--hs-serif); font-style: italic; font-size: 1.1rem; color: var(--hs-brown); }
.hs-muted { color: var(--hs-brown); font-weight: 400; }
.hs-legend { list-style: none; margin: 0 0 1rem; padding: 0; display: grid; gap: .55rem; text-align: left; }
.hs-legend li { display: flex; align-items: center; gap: .75rem; padding: .5rem .75rem; background: var(--hs-cream); border-radius: 14px; }
.hs-legend strong { color: var(--hs-ink); }
.hs-legend-icon { width: 40px; height: 40px; flex: none; }
.hs-help { margin: 0 0 1.25rem; font-size: .95rem; }
@media (hover: none) and (pointer: coarse) { .hs-help-keys { display: none; } }

.hs-actions { display: grid; gap: 10px; }
.hs-btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 56px; padding: .8rem 1.4rem;
  border-radius: 999px;
  border: 1.5px solid var(--hs-brown);
  background: var(--hs-brown); color: var(--hs-cream);
  font-weight: 650; font-size: 1.12rem; letter-spacing: .01em;
  touch-action: manipulation;
}
.hs-btn:active { background: var(--hs-ink); border-color: var(--hs-ink); }
@media (hover: hover) { .hs-btn:hover { background: var(--hs-ink); border-color: var(--hs-ink); } .hs-btn--ghost:hover { color: var(--hs-cream); } }
.hs-btn--ghost { background: transparent; color: var(--hs-ink); border-color: rgba(44,34,27,.4); }
.hs-btn--ghost:active { color: var(--hs-cream); }

.hs-final { margin: .5rem 0 .25rem; display: flex; flex-direction: column; align-items: center; }
.hs-final-label { font-size: .74rem; font-weight: 600; letter-spacing: .18em; text-transform: uppercase; color: var(--hs-crust); }
.hs-final-score { font-family: var(--hs-serif); font-weight: 600; font-size: 3.2rem; line-height: 1; color: var(--hs-ink); font-variant-numeric: tabular-nums; }
.hs-badge { display: inline-block; margin: .4rem 0 0; padding: .3rem .8rem; border-radius: 999px; background: var(--hs-wheat); color: var(--hs-ink); font-weight: 650; font-size: .92rem; }

.hs-form { margin: 1.1rem 0 .4rem; text-align: left; user-select: text; -webkit-user-select: text; }
.hs-label { display: block; margin-bottom: .45rem; font-weight: 600; color: var(--hs-ink); }
.hs-form-row { display: flex; gap: 8px; }
.hs-input {
  flex: 1; min-width: 0; min-height: 56px; padding: .7rem 1rem;
  font-size: 1.15rem; /* >=16px so iOS does not zoom on focus */
  color: var(--hs-ink); background: var(--hs-cream);
  border: 1.5px solid rgba(44,34,27,.4); border-radius: 16px;
  user-select: text; -webkit-user-select: text;
}
.hs-input::placeholder { color: #7a6656; }
.hs-input:focus-visible { outline-offset: 1px; }
.hs-btn--save { flex: none; min-width: 92px; padding-inline: 1.1rem; }
.hs-saved { margin: .9rem 0 .2rem; font-weight: 600; color: var(--hs-crust); }
#hs-over .hs-actions { margin-top: 1.1rem; }

.hs-scores { list-style: none; margin: 0 0 1.2rem; padding: 0; text-align: left; counter-reset: none; }
.hs-scores li {
  display: grid; grid-template-columns: 2.2rem minmax(0, 1fr) auto; align-items: center; gap: .5rem;
  min-height: 46px; padding: .4rem .8rem; border-radius: 12px;
  font-variant-numeric: tabular-nums;
}
.hs-scores li:nth-child(odd) { background: var(--hs-cream); }
.hs-scores li.is-new { background: var(--hs-wheat); }
.hs-rank { font-weight: 700; color: var(--hs-crust); }
.hs-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--hs-ink); font-weight: 600; }
.hs-score { font-weight: 700; color: var(--hs-ink); }
.hs-empty { margin: 0 0 1.2rem; padding: 1rem; border-radius: 14px; background: var(--hs-cream); }

@media (forced-colors: active) {
  .hs-dir, .hs-btn, .hs-icon-btn { border: 2px solid ButtonText; }
}
