:root {
  --bg: #f4efe6;
  --panel: #fffaf2;
  --ink: #31261c;
  --muted: #756453;
  --line: #7d6a57;
  --accent: #b36a2e;
  --whiteStone: #f7f7f3;
  --blackStone: #202020;
  --legal: rgba(58, 140, 92, 0.28);
  --selected: rgba(53, 100, 185, 0.28);
  --centre: rgba(230, 194, 120, 0.35);
  --corner: rgba(193, 111, 44, 0.18);
  --lastmove: rgba(201, 62, 62, 0.22);
  --danger: #a33b31;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
}
a {
  color: inherit;
}
.shell {
  min-height: 100vh;
}
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  padding: 16px 20px;
  border-bottom: 1px solid #d8cab7;
  background: rgba(255, 250, 242, 0.96);
  backdrop-filter: blur(8px);
}
.topbar-subtitle {
  margin: 4px 0 0;
}
.view-tabs {
  display: inline-flex;
  gap: 8px;
  padding: 6px;
  border: 1px solid #ddcfbe;
  border-radius: 999px;
  background: rgba(255,255,255,0.7);
}
.view-tab,
.button-secondary {
  appearance: none;
  border: 1px solid #ccb79a;
  background: #fff;
  color: var(--ink);
  border-radius: 999px;
  padding: 10px 14px;
  font-size: 0.95rem;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.view-tab:hover,
.button-secondary:hover,
button:hover {
  background: #faf4ea;
}
.view-tab.is-active {
  background: #efe0cd;
  border-color: #c69d73;
  color: #4f2d11;
}
.button-compact {
  white-space: nowrap;
}
.view-panel[hidden] {
  display: none !important;
}
.app {
  display: grid;
  grid-template-columns: 360px 1fr;
  min-height: calc(100vh - 86px);
}
.sidebar {
  padding: 20px;
  border-right: 1px solid #d8cab7;
  background: linear-gradient(180deg, #fffaf2 0%, #f7efdf 100%);
  overflow: auto;
}
.main {
  min-width: 0;
  display: flex;
  flex-direction: column;
}
h1 { margin: 0; font-size: 1.6rem; }
h2 { margin: 0 0 10px; font-size: 1rem; }
h3 {
  margin: 0 0 10px;
  font-size: 1.2rem;
}
h4 {
  margin: 0 0 8px;
  font-size: 1rem;
}
p, li {
  line-height: 1.55;
}
ul, ol {
  margin: 0;
  padding-left: 1.15rem;
}
.muted { color: var(--muted); }
.eyebrow {
  margin: 0 0 6px;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.card {
  background: var(--panel);
  border: 1px solid #ddcfbe;
  border-radius: 16px;
  padding: 12px 14px;
  margin-top: 12px;
  box-shadow: 0 3px 10px rgba(0,0,0,0.04);
}
.quick-link-card {
  margin-top: 0;
}
.quick-link-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.stat-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 0;
  border-bottom: 1px solid rgba(0,0,0,0.04);
}
.stat-row:last-child { border-bottom: 0; }
.controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
button {
  appearance: none;
  border: 1px solid #ccb79a;
  background: #fff;
  color: var(--ink);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 0.95rem;
  cursor: pointer;
}
button:disabled { opacity: 0.55; cursor: not-allowed; }
.board-wrap {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 18px;
  min-height: 78vh;
}
svg {
  width: min(92vw, 1100px);
  height: auto;
  max-height: 92vh;
  display: block;
}
.log-panel { padding: 0 18px 18px; }
.log {
  background: var(--panel);
  border: 1px solid #ddcfbe;
  border-radius: 16px;
  padding: 10px 12px;
  max-height: 250px;
  overflow: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.88rem;
  white-space: pre-wrap;
  line-height: 1.55;
}
.warning {
  min-height: 1.4em;
  margin: 10px 0 0;
  color: var(--danger);
  font-weight: 600;
}
.small { font-size: 0.92rem; }
.legend-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.legend-item { display: flex; align-items: center; gap: 8px; }
.dot {
  width: 14px;
  height: 14px;
  border-radius: 999px;
  border: 1px solid #746858;
  display: inline-block;
}
.dot.centre { background: var(--centre); }
.dot.corner { background: var(--corner); }
.dot.white { background: var(--whiteStone); }
.dot.black { background: var(--blackStone); }
.dot.legal { background: var(--legal); }
.dot.selected { background: var(--selected); }
.dot.lastmove { background: var(--lastmove); }
.dot.corner-token {
  background: transparent;
  box-shadow: inset 0 0 0 3px rgba(176, 96, 26, 0.88);
}
.dot.setup { background: rgba(126, 167, 131, 0.2); }
.status-guide {
  display: grid;
  gap: 8px;
}
.status-line {
  display: flex;
  align-items: center;
  gap: 8px;
}
.guide-chip {
  width: 20px;
  height: 12px;
  border-radius: 999px;
  display: inline-block;
  border: 1px solid #8f7a64;
}
.guide-chip.token {
  background: linear-gradient(90deg, transparent 0%, transparent 25%, rgba(196, 110, 40, 0.24) 25%, rgba(196, 110, 40, 0.24) 75%, transparent 75%, transparent 100%);
  box-shadow: inset 0 0 0 2px rgba(176, 96, 26, 0.88);
}
.guide-chip.placement { background: rgba(126, 167, 131, 0.2); }
.guide-chip.centre {
  background: radial-gradient(circle, rgba(230, 194, 120, 0.42) 0%, rgba(230, 194, 120, 0.18) 70%, transparent 71%);
}
.stat-row-diagnostics strong {
  font-size: 0.78rem;
  line-height: 1.3;
  white-space: normal;
  text-align: right;
  max-width: 14rem;
}
.log .log-entry {
  display: block;
  padding: 0.2rem 0;
  border-bottom: 1px solid rgba(0,0,0,0.05);
}
.log .log-entry:last-child {
  border-bottom: 0;
}
.log .log-entry.event {
  font-weight: 600;
}
.log .log-entry.metrics {
  color: #5f503f;
}
.log .metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(135px, 1fr));
  gap: 8px 12px;
}
.log .metric {
  display: flex;
  flex-direction: column;
  padding: 6px 8px;
  border-radius: 10px;
  background: rgba(0,0,0,0.03);
}
.log .metric-label {
  font-size: 0.75rem;
  color: var(--muted);
}
.rules-shell {
  padding: 20px;
}
.rules-page {
  max-width: 1200px;
  margin: 0 auto;
}
.rules-header {
  margin-top: 0;
  position: sticky;
  top: 92px;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}
.rules-header h2 {
  margin-bottom: 6px;
  font-size: 1.45rem;
}
.rules-intro {
  margin: 0;
}
.rules-header-actions,
.rules-footer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.rules-layout {
  margin-top: 16px;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}
.rules-nav {
  position: sticky;
  top: 210px;
  margin-top: 0;
}
.anchor-list {
  display: grid;
  gap: 8px;
}
.anchor-list a {
  padding: 8px 10px;
  border-radius: 10px;
  text-decoration: none;
  color: var(--muted);
  background: rgba(0,0,0,0.025);
}
.anchor-list a:hover {
  color: var(--ink);
  background: rgba(179, 106, 46, 0.08);
}
.rules-content {
  min-width: 0;
}
.rules-section {
  padding: 18px 20px;
}
.rules-section:first-child {
  margin-top: 0;
}
.quick-start-card {
  margin-top: 0;
}
.section-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 6px;
}
.quick-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.quick-grid section {
  padding: 14px;
  border-radius: 14px;
  background: rgba(0,0,0,0.025);
  border: 1px solid rgba(125, 106, 87, 0.12);
}
.mini-legend {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.mini-legend-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px;
  border-radius: 14px;
  background: rgba(0,0,0,0.025);
  border: 1px solid rgba(125, 106, 87, 0.12);
}
.mini-legend-item p {
  margin: 4px 0 0;
}
.legend-icon {
  min-width: 44px;
  height: 44px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(179, 106, 46, 0.06);
  border: 1px solid rgba(125, 106, 87, 0.14);
}
.legend-icon .dot {
  width: 18px;
  height: 18px;
}
.symbol-icon {
  font-weight: 700;
  color: #8b5b2a;
  letter-spacing: 0.04em;
}
.future-card {
  border-color: #d5c0a7;
  background: linear-gradient(180deg, #fffaf2 0%, #fbf4ea 100%);
}
.rules-footer-actions {
  margin: 18px 0 28px;
}
@media (max-width: 1100px) {
  .rules-layout {
    grid-template-columns: 1fr;
  }
  .rules-nav,
  .rules-header {
    position: static;
  }
}
@media (max-width: 980px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid #d8cab7; }
  .controls, .legend-list { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .topbar {
    flex-direction: column;
    align-items: stretch;
  }
  .view-tabs {
    width: 100%;
    justify-content: stretch;
  }
  .view-tab,
  .button-secondary {
    flex: 1 1 auto;
  }
  .quick-link-row,
  .rules-header {
    flex-direction: column;
    align-items: stretch;
  }
  .board-wrap {
    padding: 12px;
    min-height: auto;
  }
  .log-panel {
    padding: 0 12px 12px;
  }
  .rules-shell {
    padding: 12px;
  }
  .quick-grid,
  .mini-legend {
    grid-template-columns: 1fr;
  }
  .rules-header-actions,
  .rules-footer-actions {
    flex-direction: column;
  }
  #log {
    max-height: 120px;
    overflow-y: auto;
  }
}

.setting-row {
  display: grid;
  gap: 8px;
}
.setting-row label,
.field-label {
  font-weight: 600;
  font-size: 0.92rem;
}
select,
input,
textarea {
  width: 100%;
  border: 1px solid #ccb79a;
  border-radius: 12px;
  padding: 10px 12px;
  background: #fff;
  color: var(--ink);
  font: inherit;
}
textarea {
  resize: vertical;
}
.feedback-page {
  max-width: 1000px;
}
.feedback-card {
  margin-top: 16px;
}
.feedback-note {
  margin: 0 0 14px;
}
.feedback-form {
  display: grid;
  gap: 16px;
}
.feedback-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}
.feedback-block {
  padding: 14px;
  border-radius: 14px;
  background: rgba(0,0,0,0.025);
  border: 1px solid rgba(125, 106, 87, 0.12);
}
.radio-option {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 0;
}
.radio-option input {
  width: auto;
  margin-top: 3px;
}
.meta-list {
  display: grid;
  gap: 6px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.92rem;
}
.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.field-grid > div {
  display: grid;
  gap: 8px;
}
.field-span {
  grid-column: 1 / -1;
}
.feedback-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.feedback-status {
  margin-top: 0;
}
@media (max-width: 768px) {
  .feedback-grid,
  .field-grid {
    grid-template-columns: 1fr;
  }
  .feedback-actions {
    flex-direction: column;
  }
}
