/* OD-LAYOUT-PRIMITIVES v1 — structure only: display, flex/grid, overflow, wrapping, ratio, geometry.
   Put this @layer first; product CSS outside the layer wins ordinary layout rules.
   Native hidden and closed-dialog states take precedence over component display rules. */
@layer od-layout {
  [hidden]:not([hidden="until-found" i]) { display: none !important; }
  dialog:not([open]) { display: none !important; }

  :where(.od-stack,.od-row,.od-row-top,.od-cluster,.od-grid,.od-field,.od-stat,.od-cell,.od-tile) > :where(*) { min-width: 0; }

  /* containers */
  .od-stack   { display: flex; flex-direction: column; gap: var(--od-gap, 8px); }
  .od-row     { display: flex; align-items: center; gap: var(--od-gap, 8px); }
  .od-row-top { display: flex; align-items: flex-start; gap: var(--od-gap, 8px); }
  .od-cluster { display: flex; flex-wrap: wrap; align-items: center; gap: var(--od-gap, 8px); }
  .od-fill    { flex: 1 1 0; min-width: 0; }
  .od-fixed   { flex: none; }
  .od-grid    { display: grid; gap: var(--od-gap, 12px); grid-template-columns: repeat(var(--od-cols, 3), minmax(0, 1fr)); }

  /* stacked information: each piece is its own line — never sibling inline spans */
  .od-stat, .od-field, .od-cell { display: grid; gap: var(--od-gap, 2px); }
  :where(.od-stat,.od-field,.od-cell) > :where(*) { display: block; }
  .od-tile { display: grid; grid-template-rows: auto 1fr; }
  :where(.od-tile) > :where(*) { display: block; }

  /* media keeps its intrinsic ratio by default; never a distorted or cropped
     cover by accident. height:auto lets the ratio win over an <img height="…">
     attribute. Cropping to a uniform box is an explicit opt-in: set --od-ratio
     AND add .od-media-cover together (per the core rule, only where a crop is
     deliberate — tile thumbs, decorative fills — never on full-frame content). */
  .od-media { display: block; width: 100%; height: auto; aspect-ratio: var(--od-ratio, auto); }
  .od-media-cover { object-fit: cover; }

  /* functional inline SVG icons opt into bounded geometry; content SVGs keep their own */
  .od-icon { display: inline-block; inline-size: var(--od-icon-size, 1em); block-size: var(--od-icon-size, 1em); flex: none; }

  /* data text only — authored copy is rewritten to its budget instead */
  .od-truncate { display: block; max-width: 100%; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  .od-clamp-2, .od-clamp-3 { display: -webkit-box; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
  .od-clamp-2 { -webkit-line-clamp: 2; }
  .od-clamp-3 { -webkit-line-clamp: 3; }
  .od-lines-2 { min-height: calc(2 * 1.4em); }   /* block-level reservation for a shared baseline */
  .od-nowrap  { white-space: nowrap; }           /* 数字+单位 · 价格+起 · 日期+星期 */
  .od-keep    { word-break: keep-all; overflow-wrap: anywhere; } /* CJK labels break at spaces / <wbr> first */

  /* screen skeleton (optional): bars take their own space, the middle scrolls — no padding guessed for chrome */
  .od-screen { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; height: 100%; }
  .od-scroll { overflow-y: auto; overscroll-behavior: contain; min-height: 0; }

  /* horizontal rail: the next item peeks at the edge; trailing room survives overflow */
  .od-rail { display: flex; gap: var(--od-gap, 8px); overflow-x: auto; scroll-snap-type: x proximity; scrollbar-width: none;
             padding-inline: var(--od-rail-pad, 16px); scroll-padding-inline: var(--od-rail-pad, 16px); }
  .od-rail::-webkit-scrollbar { display: none; }
  :where(.od-rail) > :where(*) { flex: none; scroll-snap-align: start; }
  :where(.od-rail) > :where(:last-child) { margin-inline-end: var(--od-rail-pad, 16px); }

  .od-spacer { flex: none; visibility: hidden; pointer-events: none; }
  .od-touch  { min-width: 44px; min-height: 44px; }
}
:root [hidden]:where(:not([hidden="until-found" i])) { display: none; }
/* /OD-LAYOUT-PRIMITIVES v1 */

:root {
  /* Washi & Kaya Design Tokens */
  --bg-desk: #EFE8DC;
  --bg-desk-edge: #E5DCCB;
  --surface: #FAF7F2;
  --surface-elevated: #FFFDF9;
  --surface-hover: #F2EBE0;
  --surface-subtle: #F4EFE6;
  --border: #DDD2C0;
  --border-strong: #C6B79E;

  --ink: #1C1915;
  --ink-secondary: #685D50;
  --ink-subtle: #706558;

  --goban-light: #E2B75B;
  --goban-mid: #DBAE4D;
  --goban-dark: #D39E3A;
  --goban-rim: #8B601B;
  --goban-bevel: #A97723;
  --goban-line: #36250D;

  --accent-amber: #D97706;
  --accent-amber-deep: #9A3412;
  --accent-amber-soft: rgba(217, 119, 6, 0.14);
  --accent-amber-ring: rgba(217, 119, 6, 0.34);

  --five-black: #DC2626;
  --five-black-soft: rgba(220, 38, 38, 0.14);
  --five-white: #0284C7;
  --five-white-soft: rgba(2, 132, 199, 0.14);

  --danger: #B91C1C;
  --danger-bg: rgba(185, 28, 28, 0.08);

  /* Typography */
  --font-display: 'Plus Jakarta Sans', 'Inter', -apple-system, BlinkMacSystemFont, 'SF Pro Display', system-ui, sans-serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'SF Pro Text', system-ui, sans-serif;

  /* Radii & Spacing */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-pill: 999px;

  /* Shadows */
  --shadow-card: 0 4px 16px rgba(45, 31, 14, 0.06), 0 1px 2px rgba(45, 31, 14, 0.04);
  --shadow-card-active: 0 12px 30px rgba(217, 119, 6, 0.16), 0 3px 10px rgba(45, 31, 14, 0.08);
  --shadow-pop: 0 16px 40px rgba(28, 25, 21, 0.14), 0 2px 6px rgba(28, 25, 21, 0.06);
  --shadow-board: 0 22px 46px rgba(54, 37, 13, 0.24), 0 6px 14px rgba(54, 37, 13, 0.14);

  /* Motion */
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --dur-fast: 150ms;
  --dur-med: 240ms;
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  background-color: var(--bg-desk);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

body {
  background-image:
    radial-gradient(ellipse 90% 80% at 50% 48%, rgba(255, 252, 245, 0.52) 0%, rgba(239, 232, 220, 0) 65%),
    radial-gradient(circle at 12% 14%, rgba(211, 158, 58, 0.08) 0%, transparent 45%),
    radial-gradient(circle at 88% 86%, rgba(139, 96, 27, 0.07) 0%, transparent 48%);
  background-attachment: fixed;
}

button {
  font-family: inherit;
  color: inherit;
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--accent-amber);
  outline-offset: 2px;
}

.tabular {
  font-variant-numeric: tabular-nums;
}

/* ==========================================================================
   APP SHELL
   ========================================================================== */
.app-shell {
  display: grid;
  grid-template-rows: 56px auto minmax(0, 1fr);
  height: 100dvh;
  width: 100%;
  overflow: hidden;
}

/* ==========================================================================
   A. TOP COMPACT HUD (56px, floating, no heavy slab)
   ========================================================================== */
.hud {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding-inline: clamp(14px, 2.2vw, 28px);
  height: 56px;
  position: relative;
  z-index: 30;
  user-select: none;
}

.hud-left {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-self: start;
  min-width: 0;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  text-decoration: none;
  color: var(--ink);
}

.brand-mark {
  display: block;
  width: 26px;
  height: 26px;
  flex: none;
}

.brand-title {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.025em;
  color: var(--ink);
  white-space: nowrap;
}

.size-chip {
  display: inline-flex;
  align-items: center;
  height: 26px;
  padding: 0 9px;
  border-radius: var(--radius-pill);
  background: rgba(250, 247, 242, 0.72);
  border: 1px solid var(--border);
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-secondary);
  white-space: nowrap;
  cursor: default;
  transition: border-color var(--dur-fast) var(--ease-out), background-color var(--dur-fast) var(--ease-out);
}

.size-chip:hover {
  background: var(--surface);
  border-color: var(--border-strong);
}

/* Center Status Pill */
.hud-center {
  position: relative;
  justify-self: center;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 36px;
  padding: 0 14px;
  border-radius: var(--radius-pill);
  background: rgba(250, 247, 242, 0.88);
  border: 1px solid var(--border);
  box-shadow: 0 2px 8px rgba(45, 31, 14, 0.05);
  color: var(--ink);
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
  transition: background-color var(--dur-fast) var(--ease-out),
              border-color var(--dur-fast) var(--ease-out),
              box-shadow var(--dur-fast) var(--ease-out),
              transform var(--dur-fast) var(--ease-out);
}

@media (hover: hover) {
  .status-pill:hover {
    background: var(--surface-elevated);
    border-color: var(--border-strong);
    box-shadow: 0 4px 12px rgba(45, 31, 14, 0.09);
  }
}

.status-pill[aria-expanded="true"] {
  background: var(--surface-elevated);
  border-color: var(--accent-amber);
  box-shadow: 0 0 0 3px var(--accent-amber-soft);
}

.status-pill .sep {
  color: var(--border-strong);
}

.status-pill .fives-count-dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: var(--radius-pill);
  background: var(--surface-hover);
  color: var(--ink-secondary);
  font-size: 11.5px;
  font-weight: 700;
}

.status-pill .chevron {
  --od-icon-size: 14px;
  color: var(--ink-secondary);
  transition: transform var(--dur-fast) var(--ease-out);
}

.status-pill[aria-expanded="true"] .chevron {
  transform: rotate(180deg);
}

/* Right Action Icons (exactly 3) */
.hud-right {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-self: end;
  position: relative;
}

.hud-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  background: rgba(250, 247, 242, 0.82);
  border: 1px solid var(--border);
  color: var(--ink);
  position: relative;
  transition: background-color var(--dur-fast) var(--ease-out),
              border-color var(--dur-fast) var(--ease-out),
              box-shadow var(--dur-fast) var(--ease-out),
              opacity var(--dur-fast) var(--ease-out),
              transform var(--dur-fast) var(--ease-out);
}

.hud-icon-btn .od-icon {
  --od-icon-size: 18px;
}

@media (hover: hover) {
  .hud-icon-btn:not(:disabled):hover {
    background: var(--surface-elevated);
    border-color: var(--border-strong);
    box-shadow: 0 3px 10px rgba(45, 31, 14, 0.08);
  }
}

.hud-icon-btn:not(:disabled):active {
  transform: translateY(1px);
}

.hud-icon-btn[aria-expanded="true"] {
  background: var(--surface-elevated);
  border-color: var(--accent-amber);
  box-shadow: 0 0 0 3px var(--accent-amber-soft);
}

.hud-icon-btn:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

/* Subtle CSS Tooltips for Desktop */
@media (hover: hover) {
  [data-tooltip] {
    position: relative;
  }
  [data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    top: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%) translateY(-2px);
    padding: 5px 9px;
    border-radius: 7px;
    background: var(--ink);
    color: var(--surface);
    font-size: 12px;
    font-weight: 500;
    line-height: 1.3;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 140ms var(--ease-out), transform 140ms var(--ease-out);
    z-index: 60;
    box-shadow: 0 6px 16px rgba(28, 25, 21, 0.18);
  }
  [data-tooltip]:hover::after,
  [data-tooltip]:focus-visible::after {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
  .hud-right [data-tooltip]:last-of-type::after {
    left: auto;
    right: 0;
    transform: translateY(-2px);
  }
  .hud-right [data-tooltip]:last-of-type:hover::after,
  .hud-right [data-tooltip]:last-of-type:focus-visible::after {
    transform: translateY(0);
  }
  [data-tooltip][aria-expanded="true"]::after {
    opacity: 0;
  }
}

/* ==========================================================================
   POPOVERS (Fives History & Settings Gear)
   ========================================================================== */
.popover {
  position: absolute;
  top: calc(100% + 10px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-pop);
  z-index: 50;
  animation: popIn 170ms var(--ease-out);
}

@keyframes popIn {
  from { opacity: 0; transform: translateY(-6px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* Fives History Popover */
.fives-popover {
  left: 50%;
  transform: translateX(-50%);
  width: min(340px, calc(100vw - 24px));
  padding: 12px;
  animation-name: popInCenter;
}

@keyframes popInCenter {
  from { opacity: 0; transform: translateX(-50%) translateY(-6px) scale(0.98); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
}

.popover-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 4px 10px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}

.popover-title {
  font-family: var(--font-display);
  font-size: 13.5px;
  font-weight: 700;
  color: var(--ink);
  margin: 0;
}

.popover-sub {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-secondary);
}

.fives-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 260px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.fives-item-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  text-align: left;
  transition: background-color var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out);
}

@media (hover: hover) {
  .fives-item-btn:hover {
    background: var(--surface-hover);
    border-color: var(--border);
  }
}

.fives-item-btn.is-highlighted {
  background: var(--surface-hover);
  border-color: var(--border-strong);
}

.five-swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: none;
}

.five-swatch.black {
  background: var(--five-black);
  box-shadow: 0 0 0 3px var(--five-black-soft);
}

.five-swatch.white {
  background: var(--five-white);
  box-shadow: 0 0 0 3px var(--five-white-soft);
}

.five-meta {
  flex: 1 1 0;
  min-width: 0;
}

.five-label {
  display: block;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink);
}

.five-coords {
  display: block;
  font-size: 12px;
  color: var(--ink-secondary);
}

.five-axis-badge {
  flex: none;
  padding: 2px 7px;
  border-radius: 6px;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-secondary);
}

.fives-empty {
  padding: 18px 12px;
  text-align: center;
  font-size: 13px;
  color: var(--ink-secondary);
  line-height: 1.5;
}

/* Settings Gear Popover */
.settings-popover {
  right: 0;
  width: min(304px, calc(100vw - 24px));
  padding: 8px;
}

.menu-section {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.menu-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 10px;
  border-radius: 10px;
}

.menu-row-label {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 14px;
  font-weight: 500;
  color: var(--ink);
}

.menu-row-label .od-icon {
  --od-icon-size: 16px;
  color: var(--ink-secondary);
}

/* Switch Control */
.switch-btn {
  position: relative;
  width: 42px;
  height: 24px;
  padding: 0;
  border: none;
  border-radius: var(--radius-pill);
  background: #D6CBB9;
  transition: background-color var(--dur-fast) var(--ease-out);
  flex: none;
}

.switch-btn[aria-checked="true"] {
  background: var(--accent-amber);
}

.switch-thumb {
  display: block;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #FFFFFF;
  box-shadow: 0 1px 3px rgba(28, 25, 21, 0.24);
  transform: translateX(3px);
  transition: transform var(--dur-fast) var(--ease-out);
}

.switch-btn[aria-checked="true"] .switch-thumb {
  transform: translateX(21px);
}

/* Segmented Control */
.segmented {
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  padding: 2px;
  border-radius: 9px;
  background: var(--bg-desk);
  border: 1px solid var(--border);
  gap: 2px;
}

.seg-btn {
  padding: 5px 10px;
  border: none;
  border-radius: 7px;
  background: transparent;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-secondary);
  white-space: nowrap;
  transition: background-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out);
}

.seg-btn[aria-pressed="true"] {
  background: var(--surface-elevated);
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(28, 25, 21, 0.08);
}

/* Action Buttons inside Menu */
.menu-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  border: none;
  border-radius: 10px;
  background: transparent;
  font-size: 14px;
  font-weight: 500;
  color: var(--ink);
  text-align: left;
  transition: background-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}

@media (hover: hover) {
  .menu-btn:not(:disabled):hover {
    background: var(--surface-hover);
  }
}

.menu-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.menu-btn-left {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.menu-btn-left .od-icon {
  --od-icon-size: 16px;
  color: var(--ink-secondary);
}

.menu-badge {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--ink-secondary);
  padding: 2px 7px;
  border-radius: 6px;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  white-space: nowrap;
}

.menu-chevron {
  --od-icon-size: 14px;
  color: var(--ink-secondary);
  transition: transform var(--dur-fast) var(--ease-out);
}

.menu-btn[aria-expanded="true"] .menu-chevron {
  transform: rotate(180deg);
}

.demo-submenu {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 4px 6px 6px 28px;
}

.demo-item {
  display: flex;
  flex-direction: column;
  gap: 1px;
  width: 100%;
  padding: 7px 10px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: var(--surface-subtle);
  text-align: left;
  transition: background-color var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out);
}

@media (hover: hover) {
  .demo-item:hover {
    background: var(--surface-hover);
    border-color: var(--border);
  }
}

.demo-item-title {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
}

.demo-item-desc {
  display: block;
  font-size: 11.5px;
  color: var(--ink-secondary);
}

.menu-divider {
  height: 1px;
  background: var(--border);
  margin: 6px 4px;
}

.menu-btn.is-danger {
  color: var(--danger);
}

.menu-btn.is-danger .od-icon {
  color: var(--danger);
}

@media (hover: hover) {
  .menu-btn.is-danger:hover {
    background: var(--danger-bg);
  }
}

.menu-btn.is-confirming {
  background: var(--danger);
  color: #FFFFFF;
}

.menu-btn.is-confirming .od-icon {
  color: #FFFFFF;
}

/* ==========================================================================
   MAIN DUEL ARENA (Left Player | Center Goban | Right Player)
   ========================================================================== */
.arena {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: center;
  gap: 0;
  padding: 4px clamp(10px, 1.8vw, 24px) 14px;
  min-height: 0;
  height: 100%;
  width: 100%;
}

/* Compact Mobile Duel Strip (hidden on Desktop >= 960px) */
/* Compact Duel Bar above board */
.mobile-duel {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
  padding: 4px clamp(12px, 2.2vw, 28px) 6px;
  width: 100%;
  max-width: 1120px;
  margin-inline: auto;
  z-index: 15;
}

.m-player {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 14px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  box-shadow: var(--shadow-card);
  opacity: 0.74;
  min-width: 0;
  transition: opacity var(--dur-med) var(--ease-out), border-color var(--dur-med) var(--ease-out), box-shadow var(--dur-med) var(--ease-out);
}

.m-player.is-white {
  flex-direction: row-reverse;
  text-align: right;
}

.m-player.is-active {
  opacity: 1;
  background: var(--surface-elevated);
  border-color: var(--accent-amber);
  box-shadow: 0 4px 14px rgba(217, 119, 6, 0.18), 0 0 0 3px var(--accent-amber-soft);
}

.m-player img {
  display: block;
  width: 30px;
  height: 30px;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  flex: none;
}

.m-info {
  flex: 1 1 0;
  min-width: 0;
}

.m-name-btn {
  display: block;
  width: 100%;
  padding: 0;
  border: none;
  background: transparent;
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
  text-align: inherit;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.m-stones {
  display: block;
  font-size: 11px;
  color: var(--ink-secondary);
  white-space: nowrap;
}

.m-score {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 800;
  line-height: 1;
  color: var(--ink);
  flex: none;
  padding-inline: 2px;
}

.m-vs {
  font-size: 11px;
  font-weight: 700;
  color: var(--ink-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}


/* ==========================================================================
   B & D. SYMMETRIC PLAYER CARDS (Desktop)
   ========================================================================== */
.player-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 22px 18px 20px;
  border-radius: 20px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  box-shadow: var(--shadow-card);
  opacity: 0.72;
  transform: translateY(0);
  transition: opacity var(--dur-med) var(--ease-out),
              transform var(--dur-med) var(--ease-out),
              border-color var(--dur-med) var(--ease-out),
              box-shadow var(--dur-med) var(--ease-out);
  position: relative;
}

.player-card.is-active {
  opacity: 1;
  background: var(--surface-elevated);
  border-color: var(--accent-amber);
  box-shadow: var(--shadow-card-active), 0 0 0 4px var(--accent-amber-soft);
  transform: translateY(-3px);
}

.turn-slot {
  height: 26px;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.turn-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 26px;
  padding: 0 11px;
  border-radius: var(--radius-pill);
  background: #FEF3C7;
  border: 1px solid rgba(217, 119, 6, 0.35);
  color: #92400E;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.01em;
  white-space: nowrap;
  opacity: 0;
  transform: translateY(3px) scale(0.96);
  transition: opacity var(--dur-med) var(--ease-out), transform var(--dur-med) var(--ease-out);
}

.player-card.is-active .turn-badge {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.turn-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent-amber);
  animation: pulseDot 1.9s ease-in-out infinite;
}

@keyframes pulseDot {
  0%, 100% { transform: scale(1); opacity: 1; }
  50%      { transform: scale(1.32); opacity: 0.65; }
}

.stone-figure {
  width: 78px;
  height: 78px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.stone-figure img {
  display: block;
  width: 78px;
  height: 78px;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
}

.player-name-wrap {
  width: 100%;
  display: flex;
  justify-content: center;
  margin-bottom: 14px;
}

.player-name-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  max-width: 100%;
  padding: 4px 8px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
  transition: background-color var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out);
}

.player-name-text {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 144px;
}

.player-name-btn .edit-hint {
  --od-icon-size: 13px;
  color: var(--ink-secondary);
  opacity: 0;
  transition: opacity var(--dur-fast) var(--ease-out);
}

@media (hover: hover) {
  .player-name-btn:hover {
    background: var(--surface-hover);
    border-color: var(--border);
  }
  .player-name-btn:hover .edit-hint {
    opacity: 1;
  }
}

.player-name-input {
  width: 100%;
  max-width: 164px;
  padding: 4px 8px;
  border: 1.5px solid var(--accent-amber);
  border-radius: 8px;
  background: #FFFFFF;
  font-family: var(--font-display);
  font-size: 15.5px;
  font-weight: 700;
  color: var(--ink);
  text-align: center;
  outline: none;
}

.score-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  margin-bottom: 14px;
}

.score-value {
  display: block;
  font-family: var(--font-display);
  font-size: clamp(46px, 4.4vw, 56px);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.03em;
  color: var(--ink);
}

.score-value.bump {
  animation: scoreBump 320ms var(--ease-out);
}

@keyframes scoreBump {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.18); }
  100% { transform: scale(1); }
}

.score-label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-secondary);
}

.player-divider {
  width: 44px;
  height: 1px;
  background: var(--border);
  margin-bottom: 12px;
}

.stones-meta {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-secondary);
}

.capsule-indicator {
  width: 12px;
  height: 6px;
  border-radius: var(--radius-pill);
  flex: none;
}

.capsule-indicator.black {
  border: 1.8px solid var(--five-black);
  background: var(--five-black-soft);
}

.capsule-indicator.white {
  border: 1.8px solid var(--five-white);
  background: var(--five-white-soft);
}

/* ==========================================================================
   C. CENTRAL GOBAN STAGE (80%+ visual attention)
   ========================================================================== */
.stage-wrap {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 0;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-radius: 22px;
  touch-action: none;
  cursor: grab;
  user-select: none;
}

.stage-wrap.is-dragging {
  cursor: grabbing;
}

.board-transform {
  transform-origin: center center;
  will-change: transform;
  display: flex;
  align-items: center;
  justify-content: center;
}

.board-frame {
  position: relative;
  border-radius: 14px;
  box-shadow:
    0 9px 0 0 var(--goban-bevel),
    0 10px 0 0 var(--goban-rim),
    var(--shadow-board);
  transition: box-shadow var(--dur-med) var(--ease-out);
}

.goban-svg {
  display: block;
  border-radius: 14px;
  overflow: visible;
}

.goban-cell-hit {
  cursor: pointer;
}

.stage-wrap.is-dragging .goban-cell-hit {
  cursor: grabbing;
}

.stone-placed {
  transform-box: fill-box;
  transform-origin: center;
}

.stone-placed.is-new {
  animation: stoneDrop 190ms var(--ease-out);
}

@keyframes stoneDrop {
  from { opacity: 0; transform: scale(1.16); }
  to   { opacity: 1; transform: scale(1); }
}

.five-capsule {
  transition: opacity 180ms var(--ease-out), stroke-width 180ms var(--ease-out);
  pointer-events: none;
}

.five-capsule.is-dimmed {
  opacity: 0.12;
}

.five-capsule.is-focused {
  opacity: 1 !important;
  filter: drop-shadow(0 0 6px rgba(28, 25, 21, 0.22));
}

.five-capsule.is-hidden-rest {
  opacity: 0;
}

/* Floating Zoom Capsule (Bottom-right of stage) */
.zoom-capsule {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 20;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 4px;
  border-radius: var(--radius-pill);
  background: rgba(250, 247, 242, 0.86);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  box-shadow: 0 6px 18px rgba(45, 31, 14, 0.1);
}

.zoom-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: none;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--ink);
  transition: background-color var(--dur-fast) var(--ease-out);
}

.zoom-btn .od-icon {
  --od-icon-size: 15px;
}

@media (hover: hover) {
  .zoom-btn:hover {
    background: var(--surface-hover);
  }
}

.zoom-readout {
  min-width: 48px;
  height: 30px;
  padding: 0 6px;
  border: none;
  border-radius: var(--radius-pill);
  background: transparent;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-secondary);
  text-align: center;
  transition: background-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}

@media (hover: hover) {
  .zoom-readout:hover {
    background: var(--surface-hover);
    color: var(--ink);
  }
}

.zoom-sep {
  width: 1px;
  height: 16px;
  background: var(--border);
  margin-inline: 2px;
}

/* Subtle ephemeral toast (only for auto-expand / demo load feedback) */
.stage-toast {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  padding: 7px 14px;
  border-radius: var(--radius-pill);
  background: rgba(28, 25, 21, 0.88);
  color: var(--surface);
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  pointer-events: none;
  z-index: 25;
  box-shadow: 0 8px 20px rgba(28, 25, 21, 0.2);
  animation: toastIn 200ms var(--ease-out);
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ==========================================================================
   MODALS (Native <dialog>)
   ========================================================================== */
dialog.modal {
  margin: auto;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 28px 70px rgba(28, 25, 21, 0.28);
  max-height: min(88dvh, 820px);
  overflow: hidden;
}

dialog.modal::backdrop {
  background: rgba(28, 25, 21, 0.44);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.modal-rules {
  width: min(820px, calc(100vw - 24px));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.modal-summary {
  width: min(460px, calc(100vw - 24px));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--border);
}

.modal-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 19px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.modal-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-elevated);
  color: var(--ink-secondary);
  transition: background-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}

.modal-close .od-icon {
  --od-icon-size: 16px;
}

@media (hover: hover) {
  .modal-close:hover {
    background: var(--surface-hover);
    color: var(--ink);
  }
}

.modal-body {
  padding: 20px 22px 24px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* Rules Cards */
.rules-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 22px;
}

.rule-card {
  padding: 14px 16px;
  border-radius: 14px;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
}

.rule-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 7px;
  background: var(--bg-desk);
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 8px;
}

.rule-card h3 {
  margin: 0 0 4px;
  font-family: var(--font-display);
  font-size: 14.5px;
  font-weight: 700;
  color: var(--ink);
}

.rule-card p {
  margin: 0;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--ink-secondary);
}

/* Rules Visual Diagrams Gallery (5 schemes) */
.diagrams-heading {
  margin: 0 0 12px;
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 700;
  color: var(--ink-secondary);
}

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

.diagram-card {
  display: flex;
  flex-direction: column;
  border-radius: 14px;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  overflow: hidden;
}

.diagram-figure {
  padding: 12px;
  background: var(--bg-desk);
  display: flex;
  align-items: center;
  justify-content: center;
}

.diagram-svg {
  display: block;
  width: 100%;
  max-width: 168px;
  height: auto;
}

.diagram-caption {
  padding: 10px 12px 12px;
}

.diagram-caption strong {
  display: block;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 2px;
}

.diagram-caption span {
  display: block;
  font-size: 12px;
  line-height: 1.4;
  color: var(--ink-secondary);
}

/* Summary Modal Content */
.summary-hero {
  text-align: center;
  margin-bottom: 18px;
}

.summary-kicker {
  display: inline-block;
  padding: 4px 11px;
  border-radius: var(--radius-pill);
  background: #FEF3C7;
  border: 1px solid rgba(217, 119, 6, 0.32);
  color: #92400E;
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 8px;
}

.summary-headline {
  margin: 0 0 4px;
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.025em;
  color: var(--ink);
}

.summary-sub {
  margin: 0;
  font-size: 13.5px;
  color: var(--ink-secondary);
}

.summary-duel {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 16px;
  border-radius: 16px;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  margin-bottom: 20px;
}

.summary-side {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 6px;
  padding: 10px 8px;
  border-radius: 12px;
}

.summary-side.is-winner {
  background: rgba(217, 119, 6, 0.08);
  box-shadow: inset 0 0 0 1.5px rgba(217, 119, 6, 0.36);
}

.summary-side img {
  display: block;
  width: 48px;
  height: 48px;
  aspect-ratio: 1 / 1;
  object-fit: contain;
}

.summary-name {
  display: block;
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
  max-width: 130px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.summary-score {
  display: block;
  font-family: var(--font-display);
  font-size: 36px;
  font-weight: 800;
  line-height: 1;
  color: var(--ink);
}

.summary-stones {
  display: block;
  font-size: 12px;
  color: var(--ink-secondary);
}

.summary-vs {
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.summary-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 42px;
  padding: 0 16px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  transition: background-color var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out), transform var(--dur-fast) var(--ease-out);
}

.btn:active {
  transform: translateY(1px);
}

.btn-secondary {
  background: var(--surface-elevated);
  border: 1px solid var(--border-strong);
  color: var(--ink);
}

@media (hover: hover) {
  .btn-secondary:hover {
    background: var(--surface-hover);
  }
}

.btn-primary {
  background: var(--ink);
  border: 1px solid var(--ink);
  color: #FAF7F2;
}

@media (hover: hover) {
  .btn-primary:hover {
    background: #2E2923;
  }
}

/* ==========================================================================
   RESPONSIVE: TABLET & MOBILE (< 960px, down to 375px)
   ========================================================================== */
@media (max-width: 959px) {
  .app-shell {
    grid-template-rows: 54px auto minmax(0, 1fr);
  }

  .hud {
    height: 54px;
    padding-inline: 12px;
  }

  .brand-title {
    font-size: 16px;
  }

  .size-chip {
    display: none;
  }

  .status-pill {
    height: 34px;
    padding: 0 11px;
    font-size: 12.5px;
    gap: 6px;
  }

  .hud-icon-btn {
    width: 36px;
    height: 36px;
  }

  .arena {
    grid-template-columns: minmax(0, 1fr);
    padding: 4px 10px 12px;
    gap: 0;
  }

  .player-card {
    display: none;
  }

  .zoom-capsule {
    right: 8px;
    bottom: 8px;
  }

  .rules-grid {
    grid-template-columns: 1fr;
  }

  .diagrams-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 480px) {
  .brand-mark {
    width: 22px;
    height: 22px;
  }

  .brand-title {
    font-size: 15px;
  }

  .status-pill .move-prefix {
    display: none;
  }

  .hud-right {
    gap: 5px;
  }

  .diagrams-grid {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Canvas board + real rule screenshots */
#boardCanvas { width: 100%; height: 100%; display: block; touch-action: none; }
.diagram-figure img { display: block; width: 100%; height: auto; border-radius: 8px; object-fit: contain; }

.player-card { display: none !important; }
