:root {
  color-scheme: dark;
  --paper: #101513;
  --panel: #1b2421;
  --ink: #f2eadb;
  --muted: #9da89f;
  --line: #3b4842;
  --soft-line: #2b3732;
  --deep: #f3d5a9;
  --deep-soft: #ffe0b8;
  --orange: #ef8354;
  --red: #e05b5b;
  --yellow: #f2c75c;
  --blue: #4776e6;
  --lilac: #a890c2;
  --true-green: #20c85a;
  --magenta: #d879a7;
  --white-color: #f8f1e3;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
}

button, a { font: inherit; }
button { cursor: pointer; }

.app-shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 18px 32px 28px;
}

.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  min-height: 62px;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  width: max-content;
  color: var(--ink);
  font-size: 1.12rem;
  font-weight: 780;
  letter-spacing: 0.01em;
  text-decoration: none;
}

.brand-mark {
  display: inline-flex;
  align-items: end;
  gap: 3px;
  width: 24px;
  height: 22px;
}

.brand-mark i {
  display: block;
  width: 6px;
  border-radius: 5px 5px 2px 2px;
}

.brand-mark i:nth-child(1) { height: 13px; background: var(--orange); }
.brand-mark i:nth-child(2) { height: 20px; background: var(--blue); }
.brand-mark i:nth-child(3) { height: 16px; background: var(--yellow); }

.topbar__date { text-align: center; }
.eyebrow, .panel-kicker, .metric-label {
  display: block;
  color: var(--muted);
  font-size: 0.67rem;
  font-weight: 760;
  letter-spacing: 0.13em;
  line-height: 1.2;
  text-transform: uppercase;
}

.topbar__date strong {
  display: block;
  margin-top: 5px;
  font-size: 0.84rem;
  letter-spacing: 0.01em;
}

.streak-pill {
  display: inline-flex;
  align-items: center;
  justify-self: end;
  gap: 8px;
  color: var(--deep);
  font-size: 0.78rem;
}

.streak-pill__dot, .live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--orange);
  box-shadow: 0 0 0 4px rgba(239, 131, 84, 0.14);
}

.game-layout {
  display: grid;
  grid-template-columns: 175px minmax(560px, 1fr) 175px;
  gap: 24px;
  align-items: start;
  padding-top: 26px;
}

.side-panel { padding-top: 11px; }
.side-panel h1 {
  max-width: 170px;
  margin: 13px 0 13px;
  font-size: clamp(2rem, 3.2vw, 2.8rem);
  line-height: 0.98;
  letter-spacing: 0;
}

.lede {
  max-width: 190px;
  margin: 0;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.55;
}

.score-block {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 22px 0 18px;
}

.score-block > div { border-top: 1px solid var(--line); padding-top: 11px; }
.score-block strong {
  display: block;
  margin-top: 5px;
  font-size: 1.05rem;
  font-weight: 650;
  letter-spacing: 0;
}

.controls { display: flex; align-items: center; gap: 6px; }
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 30px;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 5px 9px;
  font-size: 0.7rem;
  font-weight: 720;
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease, opacity 160ms ease;
}

.button:hover:not(:disabled) { transform: translateY(-1px); }
.button:focus-visible, .text-button:focus-visible, .modal__close:focus-visible, .tube:focus-visible { outline: 3px solid rgba(101, 168, 209, 0.55); outline-offset: 3px; }
.button:disabled { cursor: default; opacity: 0.38; }
.button--dark { color: var(--panel); background: var(--deep); }
.button--dark:hover:not(:disabled) { background: var(--deep-soft); }
.button--quiet { color: var(--ink); background: transparent; border-color: var(--line); }
.button--quiet:hover:not(:disabled) { background: rgba(255, 255, 255, 0.07); }
.button--new { grid-column: auto; }
.board-tools { display: flex; justify-content: flex-end; margin-top: 11px; }
.text-button {
  display: inline-flex;
  gap: 6px;
  margin-top: 28px;
  border: 0;
  padding: 0;
  color: var(--muted);
  background: transparent;
  font-size: 0.75rem;
  font-weight: 700;
}
.text-button:hover { color: var(--ink); }

.board-panel {
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 20px 24px 16px;
}

.board-header, .board-footer, .side-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.board-header h2 {
  margin: 9px 0 0;
  font-size: 1.27rem;
  font-weight: 700;
  letter-spacing: 0;
}

.board-meta { display: flex; align-items: center; gap: 12px; }
.move-badge, .board-id {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  white-space: nowrap;
}
.move-badge { border: 1px solid var(--soft-line); border-radius: 99px; padding: 6px 9px; }
.board-id { font-variant-numeric: tabular-nums; }

.board {
  display: grid;
  grid-template-columns: repeat(5, minmax(58px, 78px));
  justify-content: center;
  gap: 16px 22px;
  min-height: 0;
  padding: 28px 8px 24px;
}

.tube-wrap { display: grid; justify-items: center; gap: 9px; }
.tube-label {
  color: var(--muted);
  font-size: 0.65rem;
  font-weight: 760;
  letter-spacing: 0.08em;
}

.tube {
  position: relative;
  display: flex;
  flex-direction: column-reverse;
  width: 62px;
  height: 232px;
  overflow: hidden;
  border: 2px solid #58645d;
  border-top: 0;
  border-radius: 5px 5px 19px 19px;
  padding: 12px 5px 8px;
  background: #202a26;
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.24), 0 6px 0 -3px var(--panel), 0 7px 0 -2px #58645d;
  transition: transform 180ms ease, border-color 180ms ease, box-shadow 180ms ease;
}

.tube::before {
  content: "";
  position: absolute;
  top: 0;
  left: -2px;
  right: -2px;
  height: 9px;
  border: 2px solid #58645d;
  border-bottom: 0;
  border-radius: 6px 6px 0 0;
  background: var(--panel);
}

.tube:hover { transform: translateY(-3px); border-color: #9aa59c; }
.tube--selected { transform: translateY(-10px); border-color: var(--deep); box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.24), 0 0 0 4px rgba(243, 213, 169, 0.2), 0 10px 0 -3px var(--panel), 0 11px 0 -2px var(--deep); }
.tube--target { border-color: var(--blue); }

.segment {
  width: 100%;
  flex: 0 0 40px;
  min-height: 40px;
  border-top: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 4px 4px 8px 8px;
  box-shadow: inset 0 -7px 9px rgba(0, 0, 0, 0.22), inset 0 5px 8px rgba(255, 255, 255, 0.12);
  animation: settle 180ms ease both;
}
.segment--orange { background: var(--orange); }
.segment--red { background: var(--red); }
.segment--yellow { background: var(--yellow); }
.segment--blue { background: var(--blue); }
.segment--lilac { background: var(--lilac); }
.segment--green { background: var(--white-color); }
.segment--cyan { background: var(--true-green); }
.segment--magenta { background: var(--magenta); }

@keyframes settle { from { transform: translateY(-8px); opacity: 0.6; } to { transform: translateY(0); opacity: 1; } }

.board-footer { border-top: 1px solid var(--soft-line); padding-top: 17px; }
.hint { min-height: 18px; color: var(--muted); font-size: 0.74rem; }
.button--share { color: var(--ink); border-color: var(--line); background: transparent; }
.button--share:hover:not(:disabled) { border-color: var(--deep); background: rgba(255, 255, 255, 0.07); }

.side-panel--right { padding-top: 13px; }
.side-heading { align-items: start; }
.side-heading .live-dot { width: 7px; height: 7px; margin-top: 2px; background: var(--true-green); box-shadow: 0 0 0 4px rgba(32, 200, 90, 0.16); }
.run-card { margin-top: 18px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 3px 0; }
.run-card__row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--soft-line); }
.run-card__row:last-child { border-bottom: 0; }
.run-card__row span { color: var(--muted); font-size: 0.72rem; }
.run-card__row strong { font-size: 0.75rem; font-weight: 730; text-align: right; }
.rule-list { display: grid; gap: 10px; margin-top: 20px; }
.rule { display: grid; grid-template-columns: 25px 1fr; gap: 8px; color: var(--muted); font-size: 0.73rem; line-height: 1.45; }
.rule-number { color: var(--orange); font-size: 0.65rem; font-weight: 800; }
.maker-note { margin-top: 28px; color: var(--deep); font-size: 0.72rem; font-weight: 700; line-height: 1.45; }
.maker-note span { color: var(--muted); font-weight: 500; }

.modal { width: min(430px, calc(100% - 32px)); border: 1px solid var(--line); border-radius: 5px; padding: 30px; color: var(--ink); background: var(--panel); box-shadow: 0 20px 70px rgba(0, 0, 0, 0.42); }
.modal::backdrop { background: rgba(0, 0, 0, 0.62); backdrop-filter: blur(2px); }
.modal__close { position: absolute; top: 14px; right: 15px; border: 0; color: var(--muted); background: transparent; font-size: 1.4rem; line-height: 1; }
.modal h2 { margin: 12px 0; font-size: 1.65rem; letter-spacing: 0; }
.modal p, .modal li { color: var(--muted); font-size: 0.82rem; line-height: 1.6; }
.modal ul { margin: 18px 0; padding-left: 19px; }
.modal__note { border-top: 1px solid var(--soft-line); padding-top: 16px; font-size: 0.73rem !important; }
.toast { position: fixed; bottom: 25px; left: 50%; z-index: 5; transform: translate(-50%, 16px); border-radius: 4px; padding: 10px 14px; color: var(--panel); background: var(--deep); font-size: 0.75rem; opacity: 0; pointer-events: none; transition: opacity 180ms ease, transform 180ms ease; }
.toast--visible { transform: translate(-50%, 0); opacity: 1; }

@media (max-width: 1060px) {
  .app-shell { padding-inline: 20px; }
  .game-layout { grid-template-columns: 160px minmax(500px, 1fr); gap: 20px; }
  .side-panel--right { grid-column: 1 / -1; display: grid; grid-template-columns: 180px 1fr 1fr; gap: 26px; padding: 0; }
  .side-panel--right .run-card { margin-top: 0; }
  .side-panel--right .rule-list { margin-top: 0; }
  .side-panel--right .maker-note { margin-top: 0; align-self: center; }
}

@media (max-width: 720px) {
  .app-shell { padding: 8px 13px 0; }
  .topbar { grid-template-columns: 1fr auto; min-height: 44px; }
  .brand { gap: 8px; font-size: 0.96rem; }
  .brand-mark { width: 21px; height: 19px; }
  .brand-mark i { width: 5px; }
  .topbar__date { display: none; }
  .streak-pill { gap: 6px; font-size: 0.66rem; }
  .streak-pill__dot { width: 6px; height: 6px; box-shadow: 0 0 0 3px rgba(239, 131, 84, 0.14); }
  .game-layout { display: block; padding-top: 10px; }
  .side-panel--left { display: grid; grid-template-columns: 1fr auto; gap: 0 12px; padding: 0 4px 8px; }
  .side-panel--left .panel-kicker, .side-panel--left h1, .side-panel--left .lede { grid-column: 1; }
  .side-panel--left h1 { max-width: none; margin: 4px 0 4px; font-size: 1.7rem; }
  .side-panel--left .lede { max-width: 205px; font-size: 0.67rem; line-height: 1.35; }
  .score-block { grid-column: 2; grid-row: 1 / span 3; display: block; margin: 0; min-width: 79px; }
  .score-block > div { margin-bottom: 7px; padding-top: 8px; }
  .score-block strong { margin-top: 3px; font-size: 0.92rem; }
  .score-block .metric-label { font-size: 0.58rem; }
  .text-button { grid-column: 1 / -1; margin: 8px 0 0; font-size: 0.64rem; }
  .board-panel { min-height: 0; padding: 10px 8px 7px; }
  .board-header { align-items: end; }
  .board-header h2 { margin-top: 5px; font-size: 0.94rem; }
  .board-meta { display: grid; gap: 4px; justify-items: end; }
  .move-badge, .board-id { font-size: 0.62rem; }
  .move-badge { padding: 4px 7px; }
  .board-tools { justify-content: flex-end; margin-top: 8px; }
  .board-tools .controls { flex-wrap: wrap; justify-content: flex-end; }
  .board { grid-template-columns: repeat(4, minmax(42px, 52px)); gap: 8px 6px; min-height: 0; padding: 14px 1px 12px; }
  .tube { width: 48px; height: 128px; padding: 8px 3px 4px; border-radius: 4px 4px 14px 14px; }
  .tube::before { height: 7px; }
  .segment { flex-basis: 21px; min-height: 21px; }
  .tube-wrap { gap: 6px; }
  .tube-label { font-size: 0.58rem; }
  .board-footer { display: grid; gap: 12px; }
  .hint { font-size: 0.66rem; }
  .button--share { width: 100%; }
  .side-panel--right { display: none; }
}

@media (max-width: 390px) {
  .board { gap: 7px 4px; }
  .tube { width: 46px; }
  .segment { flex-basis: 21px; min-height: 21px; }
}
