:root {
  color-scheme: dark;
  --ink: #f4f1e8;
  --muted: #b9baad;
  --paper: #151714;
  --panel: #1e211c;
  --line: rgba(244, 241, 232, 0.14);
  --line-strong: rgba(244, 241, 232, 0.28);
  --green: #77c892;
  --gold: #f0b650;
  --coral: #ee6b5d;
  --aqua: #58bfd1;
  --shadow: rgba(0, 0, 0, 0.32);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button {
  font: inherit;
}

.game-shell {
  position: relative;
  display: grid;
  grid-template-rows: minmax(54px, auto) minmax(0, 1fr) minmax(76px, auto);
  width: 100vw;
  height: 100svh;
  min-height: 540px;
  background:
    linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    var(--paper);
  background-size: 22px 22px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-width: 0;
  padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 10px
    max(16px, env(safe-area-inset-left));
  border-bottom: 1px solid var(--line);
  background: rgba(21, 23, 20, 0.92);
}

.brand,
.meters {
  display: flex;
  align-items: center;
  min-width: 0;
}

.brand {
  gap: 10px;
}

.brand strong {
  overflow: hidden;
  font-size: 16px;
  font-weight: 780;
  letter-spacing: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand span,
.meters span {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.045);
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.meters {
  justify-content: flex-end;
  gap: 8px;
}

.stage-wrap {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  touch-action: none;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
}

#gameCanvas:active {
  cursor: grabbing;
}

.toolbelt {
  display: grid;
  grid-template-columns: repeat(7, 46px) minmax(120px, 1fr);
  align-items: center;
  gap: 10px;
  padding: 12px max(16px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
  border-top: 1px solid var(--line);
  background: rgba(30, 33, 28, 0.96);
  box-shadow: 0 -18px 45px var(--shadow);
}

.tool {
  display: inline-grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #292d26;
  color: var(--ink);
  cursor: pointer;
  font-size: 24px;
  line-height: 1;
  transition:
    transform 140ms ease,
    border-color 140ms ease,
    background 140ms ease;
}

.tool:hover,
.tool:focus-visible {
  border-color: rgba(119, 200, 146, 0.8);
  background: #32372f;
  outline: none;
  transform: translateY(-1px);
}

.tool:active {
  transform: translateY(1px);
}

.tool.accent {
  border-color: rgba(240, 182, 80, 0.7);
  color: #111412;
  background: var(--gold);
}

.readout {
  overflow: hidden;
  min-width: 0;
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  line-height: 1.35;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tutorial-layer {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  pointer-events: none;
}

.tutorial-layer.active {
  display: block;
}

.tutorial-layer::before {
  position: absolute;
  inset: 0;
  background: rgba(6, 8, 7, 0.36);
  content: "";
}

.tutorial-spotlight {
  position: absolute;
  left: var(--spot-x, 50%);
  top: var(--spot-y, 50%);
  width: var(--spot-w, 120px);
  height: var(--spot-h, 120px);
  border: 2px solid rgba(240, 182, 80, 0.95);
  border-radius: 8px;
  box-shadow:
    0 0 0 9999px rgba(6, 8, 7, 0.42),
    0 0 28px rgba(240, 182, 80, 0.32);
  transform: translateZ(0);
  transition:
    left 180ms ease,
    top 180ms ease,
    width 180ms ease,
    height 180ms ease;
}

.tutorial-card {
  position: absolute;
  right: max(16px, env(safe-area-inset-right));
  bottom: calc(92px + env(safe-area-inset-bottom));
  width: min(360px, calc(100vw - 32px));
  padding: 16px;
  border: 1px solid rgba(244, 241, 232, 0.22);
  border-radius: 8px;
  background: rgba(30, 33, 28, 0.98);
  box-shadow: 0 18px 54px rgba(0, 0, 0, 0.42);
  pointer-events: auto;
}

.tutorial-kicker {
  margin-bottom: 8px;
  color: var(--gold);
  font-size: 12px;
  font-weight: 760;
  font-variant-numeric: tabular-nums;
}

.tutorial-card h2 {
  margin: 0 0 8px;
  color: var(--ink);
  font-size: 18px;
  line-height: 1.25;
}

.tutorial-card p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

.tutorial-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}

.tutorial-actions button {
  min-width: 78px;
  min-height: 38px;
  border-radius: 8px;
  cursor: pointer;
}

.tutorial-link {
  border: 1px solid var(--line-strong);
  background: transparent;
  color: var(--muted);
}

.tutorial-primary {
  border: 1px solid rgba(240, 182, 80, 0.7);
  background: var(--gold);
  color: #111412;
  font-weight: 760;
}

@media (max-width: 720px) {
  .game-shell {
    min-height: 500px;
    grid-template-rows: minmax(72px, auto) minmax(0, 1fr) minmax(124px, auto);
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }

  .meters {
    width: 100%;
    justify-content: space-between;
  }

  .meters span {
    flex: 1 1 0;
    justify-content: center;
    padding-inline: 6px;
  }

  .toolbelt {
    grid-template-columns: repeat(7, minmax(38px, 1fr));
    gap: 8px;
  }

  .tool {
    width: 100%;
    height: 44px;
  }

  .readout {
    grid-column: 1 / -1;
    text-align: center;
    white-space: normal;
  }

  .tutorial-card {
    right: 16px;
    bottom: calc(132px + env(safe-area-inset-bottom));
    left: 16px;
    width: auto;
    padding: 14px;
  }

  .tutorial-actions button {
    flex: 1 1 0;
  }
}
