:root {
  color-scheme: light;
  --ink: #171717;
  --muted: #6f6b63;
  --line: #d8d1c5;
  --panel: #fbfaf7;
  --paper: #fffdf8;
  --accent: #0f766e;
  --accent-strong: #115e59;
  --warn: #b45309;
  --danger: #b91c1c;
  --ok: #166534;
  --shadow: 0 18px 45px rgba(23, 23, 23, 0.12);
}

* {
  box-sizing: border-box;
}

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

body {
  background: #efebe4;
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.topbar {
  align-items: center;
  background: #1f1d1a;
  color: #fffaf0;
  display: flex;
  justify-content: space-between;
  min-height: 58px;
  padding: 0 24px;
}

.brand {
  align-items: center;
  display: flex;
  font-size: 20px;
  font-weight: 800;
  gap: 10px;
}

.yinmark {
  background:
    radial-gradient(circle at 50% 25%, #fff 0 8%, transparent 9%),
    radial-gradient(circle at 50% 75%, #111 0 8%, transparent 9%),
    linear-gradient(90deg, #111 0 50%, #fff 50% 100%);
  border: 1px solid #fff;
  border-radius: 50%;
  display: inline-block;
  height: 30px;
  position: relative;
  width: 30px;
}

.yinmark::before,
.yinmark::after {
  border-radius: 50%;
  content: "";
  height: 15px;
  left: 7px;
  position: absolute;
  width: 15px;
}

.yinmark::before {
  background: #111;
  top: 0;
}

.yinmark::after {
  background: #fff;
  bottom: 0;
}

.authbar {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.app-shell,
.page-shell {
  display: grid;
  gap: 22px;
  padding: 22px;
}

.app-shell {
  grid-template-columns: minmax(260px, 330px) minmax(0, 1fr);
  min-height: calc(100vh - 58px);
}

.page-shell {
  grid-template-columns: minmax(0, 1fr);
}

.page-shell.narrow {
  justify-content: center;
}

.page-panel {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.sidebar,
.play-area {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.sidebar {
  align-self: start;
  display: flex;
  flex-direction: column;
  gap: 18px;
  max-height: calc(100vh - 102px);
  overflow: auto;
  padding: 16px;
}

.play-area {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
  padding: 18px;
}

.page-shell .sidebar,
.admin-page {
  margin: 0 auto;
  max-width: 960px;
  width: min(100%, 960px);
}

.page-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-right: 8px;
}

.nav-link,
.page-link-button {
  align-items: center;
  text-decoration: none;
}

.nav-link {
  border: 1px solid rgba(255, 250, 240, 0.18);
  border-radius: 999px;
  color: #fffaf0;
  display: inline-flex;
  font-size: 13px;
  min-height: 34px;
  padding: 0 12px;
}

.nav-link.active {
  background: rgba(255, 250, 240, 0.14);
  border-color: rgba(255, 250, 240, 0.3);
}

.page-link-button {
  display: inline-flex;
}

.section-head,
.board-toolbar,
.action-row {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
}

h1,
h2,
p {
  margin: 0;
}

h1,
h2 {
  line-height: 1.15;
}

h1 {
  font-size: 18px;
}

h2 {
  font-size: 20px;
}

.section-copy {
  color: var(--muted);
  font-size: 14px;
  margin-top: 5px;
}

#puzzleMeta {
  color: var(--muted);
  font-size: 14px;
  margin-top: 5px;
}

.puzzle-list {
  display: grid;
  gap: 8px;
}

.puzzle-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  display: grid;
  gap: 6px;
  padding: 11px 12px;
  text-align: left;
  width: 100%;
}

.puzzle-card.active {
  border-color: var(--accent);
  box-shadow: inset 4px 0 0 var(--accent);
}

.puzzle-card strong {
  font-size: 15px;
}

.puzzle-card span {
  color: var(--muted);
  font-size: 13px;
}

.puzzle-card .solved {
  color: var(--ok);
  font-weight: 800;
}

.admin-panel {
  display: grid;
  gap: 12px;
}

.admin-page {
  padding: 18px;
}

.section-head.compact {
  margin-top: 4px;
}

.button-grid {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.button-grid .secondary-button {
  padding: 0 8px;
}

.admin-tabs {
  background: #ebe4d8;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 4px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  padding: 4px;
}

.admin-list {
  display: grid;
  gap: 8px;
}

.admin-row {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 8px;
  padding: 10px;
}

.admin-row strong {
  font-size: 14px;
}

.admin-row span {
  color: var(--muted);
  font-size: 12px;
}

.task-log {
  background: #f7f3ea;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  display: grid;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  gap: 4px;
  max-height: 220px;
  overflow: auto;
  padding: 8px;
  white-space: pre-wrap;
}

.admin-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.admin-actions button,
.admin-actions select,
.admin-actions input {
  min-height: 32px;
}

label {
  color: var(--muted);
  display: grid;
  font-size: 13px;
  gap: 5px;
}

input,
select {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  min-height: 38px;
  padding: 0 10px;
}

.board-wrap {
  display: grid;
  justify-items: center;
  min-height: 0;
}

.board-stage {
  display: grid;
  max-height: min(68vh, 720px);
  max-width: min(100%, 720px);
  position: relative;
  width: min(100%, 68vh);
}

.board {
  aspect-ratio: 1;
  background: #a97943;
  border: 2px solid #24211d;
  display: grid;
  gap: 1px;
  transition:
    filter 160ms ease,
    transform 160ms ease;
  width: 100%;
}

.board-stage.paused .board {
  filter: blur(5px) brightness(0.82) saturate(0.9);
  transform: scale(1.012);
}

.cell {
  align-items: center;
  background: #d6a15d;
  border: 0;
  color: transparent;
  display: flex;
  justify-content: center;
  min-height: 0;
  padding: 0;
  position: relative;
  touch-action: none;
  user-select: none;
  transition:
    background 120ms ease,
    box-shadow 120ms ease,
    transform 120ms ease;
}

.cell:hover:not(:disabled) {
  box-shadow: inset 0 0 0 2px rgba(15, 118, 110, 0.5);
}

.cell:focus-visible {
  outline: 3px solid #f59e0b;
  outline-offset: -3px;
}

.cell::before {
  border-radius: 50%;
  content: "";
  height: 78%;
  position: absolute;
  transform: scale(0);
  transition: transform 120ms ease;
  width: 18%;
}

.cell.black::before,
.cell.white::before {
  transform: scale(1);
  width: 78%;
}

.cell.black::before {
  background:
    radial-gradient(circle at 32% 28%, rgba(255, 255, 255, 0.18), transparent 28%),
    #111;
  box-shadow: inset -0.08em -0.1em 0.2em rgba(255, 255, 255, 0.1), 0 1px 2px rgba(0, 0, 0, 0.35);
}

.cell.white::before {
  background:
    radial-gradient(circle at 34% 28%, rgba(255, 255, 255, 0.95), transparent 28%),
    #f8f4e9;
  box-shadow: inset -0.08em -0.1em 0.18em rgba(0, 0, 0, 0.18), 0 1px 2px rgba(0, 0, 0, 0.25);
}

.cell.given::after {
  border: 2px solid #0f766e;
  border-radius: 50%;
  content: "";
  height: 24%;
  position: absolute;
  width: 24%;
}

.cell:disabled {
  cursor: not-allowed;
}

.board-overlay {
  align-items: center;
  background: rgba(31, 29, 26, 0.72);
  border: 0;
  color: #fffaf0;
  display: none;
  font-size: 22px;
  font-weight: 800;
  inset: 0;
  justify-content: center;
  position: absolute;
  text-align: center;
}

.board-overlay.visible {
  display: flex;
}

.timer-panel {
  align-items: center;
  display: flex;
  gap: 10px;
}

#timerText {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  min-width: 78px;
  padding: 8px 10px;
  text-align: center;
}

.icon-button {
  align-items: center;
  border: 1px solid transparent;
  border-radius: 6px;
  display: inline-flex;
  justify-content: center;
}

.icon-button {
  background: #fff;
  border-color: var(--line);
  color: var(--ink);
  height: 34px;
  min-width: 34px;
  padding: 0 9px;
}

.primary-button,
.secondary-button,
.text-button {
  border-radius: 6px;
  min-height: 38px;
  padding: 0 13px;
}

.primary-button {
  background: var(--accent);
  border: 1px solid var(--accent-strong);
  color: #fff;
  font-weight: 700;
}

.secondary-button,
.text-button {
  background: #fff;
  border: 1px solid var(--line);
  color: var(--ink);
}

.status {
  color: var(--muted);
  flex: 1;
  font-size: 14px;
  min-width: 0;
}

.status.ok {
  color: var(--ok);
}

.status.warn {
  color: var(--warn);
}

.status.error {
  color: var(--danger);
}

.rules {
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 14px;
  padding-top: 14px;
}

.rules summary {
  color: var(--ink);
  cursor: pointer;
  font-weight: 700;
}

.rules ol {
  margin: 10px 0 0;
  padding-left: 22px;
}

.auth-dialog {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  color: var(--ink);
  max-width: 380px;
  padding: 18px;
  width: calc(100vw - 32px);
}

.auth-dialog::backdrop {
  background: rgba(31, 29, 26, 0.44);
}

.dialog-close {
  display: flex;
  justify-content: flex-end;
  margin: 0 0 10px;
}

.auth-tabs {
  background: #ebe4d8;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 4px;
  grid-template-columns: 1fr 1fr;
  margin-bottom: 14px;
  padding: 4px;
}

.tab {
  background: transparent;
  border: 0;
  border-radius: 6px;
  min-height: 36px;
}

.tab.active {
  background: #fff;
  color: var(--accent-strong);
  font-weight: 800;
}

.auth-form {
  display: grid;
  gap: 12px;
}

.form-message {
  color: var(--danger);
  font-size: 13px;
  min-height: 18px;
}

.badge {
  background: #fef3c7;
  border: 1px solid #f59e0b;
  border-radius: 999px;
  color: #7c2d12;
  font-size: 12px;
  font-weight: 800;
  padding: 3px 8px;
}

.hidden {
  display: none;
}

@media (max-width: 860px) {
  .app-shell,
  .page-shell {
    grid-template-columns: 1fr;
    padding: 14px;
  }

  .sidebar {
    max-height: none;
  }

  .authbar {
    justify-content: flex-start;
  }

  .board-toolbar,
  .action-row {
    align-items: flex-start;
    flex-direction: column;
  }

  .status {
    width: 100%;
  }

  .board {
    width: 100%;
  }

  .board-stage {
    width: min(100%, 82vh);
  }
}
