:root {
  color-scheme: light;
  --bg-top: #8be3b0;
  --bg-mid: #287b48;
  --ink: #173624;
  --muted: rgba(23, 54, 36, 0.74);
  --panel: rgba(255, 248, 224, 0.92);
  --panel-strong: rgba(255, 252, 235, 0.97);
  --line: rgba(43, 94, 52, 0.18);
  --accent: #ffd45b;
  --accent-deep: #9d6d20;
  --shadow: rgba(10, 39, 21, 0.18);
}

@font-face {
  font-family: "Sinzano";
  src:
    url("/fonts/sinzano-regular.woff2") format("woff2"),
    url("/fonts/sinzano-regular.woff") format("woff");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at 84% 8%, rgba(255, 224, 104, 0.42), transparent 18rem),
    radial-gradient(circle at 10% 16%, rgba(173, 255, 147, 0.28), transparent 14rem),
    linear-gradient(180deg, var(--bg-top), var(--bg-mid));
  color: var(--ink);
  font-family: "Avenir Next", Avenir, "Trebuchet MS", "Segoe UI", sans-serif;
}

body.is-embedded {
  height: 100vh;
  min-height: auto;
  overflow: hidden;
  background: transparent;
}

button {
  font: inherit;
}

.dash-shell {
  width: min(1280px, calc(100vw - 1.5rem));
  margin: 0 auto;
  padding: 1rem 0 1.25rem;
}

body.is-embedded .dash-shell {
  width: 100vw;
  padding: 0;
}

.dash-header,
.dash-layout,
.stat-card,
.hud-pill,
.canvas-shell,
.touch-controls {
  border-radius: 28px;
}

.dash-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.95rem 1.05rem;
  margin-bottom: 0.85rem;
  background:
    linear-gradient(180deg, rgba(255, 253, 237, 0.96), rgba(233, 245, 205, 0.9));
  border: 2px solid rgba(54, 102, 54, 0.18);
  box-shadow: 0 18px 36px var(--shadow), inset 0 -6px 0 rgba(74, 123, 48, 0.08);
}

body.is-embedded .dash-header {
  display: none;
}

.title-block h1 {
  margin: 0;
  font-size: clamp(2rem, 3vw, 2.8rem);
  line-height: 0.95;
}

.subtitle {
  margin: 0.45rem 0 0;
  color: var(--muted);
  font-size: 1.02rem;
  font-weight: 700;
}

.small-kicker {
  margin: 0 0 0.45rem;
  color: #d05d4d;
  font-size: 0.75rem;
  font-weight: 900;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  justify-content: flex-end;
}

.toolbar-btn,
.touch-btn,
.big-btn,
.ghost-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  min-height: 52px;
  border: 0;
  border-radius: 999px;
  padding: 0.9rem 1.15rem;
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease, background 120ms ease;
}

.toolbar-icon {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 1.25em;
  height: 1.25em;
  font-size: 1.05rem;
  line-height: 1;
}

.toolbar-btn[aria-pressed="false"] .toolbar-icon::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 1.72em;
  height: 0.24em;
  border-radius: 999px;
  background: #d91f26;
  box-shadow:
    0 0 0 1px rgba(255, 248, 224, 0.9),
    0 1px 2px rgba(63, 20, 14, 0.34);
  transform: translate(-50%, -50%) rotate(45deg);
  transform-origin: center;
}

.toolbar-btn,
.ghost-btn {
  background: rgba(255, 252, 246, 0.94);
  color: var(--ink);
  box-shadow: 0 10px 20px rgba(18, 44, 28, 0.08);
}

.big-btn,
.touch-btn {
  background: linear-gradient(180deg, #ffd96f, #f1a63c);
  color: #3f2606;
  font-weight: 900;
  box-shadow: 0 14px 24px rgba(155, 93, 21, 0.22);
}

.toolbar-btn:hover,
.touch-btn:hover,
.big-btn:hover,
.ghost-btn:hover {
  transform: translateY(-1px);
}

.dash-layout {
  display: grid;
  grid-template-columns: minmax(220px, 280px) minmax(0, 1fr);
  gap: 0.9rem;
}

body.is-embedded .dash-layout {
  grid-template-columns: 1fr;
}

.dash-sidebar {
  display: grid;
  gap: 0.8rem;
}

body.is-embedded .dash-sidebar {
  display: none;
}

.stat-card {
  padding: 1rem;
  background: var(--panel-strong);
  border: 1px solid var(--line);
  box-shadow: 0 18px 36px rgba(18, 44, 28, 0.1);
}

.score-value {
  margin: 0;
  font-size: clamp(2rem, 5vw, 2.7rem);
  font-weight: 900;
  line-height: 1;
}

.meter {
  overflow: hidden;
  height: 20px;
  border-radius: 999px;
  background: rgba(23, 54, 36, 0.1);
}

.meter span {
  display: block;
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #ffc84b, #ff9640);
  border-radius: inherit;
  transition: width 160ms ease;
}

.stat-copy {
  margin: 0.55rem 0 0;
  color: var(--muted);
  line-height: 1.45;
  font-weight: 700;
}

.dash-stage {
  display: grid;
  gap: 0.75rem;
}

.hud-row {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.hud-pill {
  display: grid;
  gap: 0.3rem;
  align-content: center;
  min-height: 76px;
  padding: 0.8rem 1rem;
  background: rgba(255, 251, 241, 0.96);
  border: 1px solid var(--line);
  box-shadow: 0 14px 26px rgba(18, 44, 28, 0.08);
}

.hud-pill span {
  color: #cc6247;
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.hud-pill strong {
  font-size: clamp(1.15rem, 2vw, 1.5rem);
}

.hud-pill--mode strong {
  color: #19553a;
}

.canvas-shell {
  position: relative;
  overflow: hidden;
  padding: 0.55rem;
  background:
    linear-gradient(180deg, rgba(255, 248, 220, 0.98), rgba(124, 165, 75, 0.86));
  border: 3px solid rgba(49, 85, 41, 0.24);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.72), 0 24px 44px rgba(18, 44, 28, 0.14);
}

.embedded-toolbar {
  position: absolute;
  left: 1.05rem;
  right: 1.05rem;
  bottom: 1.05rem;
  z-index: 3;
  display: none;
  justify-content: space-between;
  align-items: flex-end;
  gap: 0.7rem;
  pointer-events: none;
}

.embedded-toolbar__group {
  display: flex;
  gap: 0.55rem;
  pointer-events: auto;
}

.toolbar-btn--embedded {
  min-height: 52px;
  max-width: 12rem;
  padding: 0.62rem 1rem;
  border: 3px solid #315d32;
  border-radius: 18px;
  background:
    radial-gradient(circle at 18% 22%, rgba(255, 255, 255, 0.62), transparent 28%),
    linear-gradient(180deg, #fff6b6 0%, #e9cf73 100%);
  box-shadow:
    0 8px 0 rgba(31, 83, 43, 0.55),
    0 14px 24px rgba(18, 44, 28, 0.2),
    inset 0 2px 0 rgba(255, 255, 255, 0.62);
  color: #244429;
  font-weight: 1000;
  letter-spacing: 0.01em;
  text-transform: uppercase;
  white-space: nowrap;
}

.toolbar-btn--embedded:active {
  transform: translateY(4px);
  box-shadow:
    0 4px 0 rgba(31, 83, 43, 0.55),
    0 8px 16px rgba(18, 44, 28, 0.18),
    inset 0 2px 0 rgba(255, 255, 255, 0.62);
}

body.is-embedded .embedded-toolbar {
  display: flex;
}

body.controls-touch.overlay-open .embedded-toolbar {
  display: none;
}

body.is-embedded .canvas-shell {
  padding: 0;
  border: 0;
  border-radius: 22px;
  background: transparent;
  box-shadow: none;
}

#game-canvas {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 20px;
  background: linear-gradient(180deg, #77defc, #afe9a6 58%, #2e7e3f 58%, #1b542b 100%);
  image-rendering: pixelated;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  background: rgba(18, 41, 28, 0.26);
}

.overlay.is-hidden {
  display: none;
}

.overlay-card {
  width: min(430px, 100%);
  padding: 1rem;
  border-radius: 28px;
  background: rgba(255, 249, 234, 0.96);
  border: 1px solid rgba(32, 58, 39, 0.1);
  box-shadow: 0 26px 50px rgba(16, 36, 23, 0.18);
}

.overlay-card h2 {
  margin: 0 0 0.55rem;
  font-size: clamp(1.45rem, 3.2vw, 1.95rem);
  line-height: 0.98;
  text-align: center;
}

.overlay-card p {
  margin: 0;
  color: var(--muted);
  font-weight: 700;
  line-height: 1.5;
  white-space: pre-line;
}

.overlay-message:empty {
  display: none;
}

.control-copy-grid {
  display: none;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.overlay-copy--controls .control-copy-grid {
  display: grid;
}

.control-copy-panel {
  display: grid;
  gap: 0.45rem;
  padding: 0.68rem;
  border-radius: 20px;
  background: rgba(244, 255, 218, 0.7);
  border: 1px solid rgba(32, 58, 39, 0.1);
}

.control-copy-panel h3 {
  margin: 0;
  color: #173624;
  font-size: 1rem;
  line-height: 1.05;
}

.control-copy-panel h3.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.control-copy-panel p {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.7rem;
  font-size: 0.94rem;
  white-space: normal;
}

.control-copy-panel strong {
  color: #24472c;
}

.control-copy-panel span {
  color: rgba(23, 54, 36, 0.72);
  text-align: right;
}

body.controls-keyboard .control-copy-panel--touch,
body.controls-touch .control-copy-panel--keyboard {
  display: none;
}

body.controls-keyboard .control-copy-grid,
body.controls-touch .control-copy-grid {
  grid-template-columns: minmax(0, 1fr);
}

.overlay-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
  justify-content: center;
  margin-top: 0.78rem;
}

.overlay-actions .big-btn {
  min-height: 58px;
  min-width: 150px;
  padding: 0.9rem 1.5rem;
  font-family: "Sinzano", "Avenir Next", "Trebuchet MS", sans-serif;
  font-size: 1.18rem;
  font-weight: 900;
  letter-spacing: 0.02em;
}

.touch-controls {
  display: none;
  gap: 0.7rem;
  justify-content: center;
  padding: 0.1rem;
  pointer-events: none;
}

.touch-btn {
  flex: 1 1 0;
  max-width: 280px;
  pointer-events: auto;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.touch-icon {
  display: none;
}

.touch-label {
  pointer-events: none;
}

.touch-btn--slide {
  background: linear-gradient(180deg, #fff5d0, #f6c56e);
}

.touch-btn.is-active {
  transform: translateY(2px) scale(0.97);
  box-shadow: 0 8px 16px rgba(92, 61, 14, 0.22);
}

@media (max-width: 920px) {
  .dash-shell {
    width: min(100vw, calc(100vw - 0.75rem));
    padding-top: 0.4rem;
  }

  .dash-layout {
    grid-template-columns: 1fr;
  }

  .dash-sidebar {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .hud-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 680px) {
  .dash-shell {
    width: 100vw;
    padding: 0;
  }

  .dash-header,
  .canvas-shell,
  .stat-card,
  .hud-pill {
    border-radius: 22px;
  }

  .dash-header {
    margin: 0.4rem;
  }

  .dash-layout {
    gap: 0.5rem;
    padding: 0 0.4rem 0.8rem;
  }

  .dash-sidebar {
    grid-template-columns: 1fr;
  }

  .dash-sidebar {
    display: none;
  }

  .header-actions {
    width: 100%;
    justify-content: stretch;
  }

  .header-actions .toolbar-btn {
    flex: 1 1 0;
  }

  .overlay {
    align-items: flex-start;
    padding: 0.55rem;
  }

  .embedded-toolbar {
    left: 0.7rem;
    right: 0.7rem;
    bottom: 0.75rem;
    gap: 0.45rem;
    flex-wrap: wrap;
  }

  .embedded-toolbar__group {
    gap: 0.38rem;
  }

  .toolbar-btn--embedded {
    min-height: 42px;
    max-width: none;
    padding: 0.42rem 0.5rem;
    border-radius: 15px;
    font-size: 0.7rem;
  }

  .overlay-card {
    max-height: calc(100% - 1.1rem);
    overflow: auto;
    padding: 0.72rem;
    border-radius: 20px;
  }

  .overlay-card h2 {
    margin-bottom: 0.42rem;
    font-size: clamp(1.25rem, 8vw, 1.8rem);
  }

  .control-copy-grid {
    grid-template-columns: 1fr;
  }

  .control-copy-panel {
    gap: 0.32rem;
    padding: 0.58rem;
    border-radius: 16px;
  }

  .control-copy-panel h3 {
    font-size: 0.9rem;
  }

  .control-copy-panel p {
    font-size: 0.82rem;
  }

  .overlay-actions {
    margin-top: 0.55rem;
  }

  .big-btn,
  .ghost-btn {
    min-height: 42px;
    padding: 0.62rem 0.9rem;
  }
}

@media (pointer: coarse), (max-width: 760px) {
  .touch-controls {
    position: fixed;
    left: 0;
    right: 0;
    bottom: calc(0.8rem + env(safe-area-inset-bottom));
    z-index: 8;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    padding: 0 clamp(1rem, 5vw, 2rem);
  }

  body.controls-keyboard .touch-controls {
    display: none;
  }

  body.controls-touch .touch-controls {
    display: flex;
  }

  .touch-btn {
    flex: 0 0 auto;
    width: clamp(82px, 20vw, 112px);
    height: clamp(82px, 20vw, 112px);
    min-height: 0;
    padding: 0;
    border: 4px solid rgba(64, 91, 35, 0.45);
    border-radius: 50%;
    background:
      radial-gradient(circle at 35% 24%, rgba(255, 255, 255, 0.58), transparent 24%),
      linear-gradient(180deg, #ffd95f, #f3a032);
    color: #432601;
    box-shadow:
      0 16px 28px rgba(18, 44, 28, 0.28),
      inset 0 -8px 0 rgba(131, 80, 17, 0.18);
  }

  .touch-btn--slide {
    background:
      radial-gradient(circle at 35% 24%, rgba(255, 255, 255, 0.64), transparent 24%),
      linear-gradient(180deg, #fff5c8, #edbf61);
  }

  .touch-icon {
    display: block;
    margin-top: -0.15rem;
    font-size: clamp(1.8rem, 7vw, 2.35rem);
    font-weight: 900;
    line-height: 0.78;
  }

  .touch-label {
    display: block;
    margin-top: 0.18rem;
    font-size: clamp(0.76rem, 3.4vw, 0.95rem);
    font-weight: 1000;
    letter-spacing: 0.02em;
  }

  body.is-embedded .touch-controls {
    bottom: calc(4.5rem + env(safe-area-inset-bottom));
  }
}
