/* Arrowtrace — pixel trail-logic skin.
 *
 * Shared geometry comes from the --pixel-* tokens in /assets/css/tokens.css.
 * Game-specific palette and board colours live only in this file. The Shell
 * pixel.css is not loaded inside the iframe.
 */

:root {
  color-scheme: light;

  --at-grid: var(--pixel-grid-size);
  --at-border: var(--pixel-border-width);
  --at-border-thin: var(--pixel-border-thin);
  --at-shadow: var(--pixel-shadow-offset);
  --at-shadow-lg: var(--pixel-shadow-offset-lg);
  --at-font: var(--pixel-ui-font);

  /* Forest trail palette — light */
  --at-bg: #eef2e4;
  --at-bg-2: #d9e0c8;
  --at-surface: #fffdf4;
  --at-surface-2: #f1eedb;
  --at-surface-3: #e2e5d0;
  --at-ink: #22281e;
  --at-muted: #5f6856;
  --at-line: #22281e;
  --at-accent: #3f7a4d;
  --at-accent-soft: #cfe3c8;
  --at-warm: #b9781f;
  --at-warm-soft: #f3dfb7;
  --at-danger: #b8462f;
  --at-danger-soft: #f2c9c0;

  --at-board-a: #f6f2e2;
  --at-board-b: #e9e5d2;
  --at-board-grid: #c9c6ad;
  --at-silhouette: #d5e6c9;
  --at-silhouette-line: #7fa878;
  --at-route: #2e3a2c;
  --at-route-selected: #2f5fa8;
  --at-route-hint: #b9781f;
  --at-route-blocked: #b8462f;
  --at-route-cleared: #3f7a4d;
  --at-route-outline: #fffdf4;
  --at-on-accent: #fffdf4;
  --at-scrim: rgba(12, 16, 12, 0.74);

  --at-mark-size: 40px;
  --at-sprite-url: url("../assets/pixel/arrowtrace-sprites.png");
}

[data-theme="dark"] {
  color-scheme: dark;

  --at-bg: #0d1410;
  --at-bg-2: #17231a;
  --at-surface: #1b291e;
  --at-surface-2: #243528;
  --at-surface-3: #2a3d2d;
  --at-ink: #eef5e6;
  --at-muted: #a4b39a;
  --at-line: #eef5e6;
  --at-accent: #7ccf8b;
  --at-accent-soft: #2c4a37;
  --at-warm: #ffc857;
  --at-warm-soft: #4a3a18;
  --at-danger: #ff6b57;
  --at-danger-soft: #4a241c;

  --at-board-a: #142018;
  --at-board-b: #0f1a12;
  --at-board-grid: #3e5442;
  --at-silhouette: #25402c;
  --at-silhouette-line: #4f7a58;
  --at-route: #cfd8c4;
  --at-route-selected: #8fb6ff;
  --at-route-hint: #ffc857;
  --at-route-blocked: #ff6b57;
  --at-route-cleared: #7ccf8b;
  --at-route-outline: #1b291e;
  --at-on-accent: #08100b;
  --at-scrim: rgba(3, 7, 5, 0.8);
}

@media (min-width: 768px) {
  :root {
    --at-mark-size: 48px;
  }
}

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

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--at-bg);
}

body {
  color: var(--at-ink);
  font-family: var(--at-font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: none;
  text-rendering: optimizeSpeed;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

button {
  color: inherit;
  font: inherit;
  touch-action: manipulation;
}

button,
canvas {
  touch-action: manipulation;
}

button:focus-visible,
canvas:focus-visible {
  outline: var(--at-border) solid var(--at-warm);
  outline-offset: 2px;
}

body.is-pointer-input :is(button, canvas):focus-visible {
  outline: none;
}

/* App frame --------------------------------------------------------------- */

.at-app {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100dvh;
  min-height: 0;
  padding:
    max(12px, env(safe-area-inset-top))
    max(12px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom))
    max(12px, env(safe-area-inset-left));
  overflow: hidden;
  isolation: isolate;
  background: var(--at-bg);
}

.at-scene {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0.38;
  background-color: var(--at-bg);
  background-image: url("../assets/arrowtrace-light.png");
  background-position: center;
  background-size: cover;
  image-rendering: -webkit-optimize-contrast;
  image-rendering: pixelated;
}

[data-theme="dark"] .at-scene {
  background-image: url("../assets/arrowtrace-dark.png");
  opacity: 0.5;
}

.at-topbar,
.at-main,
.at-boot,
.at-dialog {
  position: relative;
  z-index: 1;
}

.at-topbar,
.at-main {
  z-index: 2;
}

/* Top bar ----------------------------------------------------------------- */

.at-topbar {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: var(--at-grid);
  min-height: var(--at-mark-size);
  padding: 0 0 var(--at-grid);
}

.at-brand {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: var(--at-grid);
}

.at-brand__mark {
  flex: 0 0 auto;
  width: var(--at-mark-size);
  height: var(--at-mark-size);
  border: var(--at-border) solid var(--at-line);
  border-radius: 0;
  background-color: var(--at-surface);
  background-image: var(--at-sprite-url);
  background-repeat: no-repeat;
  background-size: calc(var(--at-mark-size) * 4) calc(var(--at-mark-size) * 2);
  background-position: 0 calc(var(--at-mark-size) * -1);
  box-shadow: var(--at-shadow) var(--at-shadow) 0 var(--at-line);
  image-rendering: -webkit-optimize-contrast;
  image-rendering: pixelated;
}

.at-brand__copy {
  display: flex;
  min-width: 0;
  flex-direction: column;
  line-height: 1.1;
}

.at-brand__copy strong {
  overflow: hidden;
  font-size: 18px;
  letter-spacing: 0.02em;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.at-brand__copy span {
  overflow: hidden;
  color: var(--at-muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Main -------------------------------------------------------------------- */

.at-main {
  display: flex;
  min-height: 0;
  flex: 1 1 auto;
  flex-direction: column;
  gap: var(--at-grid);
}

/* HUD --------------------------------------------------------------------- */

.at-hud {
  flex: 0 0 auto;
  padding: var(--at-grid);
  border: var(--at-border) solid var(--at-line);
  border-radius: 0;
  background: var(--at-surface);
  box-shadow: var(--at-shadow) var(--at-shadow) 0 var(--at-line);
}

.at-hud__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--at-grid);
}

.at-level {
  display: flex;
  min-width: 0;
  flex-direction: column;
  line-height: 1.1;
}

.at-level__label {
  font-size: 18px;
  font-weight: 700;
  text-transform: uppercase;
}

.at-level__animal {
  color: var(--at-muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.at-hud__metrics {
  display: flex;
  align-items: center;
  gap: var(--at-grid);
}

.at-timer {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.at-clock {
  position: relative;
  display: inline-block;
  width: 14px;
  height: 14px;
  border: var(--at-border-thin) solid currentColor;
  border-radius: 0;
}

.at-clock::before,
.at-clock::after {
  content: "";
  position: absolute;
  background: currentColor;
}

.at-clock::before {
  top: 3px;
  left: 6px;
  width: 2px;
  height: 4px;
}

.at-clock::after {
  top: 6px;
  left: 6px;
  width: 4px;
  height: 2px;
}

.at-timer.is-low {
  color: var(--at-danger);
}

.at-hearts {
  display: inline-flex;
  gap: 2px;
  color: var(--at-danger);
  font-size: 16px;
  letter-spacing: 0;
}

.at-hud__progress {
  display: flex;
  align-items: center;
  gap: var(--at-grid);
  margin-top: var(--at-grid);
}

.at-progress {
  height: 8px;
  flex: 1 1 auto;
  overflow: hidden;
  border: var(--at-border-thin) solid var(--at-line);
  border-radius: 0;
  background: var(--at-surface-2);
}

.at-progress span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--at-accent);
  transition: width 200ms steps(4, end);
}

.at-remaining {
  flex: 0 0 auto;
  color: var(--at-muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  white-space: nowrap;
}

/* Icon button ------------------------------------------------------------- */

.at-icon-btn {
  display: grid;
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  place-items: center;
  padding: 0;
  border: var(--at-border) solid var(--at-line);
  border-radius: 0;
  background: var(--at-surface);
  box-shadow: var(--at-shadow) var(--at-shadow) 0 var(--at-line);
  cursor: pointer;
}

.at-icon-btn:active {
  transform: translate(var(--at-shadow), var(--at-shadow));
  box-shadow: 0 0 0 var(--at-line);
}

.at-pause {
  display: inline-flex;
  gap: 4px;
}

.at-pause::before,
.at-pause::after {
  content: "";
  display: block;
  width: 5px;
  height: 16px;
  background: currentColor;
}

/* Board ------------------------------------------------------------------- */

.at-board-panel {
  display: flex;
  min-height: 0;
  flex: 1 1 auto;
  flex-direction: column;
  overflow: hidden;
  border: var(--at-border) solid var(--at-line);
  border-radius: 0;
  background-color: var(--at-board-a);
  background-image: conic-gradient(
    var(--at-board-b) 0 25%,
    var(--at-board-a) 0 50%,
    var(--at-board-b) 0 75%,
    var(--at-board-a) 0
  );
  background-size: calc(var(--at-grid) * 2) calc(var(--at-grid) * 2);
  box-shadow: var(--at-shadow-lg) var(--at-shadow-lg) 0 var(--at-line);
}

.at-board-head {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: var(--at-grid);
  padding: var(--at-grid) var(--at-grid) 0;
  color: var(--at-muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.at-board-head span:first-child {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.at-board-head i {
  width: 8px;
  height: 8px;
  background: var(--at-accent);
}

.at-board-wrap {
  position: relative;
  display: flex;
  min-height: 0;
  flex: 1 1 auto;
}

#board {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 150px;
  outline-offset: -3px;
  touch-action: none;
  image-rendering: -webkit-optimize-contrast;
  image-rendering: pixelated;
}

/* Selection bar ----------------------------------------------------------- */

.at-selection {
  position: absolute;
  right: var(--at-grid);
  bottom: var(--at-grid);
  left: var(--at-grid);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--at-grid);
  min-height: 52px;
  padding: 4px 4px 4px var(--at-grid);
  border: var(--at-border) solid var(--at-line);
  border-radius: 0;
  background: var(--at-surface);
  box-shadow: var(--at-shadow) var(--at-shadow) 0 var(--at-line);
}

.at-selection[hidden] {
  display: none;
}

.at-selection span {
  min-width: 0;
  overflow: hidden;
  font-size: 14px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Help + controls --------------------------------------------------------- */

.at-help {
  flex: 0 0 auto;
  margin: 0;
  padding: 4px var(--at-grid) var(--at-grid);
  color: var(--at-muted);
  font-size: 12px;
  text-align: center;
}

.at-controls {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: var(--at-grid);
  min-height: 56px;
  padding: 0;
}

.at-tool {
  display: flex;
  min-width: 58px;
  min-height: 44px;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
  border: var(--at-border) solid var(--at-line);
  border-radius: 0;
  background: var(--at-surface);
  box-shadow: var(--at-shadow) var(--at-shadow) 0 var(--at-line);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
}

.at-tool:active,
.at-zoom__btn:active,
.at-btn:active,
.at-icon-btn:active {
  transform: translate(var(--at-shadow), var(--at-shadow));
  box-shadow: 0 0 0 var(--at-line);
}

.at-zoom {
  display: flex;
  min-height: 44px;
  flex: 1 1 auto;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 0 4px;
  border: var(--at-border) solid var(--at-line);
  border-radius: 0;
  background: var(--at-surface);
  box-shadow: var(--at-shadow) var(--at-shadow) 0 var(--at-line);
}

.at-zoom__btn {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 0;
  border-radius: 0;
  background: transparent;
  font-family: var(--at-font);
  font-size: 22px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}

.at-zoom__btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.at-zoom__value {
  min-width: 50px;
  color: var(--at-ink);
  font-size: 12px;
  font-weight: 700;
  text-align: center;
}

/* Boot -------------------------------------------------------------------- */

.at-boot {
  position: absolute;
  z-index: 20;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--at-grid);
  color: var(--at-muted);
  background: var(--at-bg);
  font-size: 14px;
}

.at-boot[hidden] {
  display: none;
}

.at-boot__mark {
  width: 48px;
  height: 48px;
  border: var(--at-border) solid var(--at-line);
  background-color: var(--at-surface);
  background-image: var(--at-sprite-url);
  background-repeat: no-repeat;
  background-size: 192px 96px;
  background-position: 0 -48px;
  box-shadow: var(--at-shadow) var(--at-shadow) 0 var(--at-line);
  image-rendering: -webkit-optimize-contrast;
  image-rendering: pixelated;
}

/* Dialogs ----------------------------------------------------------------- */

.at-dialog {
  width: min(calc(100% - var(--at-grid) * 2), 380px);
  max-height: 80vh;
  padding: 16px;
  overflow: auto;
  border: var(--at-border) solid var(--at-line);
  border-radius: 0;
  color: var(--at-ink);
  background: var(--at-surface);
  box-shadow: var(--at-shadow-lg) var(--at-shadow-lg) 0 var(--at-line);
  text-align: center;
}

.at-dialog::backdrop {
  background: var(--at-scrim);
}

.at-dialog__badge {
  width: 64px;
  height: 64px;
  margin: 0 auto var(--at-grid);
  background-image: var(--at-sprite-url);
  background-repeat: no-repeat;
  background-size: 256px 128px;
  background-position: -64px -64px;
  image-rendering: -webkit-optimize-contrast;
  image-rendering: pixelated;
}

.at-dialog[data-result="lose"] .at-dialog__badge {
  background-position: 0 -64px;
}

.at-dialog__eyebrow {
  margin: 0 0 4px;
  color: var(--at-accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.at-dialog h2 {
  margin: 0;
  font-family: var(--at-font);
  font-size: 24px;
  line-height: 1.1;
  text-transform: uppercase;
}

.at-dialog__meta {
  margin: var(--at-grid) 0;
  color: var(--at-muted);
  font-size: 14px;
}

.at-result-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin-bottom: var(--at-grid);
  padding: var(--at-grid);
  border: var(--at-border-thin) solid var(--at-line);
  background: var(--at-surface-2);
}

.at-result-metrics span {
  display: flex;
  flex-direction: column;
}

.at-result-metrics span + span {
  border-left: var(--at-border-thin) solid var(--at-line);
}

.at-result-metrics strong {
  font-size: 24px;
  font-variant-numeric: tabular-nums;
}

.at-result-metrics small {
  color: var(--at-muted);
  font-size: 12px;
  text-transform: uppercase;
}

.at-dialog__actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--at-grid);
}

.at-dialog--compact .at-btn {
  width: 100%;
}

.at-btn {
  min-height: 48px;
  padding: 0 12px;
  border: var(--at-border) solid var(--at-line);
  border-radius: 0;
  font-family: var(--at-font);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow: var(--at-shadow) var(--at-shadow) 0 var(--at-line);
}

.at-btn--primary {
  color: var(--at-on-accent);
  background: var(--at-accent);
}

.at-btn--secondary {
  background: var(--at-surface-2);
}

.at-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

[hidden] {
  display: none !important;
}

/* Compact landscape ------------------------------------------------------- */

@media (orientation: landscape) and (max-height: 560px) {
  .at-topbar {
    display: none;
  }

  .at-help {
    display: none;
  }

  .at-hud {
    padding: 4px var(--at-grid);
  }

  .at-hud__progress {
    margin-top: 4px;
  }

  .at-controls {
    min-height: 48px;
  }

  .at-board-head {
    display: none;
  }
}

@media (orientation: landscape) and (max-height: 340px) {
  .at-app {
    gap: 4px;
    padding:
      max(4px, env(safe-area-inset-top))
      max(4px, env(safe-area-inset-right))
      max(4px, env(safe-area-inset-bottom))
      max(4px, env(safe-area-inset-left));
  }

  .at-hud__progress {
    display: none;
  }
}

/* Phone portrait ---------------------------------------------------------- */

@media (max-width: 767px) {
  .at-topbar {
    display: none;
  }

  .at-app {
    padding:
      max(8px, env(safe-area-inset-top))
      max(8px, env(safe-area-inset-right))
      max(8px, env(safe-area-inset-bottom))
      max(8px, env(safe-area-inset-left));
    gap: 8px;
  }

  .at-hud {
    padding: 6px var(--at-grid);
  }

  .at-level__label {
    font-size: 16px;
  }

  .at-timer {
    font-size: 16px;
  }

  .at-board-head {
    display: none;
  }

  .at-help {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }
}

@media (max-width: 340px) {
  .at-brand__copy,
  .at-level__animal {
    display: none;
  }

  .at-tool {
    min-width: 54px;
  }
}

/* Reduced motion ---------------------------------------------------------- */

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