@import url('../shared/theme.css');

:root {
  --ink: var(--game-surface);
  --ink-deep: var(--game-bg);
  --paper: var(--game-text);
  --muted: var(--game-muted);
  --line: var(--game-divider);
  --focus: var(--game-accent);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 280px;
  background: var(--ink-deep);
}

body {
  display: grid;
  min-width: 280px;
  min-height: 100svh;
  margin: 0;
  padding: clamp(0.75rem, 3vw, 1.25rem);
  place-items: center;
  color: var(--paper);
  background:
    radial-gradient(circle at 16% 12%, rgba(255, 126, 107, 0.16), transparent 13rem),
    radial-gradient(circle at 90% 88%, rgba(110, 168, 254, 0.13), transparent 15rem),
    var(--ink-deep);
  font-family: var(--game-font);
}

button {
  font: inherit;
}

.echo-card {
  display: grid;
  width: min(100%, 420px);
  padding: clamp(1rem, 4vw, 1.35rem);
  gap: 0.85rem;
  background: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--game-radius);
  box-shadow: var(--game-shadow);
}

.card-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 1rem;
}

.eyebrow {
  margin: 0 0 0.2rem;
  color: var(--game-accent);
  font-family: var(--game-mono);
  font-size: 0.58rem;
  font-weight: 800;
  letter-spacing: 0.18em;
}

h1 {
  margin: 0;
  font-family: var(--game-font);
  font-size: clamp(1.35rem, 6vw, 1.75rem);
  font-weight: 500;
  letter-spacing: 0.02em;
}

.round-meter {
  display: flex;
  align-items: baseline;
  min-width: 4.3rem;
  margin: 0;
  padding: 0.42rem 0.62rem;
  justify-content: center;
  background: var(--game-surface-strong);
  border: 1px solid var(--line);
  border-radius: var(--game-radius);
  font-family: var(--game-mono);
  font-variant-numeric: tabular-nums;
}

.round-meter span {
  font-size: 1rem;
  font-weight: 800;
}

.round-meter small {
  margin-left: 0.25rem;
  color: var(--muted);
  font-size: 0.65rem;
}

.intro {
  margin: 0;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.55;
}

.echo-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-auto-rows: clamp(80px, 22vw, 108px);
  gap: 0.65rem;
}

.echo-pad {
  position: relative;
  display: flex;
  min-width: 0;
  padding: 0.75rem;
  align-items: end;
  justify-content: space-between;
  color: #111321;
  border: 0;
  border-radius: var(--game-radius);
  cursor: pointer;
  font-size: 0.7rem;
  font-weight: 800;
  touch-action: manipulation;
  transform: translateY(0);
  filter: saturate(0.72) brightness(0.78);
  box-shadow: inset 0 1px rgba(255, 255, 255, 0.32);
  transition:
    filter 120ms ease,
    transform 120ms ease,
    box-shadow 120ms ease;
}

.echo-pad:disabled {
  cursor: default;
  opacity: 1;
}

.echo-pad:not(:disabled):hover {
  filter: saturate(0.92) brightness(0.92);
}

.echo-pad:not(:disabled):active,
.echo-pad.is-active {
  filter: saturate(1.08) brightness(1.2);
  transform: translateY(-2px);
  box-shadow:
    inset 0 1px rgba(255, 255, 255, 0.5),
    0 0 0 3px rgba(255, 246, 223, 0.88),
    0 0 1.5rem var(--glow);
}

.echo-pad:focus-visible,
.action:focus-visible,
.assist:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.pad-number {
  display: grid;
  width: 2rem;
  height: 2rem;
  place-items: center;
  background: rgba(17, 19, 33, 0.14);
  border: 1px solid rgba(17, 19, 33, 0.16);
  border-radius: 50%;
  font-size: 0.9rem;
}

.pad-coral {
  --glow: rgba(255, 126, 107, 0.5);
  background: linear-gradient(145deg, #ff9b83, #dc625e);
}

.pad-gold {
  --glow: rgba(255, 209, 102, 0.5);
  background: linear-gradient(145deg, #ffe092, #dfa842);
}

.pad-mint {
  --glow: rgba(115, 210, 166, 0.5);
  background: linear-gradient(145deg, #9fe5c2, #50b789);
}

.pad-blue {
  --glow: rgba(110, 168, 254, 0.5);
  background: linear-gradient(145deg, #9ec5ff, #5a82dc);
}

.feedback {
  display: grid;
  gap: 0.45rem;
}

.progress-track {
  height: 3px;
  overflow: hidden;
  background: var(--game-surface-strong);
  border-radius: var(--game-radius);
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, #ff8e78, #ffe08b, #82dbb2, #83b4ff);
  border-radius: inherit;
  transition: width 160ms ease;
}

#status {
  min-height: 1.25rem;
  margin: 0;
  color: var(--paper);
  font-family: var(--game-mono);
  font-size: 0.76rem;
  font-weight: 700;
  text-align: center;
}

.controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.55rem;
}

.action,
.assist {
  width: 100%;
  min-height: 48px;
  padding: 0.7rem 1rem;
  color: var(--game-on-accent);
  background: var(--game-accent);
  border: 0;
  border-radius: var(--game-radius);
  cursor: pointer;
  font-weight: 850;
  touch-action: manipulation;
}

.action:hover {
  background: var(--game-accent-strong);
}

.assist {
  width: auto;
  color: var(--paper);
  background: var(--game-surface-strong);
  border: 1px solid var(--line);
  font-size: 0.68rem;
}

.assist[aria-pressed='true'] {
  color: var(--game-on-accent);
  background: var(--game-accent);
}

.instructions {
  margin: -0.25rem 0 0;
  color: var(--muted);
  font-size: 0.66rem;
  line-height: 1.45;
  text-align: center;
}

html[data-embed='true'] body {
  padding: 0;
  place-items: stretch;
}

html[data-embed='true'] .echo-card {
  width: 100%;
  min-height: 100svh;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

@media (max-height: 470px) {
  .echo-card {
    gap: 0.58rem;
    padding-block: 0.85rem;
  }

  .intro {
    display: none;
  }

  .echo-grid {
    grid-auto-rows: clamp(68px, 19vw, 84px);
  }
}

@media (max-height: 390px) {
  .echo-card {
    gap: 0.4rem;
    padding: 0.65rem;
  }

  .echo-grid {
    grid-auto-rows: clamp(54px, 16vw, 64px);
    gap: 0.45rem;
  }

  .action,
  .assist {
    min-height: 44px;
  }

  .instructions {
    display: none;
  }
}

@media (max-width: 320px) {
  .echo-card {
    padding-inline: 0.75rem;
  }

  .card-header {
    gap: 0.5rem;
  }

  .action,
  .assist {
    padding-inline: 0.65rem;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .echo-grid.is-wrong {
    animation: nudge 220ms ease-in-out;
  }

  @keyframes nudge {
    25% {
      transform: translateX(-4px);
    }

    75% {
      transform: translateX(4px);
    }
  }
}

@media (prefers-reduced-motion: reduce) {
  .echo-pad,
  .progress-track span {
    transition: none;
  }

  .echo-pad:not(:disabled):active,
  .echo-pad.is-active {
    transform: none;
  }
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    color-scheme: dark;
    --game-surface-strong: #2c3237;
    --game-accent: #5eead4;
    --game-accent-strong: #2dd4bf;
    --game-on-accent: #10201e;
    --game-shadow: 0 12px 32px rgba(0, 0, 0, 0.24);
    --ink: #212529;
    --ink-deep: #1c1c1d;
    --paper: #e0e0e0;
    --muted: #9e9e9e;
    --line: #424246;
    --focus: #5eead4;
  }
}
