@font-face {
  font-family: Teko;
  src: url("../fonts/teko-500.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: Teko;
  src: url("../fonts/teko-600.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Source Sans 3";
  src: url("../fonts/source-sans-3-400.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Source Sans 3";
  src: url("../fonts/source-sans-3-600.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Source Sans 3";
  src: url("../fonts/source-sans-3-700.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --shell: #12315c;
  --shell-ink: #f4f7fb;
  --shell-soft: #d6e4f7;
  --lane: #f4f7fb;
  --lane-ink: #142033;
  --lane-soft: #3c4b63;
  --fence: #0e4eab;
  --met: #0b6a3a;
  --over: #a30d3a;
  --buzzer: #c43216;
  --buzzer-ink: #fff8f5;
  --line: #5c6d84;
  --focus: #8a5a00;
  --shadow: rgba(12, 24, 48, 0.16);
  color-scheme: light;
}

:root[data-theme="dark"] {
  --shell: #1b4f8c;
  --shell-ink: #f4f7fb;
  --shell-soft: #d6e4f7;
  --lane: #0e1726;
  --lane-ink: #e7eef8;
  --lane-soft: #c3d0e2;
  --fence: #3d78ea;
  --met: #8fe0b4;
  --over: #ffd6e0;
  --buzzer: #ff5d3c;
  --buzzer-ink: #2a0d08;
  --line: #8ea0b8;
  --focus: #ffc14d;
  --shadow: rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { scroll-behavior: auto; }

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--lane);
  color: var(--lane-ink);
  font-family: "Source Sans 3", sans-serif;
  font-size: 1.0625rem;
  line-height: 1.5;
  font-weight: 400;
}

::selection {
  background: var(--fence);
  color: var(--lane);
}

html {
  scrollbar-color: var(--shell) var(--lane);
}

.skip {
  position: absolute;
  left: 0.75rem;
  top: -4rem;
  z-index: 20;
  background: var(--buzzer);
  color: var(--buzzer-ink);
  padding: 0.55rem 0.8rem;
  font-weight: 700;
  text-decoration: none;
}

.skip:focus {
  top: 0.75rem;
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.shell {
  background: var(--shell);
  color: var(--shell-ink);
  padding: 0.85rem 1rem 1rem;
  box-shadow: 0 8px 20px var(--shadow);
}

.shell-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
}

h1 {
  margin: 0;
  font-family: Teko, sans-serif;
  font-weight: 600;
  font-size: clamp(2.4rem, 8vw, 3.6rem);
  line-height: 0.86;
  letter-spacing: -0.03em;
}

.clock[data-state="idle"] { color: var(--shell-soft); }

.clock {
  margin: 0;
  font-weight: 700;
  font-size: clamp(2rem, 7vw, 3.25rem);
  line-height: 0.9;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
  min-width: 5.5ch;
  text-align: right;
}

.shell-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.7rem 0.85rem;
  margin-top: 0.85rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  color: var(--shell-soft);
  font-size: 0.92rem;
  font-weight: 600;
}

.field select,
.theme {
  font: inherit;
  font-size: 1rem;
  font-weight: 600;
  color: var(--shell-ink);
  background: transparent;
  border: 1px solid var(--shell-soft);
  border-radius: 2px;
  min-height: 2.75rem;
  padding: 0 0.55rem;
  color-scheme: dark;
}

.field select { min-width: 6.5rem; }

.theme {
  margin-left: auto;
  cursor: pointer;
}

.best {
  margin: 0 0 0.45rem;
  color: var(--shell-soft);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.layout {
  width: min(68rem, 100%);
  margin: 0 auto;
  padding: 0.85rem 0.85rem 0.25rem;
  display: grid;
  gap: 0.75rem;
  flex: 1 0 auto;
}

.stage { min-width: 0; width: 100%; }

.board-frame {
  width: 100%;
  padding: 0.65rem;
}

.mesh {
  position: relative;
  width: 100%;
  max-width: calc(100svh - 22rem);
  margin: 0 auto;
  aspect-ratio: 1 / 1;
  touch-action: none;
  --cell: 48px;
}

.cell {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 1;
}

.clue {
  font-weight: 700;
  font-size: calc(var(--cell) * 0.42);
  line-height: 1;
  color: var(--lane-ink);
  font-variant-numeric: tabular-nums;
}

.cell[data-fill="met"] .clue {
  color: var(--met);
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 0.12em;
}

.cell[data-fill="over"] .clue {
  color: var(--over);
  outline: 2px solid var(--over);
  outline-offset: 3px;
  text-decoration: none;
}

.cell[data-fault="short"] .clue {
  color: var(--over);
  text-decoration: underline dashed;
  text-decoration-thickness: 2px;
  text-underline-offset: 0.12em;
}

.edge {
  position: absolute;
  padding: 0;
  border: 0;
  background: transparent;
  z-index: 2;
  touch-action: none;
}

.edge.h { height: 1.75rem; transform: translateY(-50%); }
.edge.v { width: 1.75rem; transform: translateX(-50%); }

.bar {
  position: absolute;
  background: var(--line);
  pointer-events: none;
}

.edge.h .bar {
  left: 6%;
  right: 6%;
  top: 50%;
  height: 2px;
  transform: translateY(-50%);
}

.edge.v .bar {
  top: 6%;
  bottom: 6%;
  left: 50%;
  width: 2px;
  transform: translateX(-50%);
}

.edge[data-state="1"] .bar { background: var(--fence); }

.edge.h[data-state="1"] .bar { height: clamp(3px, calc(var(--cell) * 0.09), 8px); }
.edge.v[data-state="1"] .bar { width: clamp(3px, calc(var(--cell) * 0.09), 8px); }

.edge[data-state="2"] .bar { display: none; }

.cross {
  display: none;
  position: absolute;
  left: 50%;
  top: 50%;
  width: calc(var(--cell) * 0.22);
  height: calc(var(--cell) * 0.22);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.cross::before,
.cross::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 100%;
  height: 2px;
  background: var(--lane-soft);
  border-radius: 1px;
}

.cross::before { transform: translate(-50%, -50%) rotate(45deg); }
.cross::after { transform: translate(-50%, -50%) rotate(-45deg); }

.edge[data-state="2"] .cross { display: block; }

.edge[data-fault="loop"] .bar,
.edge[data-fault="loop"] .cross::before,
.edge[data-fault="loop"] .cross::after {
  outline: 2px solid var(--over);
  outline-offset: 2px;
}

.edge:focus { outline: none; }

.edge:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  z-index: 4;
}

@media (hover: hover) {
  .edge.h[data-state="0"]:hover .bar { height: 3px; background: var(--lane-soft); }
  .edge.v[data-state="0"]:hover .bar { width: 3px; background: var(--lane-soft); }
}

.dot {
  position: absolute;
  width: calc(var(--cell) * 0.14);
  height: calc(var(--cell) * 0.14);
  min-width: 6px;
  min-height: 6px;
  border-radius: 50%;
  background: var(--lane-ink);
  transform: translate(-50%, -50%);
  z-index: 3;
  pointer-events: none;
}

.dot[data-bad="true"] {
  background: var(--over);
  outline: 2px solid var(--over);
  outline-offset: 3px;
}

.mesh.sweep::after {
  content: "";
  position: absolute;
  top: -4%;
  bottom: -4%;
  left: 0;
  width: 22%;
  pointer-events: none;
  z-index: 5;
  background: linear-gradient(90deg, transparent, rgba(255, 214, 140, 0.92), transparent);
  animation: slit 740ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes slit {
  0% { transform: translateX(-50%); opacity: 0; clip-path: inset(0 35% 0 35%); }
  18% { opacity: 1; }
  100% { transform: translateX(480%); opacity: 0; clip-path: inset(0 0 0 0); }
}

.status {
  margin: 0;
  min-height: 1.5rem;
}

.status ul {
  margin: 0;
  padding-left: 1.15rem;
}

.status[data-kind="bad"] { color: var(--over); font-weight: 600; }
.status[data-kind="win"] { color: var(--met); font-weight: 700; font-size: 1.2rem; }

.rules summary {
  font-family: Teko, sans-serif;
  font-weight: 600;
  font-size: 2rem;
  line-height: 0.95;
  letter-spacing: -0.02em;
  cursor: pointer;
  color: var(--lane-ink);
}

.rules summary:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.rules ul {
  margin: 0.35rem 0 0;
  padding-left: 1.15rem;
  max-width: 62ch;
}

.rules li { margin: 0.4rem 0; }

.rules li + li { margin-top: 0.55rem; }

.credit {
  margin: 1.1rem 0 0;
  color: var(--lane-soft);
  max-width: 62ch;
}

.actionbar {
  position: sticky;
  bottom: 0;
  margin-top: auto;
  z-index: 6;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.55rem 0.75rem calc(0.55rem + env(safe-area-inset-bottom));
  background: var(--shell);
  box-shadow: 0 -8px 20px var(--shadow);
}

.text-btn {
  font: inherit;
  font-weight: 600;
  color: var(--shell-ink);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 2px;
  min-height: 2.75rem;
  min-width: 2.75rem;
  padding: 0.35rem 0.7rem;
  cursor: pointer;
}

.text-btn:hover { background: rgba(255, 255, 255, 0.08); }

.text-btn:disabled {
  color: var(--shell-soft);
  cursor: not-allowed;
  background: transparent;
}

.text-btn:focus-visible,
.theme:focus-visible,
.field select:focus-visible,
.skip:focus {
  outline: 3px solid #ffc14d;
  outline-offset: 2px;
}

.buzzer:focus-visible {
  outline: 3px solid #ffc14d;
  outline-offset: 2px;
}

:root[data-theme="dark"] .buzzer:focus-visible {
  outline-color: #1a1208;
}

.buzzer {
  margin-left: auto;
  width: 4.75rem;
  height: 4.75rem;
  border: 0;
  border-radius: 50%;
  background: var(--buzzer);
  color: var(--buzzer-ink);
  font: inherit;
  font-weight: 700;
  letter-spacing: 0;
  cursor: pointer;
  box-shadow: 0 8px 14px rgba(80, 16, 8, 0.28);
}

.buzzer:hover { filter: brightness(1.05); }

.buzzer:active {
  transform: translateY(1px);
  box-shadow: 0 4px 8px rgba(80, 16, 8, 0.24);
}

body.is-solved .buzzer { box-shadow: 0 8px 14px rgba(11, 106, 58, 0.28); }

@media (min-width: 960px) {
  .layout {
    grid-template-columns: minmax(0, 1fr) 22rem;
    grid-template-areas:
      "stage rules"
      "status rules";
    column-gap: 2rem;
    align-items: start;
    padding: 1.25rem 1.5rem 0.5rem;
  }

  .stage { grid-area: stage; }
  .rules {
    grid-area: rules;
    display: flex;
    flex-direction: column;
    max-height: calc(100svh - 18.5rem);
    min-height: 0;
  }

  .rules details {
    overflow: auto;
    min-height: 0;
  }

  .rules li { margin: 0.28rem 0; }
  .status { grid-area: status; }

  .mesh { max-width: min(36rem, calc(100svh - 22rem)); }

}

@media (max-width: 380px) {
  .text-btn { padding-inline: 0.45rem; }
  .shell { padding-inline: 0.75rem; }
}

@media (prefers-reduced-motion: reduce) {
  .mesh.sweep::after { animation: none; display: none; }
  .buzzer:active { transform: none; }
}

noscript p {
  margin: 1rem;
  font-weight: 600;
}
