/* Shrew Train · Nocturnal forest */

@font-face { font-family: "Playfair Display"; font-weight: 600; font-style: normal; font-display: swap; src: url("./fonts/playfair-display-latin-600-normal.woff2") format("woff2"); }
@font-face { font-family: "Playfair Display"; font-weight: 600; font-style: italic; font-display: swap; src: url("./fonts/playfair-display-latin-600-italic.woff2") format("woff2"); }
@font-face { font-family: "Playfair Display"; font-weight: 800; font-style: normal; font-display: swap; src: url("./fonts/playfair-display-latin-800-normal.woff2") format("woff2"); }
@font-face { font-family: "EB Garamond"; font-weight: 500; font-style: normal; font-display: swap; src: url("./fonts/eb-garamond-latin-500-normal.woff2") format("woff2"); }
@font-face { font-family: "EB Garamond"; font-weight: 500; font-style: italic; font-display: swap; src: url("./fonts/eb-garamond-latin-500-italic.woff2") format("woff2"); }
@font-face { font-family: "EB Garamond"; font-weight: 600; font-style: normal; font-display: swap; src: url("./fonts/eb-garamond-latin-600-normal.woff2") format("woff2"); }

:root {
  --font-display: "Playfair Display", Georgia, serif;
  --font-body: "EB Garamond", Georgia, serif;
  --bg: #111b20;
  --surface: rgba(22, 29, 25, 0.82);
  --surface-strong: #202923;
  --border: rgba(244, 220, 179, 0.18);
  --border-strong: rgba(244, 220, 179, 0.36);
  --text: #f4e8d3;
  --muted: #c7bca6;
  --accent: #d8c392;
  --accent-2: #eed096;
  --accent-ink: #241d17;
  --danger: #d99a95;
  --shadow: 0 10px 28px rgba(9, 11, 10, 0.28);
}

html[data-theme="glade"] {
  --bg: #1b1928;
  --surface: rgba(30, 27, 39, 0.84);
  --surface-strong: #292636;
  --accent: #c7c5b2;
}

html[data-theme="hollow"] {
  --bg: #231b23;
  --surface: rgba(40, 29, 27, 0.84);
  --surface-strong: #332721;
  --accent: #dbc09d;
}

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

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 500 17px var(--font-body);
  -webkit-font-smoothing: antialiased;
  touch-action: none;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* Pin the page so iOS rubber-banding can never drag the forest around. */
body {
  position: fixed;
  inset: 0;
}

button {
  font: inherit;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

input[type="text"] {
  user-select: text;
  -webkit-user-select: text;
}

/* Focus ring: shown for keyboard focus, and for gamepad-driven focus (data-nav="keys"). */
:focus {
  outline: none;
}

:focus-visible,
html[data-nav="keys"] :focus {
  outline: 2px solid var(--accent-2);
  outline-offset: 2px;
}

.hidden {
  display: none !important;
}

.ico {
  width: 18px;
  height: 18px;
  display: block;
  stroke-width: 1.55;
  flex-shrink: 0;
}

.noscript {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 24px;
  text-align: center;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
}

/* Full-bleed shell */
.app-shell {
  position: relative;
  width: 100%;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

#game-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 0;
  cursor: pointer;
  touch-action: none;
}

/* Top HUD */
.top-bar {
  position: relative;
  z-index: 10;
  padding: max(13px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) 0 max(20px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  pointer-events: none;
}

.top-row {
  width: min(100%, 1100px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  white-space: nowrap;
}

.brand-mark .ico {
  width: 36px;
  height: 36px;
}

.brand-title {
  font: 600 italic 25px/1.2 var(--font-display);
}

.brand-title b {
  font-weight: inherit;
}

.action-cluster,
.scoreboard,
.dock-controls {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 7px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  pointer-events: auto;
}

.action-cluster {
  display: flex;
  align-items: center;
  padding: 0 3px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 38px;
  min-width: 38px;
  padding: 0 8px;
  border: 0;
  border-radius: 5px;
  background: none;
  color: var(--text);
  cursor: pointer;
}

.icon-btn-accent {
  color: var(--accent-2);
}

@media (hover: hover) {
  .icon-btn:hover,
  .dock-btn:hover:not(:disabled) {
    background-color: rgba(242, 222, 183, 0.12);
  }
  .dock-btn-primary:hover:not(:disabled) {
    background-color: var(--accent-2);
  }
}

.dock-btn.confirming {
  background-color: rgba(240, 152, 92, 0.24);
  color: var(--accent-2);
}

.scoreboard {
  width: min(100%, 468px);
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr)) minmax(0, 1.6fr);
  padding: 7px 4px;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  padding: 0 3px;
  min-width: 0;
  border-right: 1px solid var(--border);
}

.stat:last-child {
  border-right: 0;
}

.stat-k {
  font-size: 10px;
  line-height: 1.1;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}

.stat-v {
  font: 600 19px/1.15 var(--font-display);
  font-variant-numeric: lining-nums tabular-nums;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat-forest .stat-v {
  font-size: 15px;
}

.stat-shrews .stat-v {
  color: var(--accent-2);
}

.stat-v.bump {
  animation: stat-bump 0.25s ease-out;
}

@keyframes stat-bump {
  0% { color: var(--accent-2); opacity: 0.65; }
  100% { opacity: 1; }
}

/* Free stage area */
.stage-wrap {
  position: relative;
  flex: 1;
  z-index: 5;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  min-width: 0;
  min-height: 0;
  padding: 8px 12px;
}

.stage-toast {
  position: absolute;
  top: 6px;
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  padding: 8px 16px;
  border-radius: 6px;
  background: var(--surface-strong);
  border: 1px solid var(--border-strong);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
  z-index: 2;
  width: max-content;
  max-width: calc(100% - 24px);
  text-align: center;
}

.stage-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.oops-banner {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px 10px 18px;
  border-radius: 6px;
  background: var(--surface-strong);
  border: 1px solid var(--danger);
  box-shadow: var(--shadow);
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text);
  animation: oops-in 0.28s cubic-bezier(0.22, 1, 0.36, 1) 0.18s both;
}

.oops-banner.nudge {
  animation: oops-nudge 0.4s ease;
}

@keyframes oops-in {
  from { opacity: 0; transform: translateY(8px) scale(0.96); }
  to { opacity: 1; transform: none; }
}

@keyframes oops-nudge {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-7px); }
  45% { transform: translateX(6px); }
  70% { transform: translateX(-3px); }
}

.oops-actions {
  display: flex;
  gap: 8px;
}

/* Bottom dock */
.bottom-dock {
  position: relative;
  z-index: 10;
  display: flex;
  justify-content: center;
  padding: 4px max(12px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  pointer-events: none;
}

.dock-controls {
  display: flex;
  align-items: stretch;
}

.dock-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 40px;
  padding: 0 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: 600 16px/1 var(--font-body);
  cursor: pointer;
}

.dock-controls .dock-btn {
  min-width: 94px;
  border: 0;
  background: none;
}

.dock-controls .dock-btn + .dock-btn {
  border-left: 1px solid var(--border);
  border-radius: 0;
}

.dock-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.dock-btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
}

.dock-btn-xl {
  min-height: 44px;
  padding: 0 20px;
}

/* Scrim, Drawer, Modals */
.scrim {
  position: fixed;
  inset: 0;
  background: rgba(3, 8, 7, 0.62);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 30;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.scrim.show {
  opacity: 1;
  pointer-events: auto;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(390px, 92vw);
  background: var(--surface-strong);
  border-left: 1px solid var(--border);
  z-index: 40;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
  padding-right: env(safe-area-inset-right);
  animation: drawer-in 0.24s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes drawer-in {
  from { transform: translateX(28px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: max(18px, env(safe-area-inset-top)) 18px 14px;
  border-bottom: 1px solid var(--border);
}

.drawer-header h2 {
  font-family: var(--font-display);
  font-weight: 600;
  margin: 0;
  font-size: 18px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.drawer-body {
  padding: 16px 18px max(24px, env(safe-area-inset-bottom));
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.close-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  flex-shrink: 0;
}

.close-btn:hover {
  border-color: var(--border-strong);
}

.preset-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.preset-card {
  text-align: left;
  padding: 12px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.preset-card:hover {
  border-color: var(--border-strong);
}

.preset-card.active {
  border-color: var(--accent);
  background: rgba(237, 207, 150, 0.09);
}

.preset-title {
  font-size: 14.5px;
  font-weight: 800;
  color: var(--text);
}

.preset-sub {
  font-size: 11.5px;
  color: var(--muted);
  line-height: 1.35;
}

.preset-meta {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent-2);
  margin-top: 2px;
}

.custom-section h3 {
  margin: 0 0 10px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.slider-row {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 10px;
}

.slider-row label {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text);
}

.slider-row input[type="range"] {
  width: 100%;
  height: 28px;
  margin: 0;
  accent-color: var(--accent);
  touch-action: pan-y;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  margin: 8px 0 14px;
  cursor: pointer;
}

.toggle-row input {
  accent-color: var(--accent);
  width: 20px;
  height: 20px;
  margin: 0;
}

.seed-row {
  display: flex;
  gap: 8px;
}

.seed-row input {
  flex: 1;
  min-width: 0;
  height: 40px;
  padding: 0 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  /* 16px keeps iOS from zooming the page when the field is focused */
  font-size: 16px;
}

.seed-row input:focus {
  border-color: var(--accent);
}

/* Modals */
.modal {
  position: fixed;
  inset: 0;
  z-index: 45;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(14px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  /* taps beside the card fall through to the scrim, which closes the dialog */
  pointer-events: none;
}

.modal-card {
  position: relative;
  width: min(420px, 100%);
  max-height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  padding: 26px 24px 22px;
  border-radius: 10px;
  background: var(--surface-strong);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow);
  text-align: center;
  pointer-events: auto;
  animation: modal-in 0.26s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes modal-in {
  from { transform: translateY(14px) scale(0.96); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.modal-card-wide {
  width: min(500px, 100%);
  text-align: left;
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
}

.modal-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 11px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  font-size: 11.5px;
  font-weight: 700;
  color: var(--accent-2);
  margin-bottom: 10px;
}

.modal-card h2 {
  font-family: var(--font-display);
  font-weight: 600;
  margin: 0 0 6px;
  font-size: 24px;
  letter-spacing: -0.02em;
}

.modal-sub {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 14px;
}

.modal-copy {
  margin: 0 0 16px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
}

.daily-best {
  margin: 0 0 16px;
  padding: 10px 14px;
  border-radius: 12px;
  background: rgba(237, 207, 150, 0.09);
  border: 1px solid var(--border-strong);
  font-size: 13.5px;
  font-weight: 700;
  color: var(--accent);
}

.win-crest {
  width: 58px;
  height: 58px;
  margin: 0 auto 12px;
  border-radius: 50%;
  background: rgba(255, 216, 107, 0.14);
  border: 1px solid var(--accent-2);
  color: var(--accent-2);
  display: flex;
  align-items: center;
  justify-content: center;
}

.win-crest .ico {
  width: 28px;
  height: 28px;
}

.win-badges {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 18px;
}

.win-badge {
  padding: 4px 11px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--border);
  color: var(--text);
}

.win-badge.gold {
  border-color: var(--accent-2);
  color: var(--accent-2);
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.help-list {
  margin: 12px 0 20px;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 9px;
  font-size: 13.5px;
  line-height: 1.48;
  color: var(--text);
}

.help-list kbd {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 5px;
  border: 1px solid var(--border-strong);
  background: rgba(255, 255, 255, 0.08);
  font-size: 11.5px;
  font-family: inherit;
  font-weight: 700;
}

@media (max-width: 720px) {
  .top-bar {
    gap: 7px;
    padding: max(8px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) 0 max(10px, env(safe-area-inset-left));
  }
  .brand-title { font-size: 19px; }
  .brand-mark .ico { width: 30px; height: 30px; }
  .btn-lbl { display: none; }
  .icon-btn { width: 36px; min-width: 0; padding: 0; }
  .scoreboard { padding-block: 5px; }
  .stat-v { font-size: 16px; }
  .stat-forest .stat-v { font-size: 13px; }
  .dock-controls .dock-btn { min-height: 44px; }
  .modal-card { padding: 20px 16px; }
}

@media (max-width: 430px) {
  .brand-title { display: none; }
  .icon-btn { width: clamp(34px, 10vw, 44px); height: 42px; }
}

@media (max-width: 350px) {
  .stat-k { font-size: 9px; letter-spacing: 0.04em; }
  .oops-banner { flex-wrap: wrap; justify-content: center; }
}

@media (orientation: landscape) and (max-height: 520px) {
  .top-bar {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding-top: max(4px, env(safe-area-inset-top));
  }
  .top-row { display: contents; }
  .brand { order: 0; }
  .brand-title, .btn-lbl { display: none; }
  .scoreboard { order: 1; width: auto; flex: 1; max-width: 410px; margin: 0 auto; padding-block: 4px; }
  .stat-k { font-size: 9px; letter-spacing: 0.04em; }
  .stat-v { font-size: 15px; }
  .stat-forest .stat-v { font-size: 12px; }
  .action-cluster { order: 2; }
  .icon-btn { width: clamp(32px, 5vw, 42px); height: 38px; padding: 0; }
  .bottom-dock { padding-bottom: max(5px, env(safe-area-inset-bottom)); }
  .dock-controls .dock-btn { min-height: 38px; }
  .modal-card { padding-block: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-delay: 0ms !important;
    transition-duration: 0.01ms !important;
  }
}

.credit-links { margin: 14px 0 0; padding-top: 10px; border-top: 1px solid var(--border); font-size: 13px; color: var(--muted); text-align: center; }
.credit-links a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.credit-links a:hover { color: var(--text); }

.dock-hint {
  margin-top: 6px;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text);
  text-align: center;
  opacity: 0.92;
  transition: opacity 420ms ease;
  pointer-events: auto;
  text-shadow: 0 1px 3px rgb(0 0 0 / 35%);
}
.dock-hint.is-dimmed { opacity: 0.42; }
.dock-hint:hover { opacity: 0.96; }
.dock-hint kbd { font: inherit; }
.dock-hint .hint-sep { margin-inline: 4px; opacity: 0.7; }
.dock-hint .hint-gp { display: none; }
body.gamepad-active .dock-hint .hint-kb { display: none; }
body.gamepad-active .dock-hint .hint-gp { display: inline; }
.dock-hint kbd.gp-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  vertical-align: -1px;
  font: 800 10.5px/1 system-ui, -apple-system, sans-serif;
  letter-spacing: 0.02em;
  text-shadow: none;
  box-shadow: 0 1px 2px rgb(0 0 0 / 40%), inset 0 1px 0 rgb(255 255 255 / 28%);
}
.dock-hint kbd.gp-a, .dock-hint kbd.gp-b, .dock-hint kbd.gp-x, .dock-hint kbd.gp-y {
  min-width: 18px;
  height: 18px;
  padding-inline: 3px;
  border-radius: 999px;
}
.dock-hint kbd.gp-a { background: #107c10; color: #fff; border: 1px solid #35b935; }
.dock-hint kbd.gp-b { background: #d13438; color: #fff; border: 1px solid #f06568; }
.dock-hint kbd.gp-x { background: #0078d4; color: #fff; border: 1px solid #4ca8f5; }
.dock-hint kbd.gp-y { background: #eab308; color: #18181b; border: 1px solid #fde047; }
.dock-hint kbd.gp-pill {
  height: 18px;
  padding: 0 6px;
  border-radius: 5px;
  background: #23272f;
  color: #f4f4f5;
  border: 1px solid rgb(255 255 255 / 24%);
}
@media (max-width: 680px), (pointer: coarse), (orientation: landscape) and (max-height: 520px) {
  .dock-hint { display: none; }
}
