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

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

html,
body {
  min-width: 280px;
  min-height: 100%;
  margin: 0;
}

body {
  display: grid;
  place-items: center;
  color: var(--game-text);
  background: var(--game-surface);
  font-family: var(--game-font);
}

button,
output {
  color: inherit;
  font: inherit;
}

button {
  touch-action: manipulation;
}

button:focus-visible {
  outline: 3px solid var(--game-accent);
  outline-offset: 2px;
}

.game {
  --channel-count: 3;
  --total-slots: 12;
  width: min(100%, 430px);
  min-height: 100svh;
  display: grid;
  align-content: center;
  gap: 8px;
  padding: 12px;
  overflow: hidden;
  background: var(--game-bg);
}

html:not([data-embed='true']) .game {
  box-shadow: var(--game-shadow);
}

.topline,
.jammer-panel,
.trail-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.kicker,
h1,
h2,
.jammer-panel p,
.prompt,
.decision-panel p {
  margin: 0;
}

.kicker {
  color: var(--game-accent-strong);
  font-family: var(--game-mono);
  font-size: 0.61rem;
  font-weight: 750;
  letter-spacing: 0.07em;
}

h1 {
  margin-top: 2px;
  font-size: clamp(1.28rem, 6vw, 1.58rem);
  line-height: 1.06;
  letter-spacing: -0.03em;
}

h2 {
  font-size: 0.72rem;
  line-height: 1.2;
}

.reset-button {
  min-width: 58px;
  min-height: 44px;
  padding: 0 10px;
  border: 1px solid var(--game-divider);
  border-radius: var(--game-radius);
  background: var(--game-surface);
  cursor: pointer;
  font-size: 0.72rem;
  font-weight: 700;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  overflow: hidden;
  border: 1px solid var(--game-divider);
  border-radius: var(--game-radius);
}

.metric {
  min-width: 0;
  padding: 6px 3px;
  text-align: center;
}

.metric + .metric {
  border-left: 1px solid var(--game-divider);
}

.metric span,
.metric output {
  display: block;
}

.metric span {
  overflow: hidden;
  color: var(--game-muted);
  font-size: 0.56rem;
  line-height: 1.15;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.metric output {
  margin-top: 2px;
  font-family: var(--game-mono);
  font-size: 0.8rem;
  font-weight: 800;
}

.jammer-panel {
  min-height: 52px;
  padding: 7px 9px;
  border-left: 4px solid var(--game-warning);
  border-radius: var(--game-radius);
  background: var(--game-surface);
}

.jammer-panel p {
  margin-top: 3px;
  color: var(--game-muted);
  font-size: 0.66rem;
  line-height: 1.22;
}

.mode {
  flex: 0 0 auto;
  max-width: 38%;
  padding: 4px 6px;
  border-radius: 999px;
  color: var(--game-warning);
  background: color-mix(in srgb, var(--game-warning) 14%, transparent);
  font-family: var(--game-mono);
  font-size: 0.58rem;
  font-weight: 750;
  text-align: center;
}

.channel-group {
  display: grid;
  grid-template-columns: repeat(var(--channel-count), minmax(0, 1fr));
  gap: 7px;
}

.channel {
  position: relative;
  min-width: 0;
  min-height: 54px;
  display: grid;
  padding: 5px 3px;
  place-content: center;
  border: 1px solid var(--game-divider);
  border-radius: var(--game-radius);
  background: var(--game-surface);
  cursor: pointer;
  line-height: 1.1;
}

.channel span {
  font-family: var(--game-mono);
  font-size: 0.82rem;
  font-weight: 800;
}

.channel small {
  margin-top: 3px;
  color: var(--game-muted);
  font-size: 0.56rem;
}

.channel.is-selected {
  border-color: var(--game-accent);
  background: var(--game-accent-soft);
  box-shadow: inset 0 0 0 1px var(--game-accent);
}

.channel.is-last-jammed::after {
  position: absolute;
  top: 3px;
  right: 5px;
  color: var(--game-danger);
  content: '×';
  font-size: 0.78rem;
  font-weight: 900;
  opacity: 0.72;
}

.channel:disabled {
  cursor: default;
  opacity: 0.72;
}

.game[data-phase='agent'] .channel.is-selected {
  border-color: var(--game-warning);
  background: color-mix(in srgb, var(--game-warning) 14%, var(--game-bg));
  box-shadow: inset 0 0 0 1px var(--game-warning);
}

.trail-section {
  min-width: 0;
  padding: 7px;
  border: 1px solid var(--game-divider);
  border-radius: var(--game-radius);
}

.trail-heading {
  margin-bottom: 6px;
}

.legend {
  display: flex;
  gap: 6px;
  color: var(--game-muted);
  font-size: 0.56rem;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

.legend b {
  font-weight: 600;
}

.key {
  width: 7px;
  height: 7px;
  display: block;
  border-radius: 2px;
}

.jammer-key {
  background: var(--game-danger);
  opacity: 0.7;
}

.packet-key {
  border-radius: 50%;
  background: var(--game-accent);
}

.trail {
  display: grid;
  min-width: 0;
  grid-template-columns: 31px minmax(0, 1fr);
  gap: 5px;
}

.trail-labels,
.trail-grid {
  display: grid;
  grid-template-rows: repeat(var(--channel-count), 15px);
  gap: 3px 3px;
}

.trail-labels span {
  display: grid;
  place-items: center start;
  color: var(--game-muted);
  font-family: var(--game-mono);
  font-size: 0.52rem;
}

.trail-grid {
  min-width: 0;
  grid-template-columns: repeat(var(--total-slots), minmax(0, 1fr));
}

.trail-cell {
  position: relative;
  min-width: 0;
  border-radius: 2px;
  background: var(--game-surface-strong);
}

.trail-cell.is-jammed {
  background: color-mix(in srgb, var(--game-danger) 58%, var(--game-bg));
}

.trail-cell.is-success::after,
.trail-cell.is-collision::after {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 7px;
  height: 7px;
  border: 1px solid var(--game-bg);
  border-radius: 50%;
  background: var(--game-accent);
  content: '';
  transform: translate(-50%, -50%);
}

.trail-cell.is-collision::after {
  background: var(--game-danger);
  box-shadow: 0 0 0 1px var(--game-danger);
}

.prompt {
  min-height: 2.5em;
  display: grid;
  place-items: center;
  color: var(--game-muted);
  font-size: 0.7rem;
  line-height: 1.25;
  text-align: center;
}

.prompt.is-danger {
  color: var(--game-danger);
  font-weight: 700;
}

.decision-panel {
  padding: 8px;
  border: 1px solid var(--game-divider);
  border-left: 4px solid var(--game-accent);
  border-radius: var(--game-radius);
  background: var(--game-surface);
}

.decision-panel[hidden] {
  display: none;
}

.decision-panel p {
  color: var(--game-muted);
  font-size: 0.64rem;
  line-height: 1.25;
}

.decision-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 5px;
  margin-top: 6px;
}

.decision-actions button {
  min-height: 44px;
  padding: 5px 7px;
  border: 1px solid var(--game-divider);
  border-radius: var(--game-radius);
  background: var(--game-bg);
  cursor: pointer;
  font-size: 0.68rem;
  font-weight: 750;
}

.decision-actions .primary {
  border-color: var(--game-accent);
  color: var(--game-on-accent);
  background: var(--game-accent);
}

.decision-actions .quiet {
  min-height: 44px;
  color: var(--game-muted);
}

.decision-actions button:disabled {
  cursor: default;
  opacity: 0.5;
}

.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;
}

@media (max-width: 320px), (max-height: 540px) {
  .game {
    gap: 6px;
    padding: 9px;
  }

  .jammer-panel {
    min-height: 48px;
    padding-block: 5px;
  }

  .trail-section {
    padding: 5px;
  }

  .trail-labels,
  .trail-grid {
    grid-template-rows: repeat(var(--channel-count), 13px);
    gap-block: 2px;
  }

  .decision-panel {
    padding: 6px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
  }
}
