:root {
  color-scheme: light;
  --background: #ffffff;
  --surface: #f7f7f5;
  --ink: #20201e;
  --muted: #6f6f69;
  --line: #d5d5cf;
  --red: #b4473f;
  --blue: #356d86;
  --focus: #555550;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-width: 320px;
  background: var(--background);
  color: var(--ink);
  line-height: 1.45;
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--background);
}

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

button,
summary,
select {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
select:focus-visible,
summary:focus-visible,
a:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}

button:disabled,
select:disabled {
  cursor: not-allowed;
  opacity: 0.4;
}

a {
  color: inherit;
  text-underline-offset: 3px;
}

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

#afterclock-game {
  width: min(100% - 40px, 720px);
  margin: 0 auto;
  padding: 32px 0 28px;
}

.app-header {
  display: flex;
  gap: 24px;
  align-items: start;
  justify-content: space-between;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 6vw, 2.65rem);
  letter-spacing: -0.035em;
  line-height: 1;
}

.premise {
  max-width: 520px;
  margin: 9px 0 0;
  color: var(--muted);
  font-size: 0.98rem;
}

.repo-link {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.82rem;
}

.game-controls {
  display: flex;
  gap: 14px;
  align-items: end;
  margin-top: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.field {
  display: grid;
  gap: 5px;
}

.field > span {
  color: var(--muted);
  font-size: 0.72rem;
}

.field select {
  min-width: 148px;
  min-height: 38px;
  padding: 6px 30px 6px 9px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--background);
}

.quiet-actions {
  display: flex;
  gap: 16px;
  margin-left: auto;
  padding-bottom: 7px;
}

.text-button {
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  font-size: 0.82rem;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.scoreboard {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 18px;
  align-items: center;
  padding: 18px 0;
}

.score {
  display: flex;
  gap: 8px;
  align-items: baseline;
  font-weight: 600;
}

.score strong {
  font-size: 1.65rem;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.score-red {
  color: var(--red);
}

.score-blue {
  justify-content: flex-end;
  color: var(--blue);
}

.turn-readout {
  display: grid;
  justify-items: center;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.35;
}

.turn-readout strong {
  color: var(--ink);
  font-size: 1rem;
}

.play-layout {
  display: block;
}

.move-panel {
  width: min(100%, 560px);
  margin: 4px auto 0;
}

.ac-status {
  margin: 0 0 14px;
  font-size: 1.05rem;
  font-weight: 600;
}

.orientation-control {
  display: flex;
  gap: 8px;
  align-items: end;
  margin: 0;
  padding: 0;
  border: 0;
}

.orientation-control legend {
  width: 100%;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.72rem;
}

.orientation-button {
  display: flex;
  gap: 8px;
  align-items: baseline;
  justify-content: center;
  min-width: 108px;
  min-height: 40px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--background);
  cursor: pointer;
}

.orientation-button.is-active {
  border-color: var(--ink);
  background: var(--ink);
  color: white;
}

.orientation-button:not(:disabled):not(.is-active):hover {
  border-color: var(--ink);
}

.orientation-button strong {
  font-size: 0.9rem;
}

.orientation-button small {
  font-size: 0.7rem;
  opacity: 0.65;
}

.board-side {
  min-width: 0;
}

.board-frame {
  position: relative;
  width: min(calc(100% - 24px), 560px);
  margin: 28px auto 0;
}

.board-axis {
  position: absolute;
  display: grid;
  color: var(--muted);
  font-size: 0.65rem;
}

.board-axis-top {
  right: 0;
  bottom: calc(100% + 7px);
  left: 0;
  grid-template-columns: repeat(5, 1fr);
  text-align: center;
}

.board-axis-left {
  top: 0;
  right: calc(100% + 9px);
  bottom: 0;
  grid-template-rows: repeat(5, 1fr);
  align-items: center;
}

.ac-board {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  overflow: hidden;
  border: 1px solid var(--ink);
  background: var(--line);
}

.ac-cell {
  position: relative;
  display: grid;
  min-width: 0;
  aspect-ratio: 1;
  place-items: center;
  padding: 0;
  border: 0;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: var(--surface);
  cursor: pointer;
}

.ac-cell:nth-child(5n) {
  border-right: 0;
}

.ac-cell:nth-child(n + 21) {
  border-bottom: 0;
}

.ac-cell.is-empty:not(:disabled):hover {
  background: #efefeb;
}

.ac-cell.is-empty:not(:disabled)::before {
  position: absolute;
  background: currentColor;
  content: "";
  opacity: 0;
}

.ac-cell.is-empty:not(:disabled)::after {
  position: relative;
  color: white;
  content: attr(data-preview);
  font-size: clamp(0.68rem, 2vw, 0.95rem);
  font-weight: 700;
  opacity: 0;
}

.ac-board[data-next-owner="red"] .ac-cell.is-empty:not(:disabled) {
  color: var(--red);
}

.ac-board[data-next-owner="blue"] .ac-cell.is-empty:not(:disabled) {
  color: var(--blue);
}

.ac-board[data-orientation="h"] .ac-cell.is-empty:not(:disabled)::before {
  width: 64%;
  height: 30%;
}

.ac-board[data-orientation="v"] .ac-cell.is-empty:not(:disabled)::before {
  width: 30%;
  height: 64%;
}

.ac-cell.is-empty:not(:disabled):hover::before,
.ac-cell.is-empty:not(:disabled):hover::after {
  opacity: 0.35;
}

.ac-cell.is-target {
  box-shadow: inset 0 0 0 3px var(--ink);
}

.ac-cell.is-visitor {
  box-shadow: inset 0 0 0 2px var(--focus);
}

.ac-piece {
  position: absolute;
  z-index: 2;
  display: grid;
  place-items: center;
  border-radius: 2px;
  color: white;
  pointer-events: none;
}

.ac-piece.owner-red {
  background: var(--red);
}

.ac-piece.owner-blue {
  background: var(--blue);
}

.ac-piece.orientation-h {
  width: 66%;
  height: 32%;
}

.ac-piece.orientation-v {
  width: 32%;
  height: 66%;
}

.ac-piece-label {
  font-size: clamp(0.7rem, 2vw, 1rem);
  font-weight: 700;
}

.decision-trace {
  position: absolute;
  z-index: 3;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}

.decision-trace line {
  stroke: var(--focus);
  stroke-dasharray: 0.06 0.05;
  stroke-width: 0.035;
  vector-effect: non-scaling-stroke;
}

.decision-trace circle {
  fill: var(--focus);
  stroke: white;
  stroke-width: 0.03;
  vector-effect: non-scaling-stroke;
}

.inspector {
  width: min(100%, 560px);
  margin: 18px auto 0;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.inspector h2 {
  margin: 0 0 3px;
  font-size: 0.95rem;
}

.inspector p {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.reference {
  width: min(100%, 560px);
  margin: 28px auto 0;
}

.reference details {
  border-top: 1px solid var(--line);
}

.reference details:last-child {
  border-bottom: 1px solid var(--line);
}

.reference summary {
  display: flex;
  gap: 16px;
  justify-content: space-between;
  padding: 12px 0;
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 600;
  list-style: none;
}

.reference summary::-webkit-details-marker {
  display: none;
}

.reference summary::after {
  color: var(--muted);
  content: "+";
  font-weight: 400;
}

.reference details[open] summary::after {
  content: "−";
}

#ac-ledger-count {
  margin-left: auto;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 400;
}

.rules-copy {
  padding: 0 0 14px;
}

.rules-copy p {
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.ac-ledger {
  display: grid;
  margin: 0;
  padding: 0 0 10px;
  list-style: none;
}

.ac-ledger-item {
  display: grid;
  grid-template-columns: 8px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  border-top: 1px solid #ecece8;
}

.ac-owner-mark {
  width: 7px;
  height: 7px;
  border-radius: 50%;
}

.ac-owner-mark.owner-red {
  background: var(--red);
}

.ac-owner-mark.owner-blue {
  background: var(--blue);
}

.ac-ledger-button {
  min-width: 0;
  padding: 8px 0;
  overflow: hidden;
  border: 0;
  background: none;
  cursor: pointer;
  font-size: 0.76rem;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ac-ledger-button:hover,
.ac-ledger-button.is-selected {
  text-decoration: underline;
}

.ac-ledger-result {
  color: var(--muted);
  font-size: 0.72rem;
}

.ac-empty-ledger {
  padding: 0 0 12px;
  color: var(--muted);
  font-size: 0.82rem;
}

@media (max-width: 560px) {
  #afterclock-game {
    width: min(100% - 28px, 500px);
    padding-top: 22px;
  }

  .app-header {
    gap: 12px;
  }

  .repo-link {
    margin-top: 5px;
  }

  .game-controls {
    flex-wrap: wrap;
    margin-top: 20px;
  }

  .field {
    flex: 1 1 138px;
  }

  .field select {
    width: 100%;
    min-width: 0;
  }

  .quiet-actions {
    flex: 1 0 100%;
    margin-left: 0;
    padding: 2px 0 0;
  }

  .scoreboard {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 15px 0 18px;
  }

  .turn-readout {
    grid-column: 1 / -1;
    grid-row: 1;
    margin-bottom: 6px;
  }

  .score-blue {
    justify-content: flex-end;
  }

  .ac-status {
    font-size: 1rem;
  }

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

  .orientation-control legend {
    grid-column: 1 / -1;
  }

  .orientation-button {
    width: 100%;
    min-width: 0;
  }

  .board-frame {
    width: calc(100% - 20px);
    margin-top: 26px;
    margin-left: 20px;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .orientation-button,
  .ac-cell,
  .text-button {
    transition: border-color 100ms ease, background-color 100ms ease, color 100ms ease;
  }
}
