:root {
  color-scheme: dark;
  --bg: #101217;
  --panel: #171b22;
  --panel-2: #10151c;
  --ink: #f3f0e8;
  --muted: #a8afbb;
  --line: #303845;
  --dark-cell: #202a35;
  --light-cell: #e8e1d0;
  --red: #d13f45;
  --blue: #3d80df;
  --green: #35a46d;
  --gold: #e6b94a;
  --target: #55c581;
  --violet: #8f72d8;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
select,
input {
  font: inherit;
}

button {
  color: var(--ink);
}

.app-shell {
  height: 100vh;
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  overflow: hidden;
  background:
    radial-gradient(circle at 25% 15%, rgba(64, 118, 132, 0.24), transparent 32rem),
    linear-gradient(145deg, #0c1116 0%, #11191f 54%, #0d1218 100%);
}

.board-stage {
  min-width: 0;
  display: grid;
  place-items: center;
  padding: clamp(10px, 2vw, 26px);
}

#board {
  width: min(94vmin, calc(100vw - 332px));
  height: min(94vmin, calc(100vw - 332px));
  max-width: 1040px;
  max-height: 1040px;
  min-width: 320px;
  min-height: 320px;
  display: block;
  cursor: pointer;
  touch-action: manipulation;
}

.side-panel {
  height: 100vh;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  border-left: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(23, 27, 34, 0.96);
  overflow: auto;
}

.topbar,
.dialog-head,
.move-log-panel header,
.seat-row,
.slider-row,
.actions,
.toolbar,
.counts,
.engine-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar {
  justify-content: space-between;
}

.play-summary {
  display: grid;
  gap: 9px;
  padding: 0 0 10px;
  background: rgba(23, 27, 34, 0.96);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 7px;
}

.account-button {
  min-height: 30px;
  max-width: 66px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 8px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #111720;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.7rem;
  font-weight: 800;
}

.account-button span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-button.signed-in {
  border-color: rgba(85, 197, 129, 0.5);
  color: var(--ink);
}

.mode-tabs {
  display: grid;
  grid-template-columns: repeat(3, 42px);
  gap: 6px;
  padding: 1px 0 2px;
}

.mode-tab,
.toolbar button,
.actions button,
.seat,
.dialog-head button {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #111720;
  min-height: 38px;
  cursor: pointer;
}

.mode-tab {
  display: grid;
  place-items: center;
  padding: 0;
  font-size: 1.2rem;
  line-height: 1;
}

.mode-tab.active,
.toolbar button.active,
.actions button:focus-visible,
.mode-tab:focus-visible {
  outline: none;
  border-color: rgba(222, 183, 90, 0.84);
  background: #1d2530;
}

.wasm-badge {
  width: 10px;
  height: 10px;
  padding: 0;
  border: 1px solid rgba(222, 183, 90, 0.45);
  border-radius: 50%;
  background: var(--gold);
  color: transparent;
  overflow: hidden;
  font-size: 0;
  box-shadow: 0 0 10px rgba(230, 185, 74, 0.32);
}

.status,
.inspector,
.move-log-panel,
.control-card,
.panel-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
}

.status {
  min-height: 42px;
  padding: 10px 11px;
  font-size: 0.88rem;
  line-height: 1.35;
}

.slider-row {
  min-height: 34px;
}

.seat-row span,
.move-log-panel header span,
.control-label,
.slider-row span,
.counts span,
.panel-section h2 {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

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

.seat-row > span {
  grid-column: 1 / -1;
}

.seat {
  width: 100%;
  min-height: 34px;
  border-radius: 7px;
  padding: 0 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  line-height: 1;
}

.seat.red {
  background: var(--red);
}

.seat.blue {
  background: var(--blue);
}

.seat.green {
  background: var(--green);
}

.seat.active {
  box-shadow: inset 0 0 0 2px var(--ink), 0 0 16px currentColor;
}

.stack {
  display: grid;
  gap: 8px;
}

.panel-section {
  display: grid;
  gap: 9px;
  padding: 10px;
}

.panel-section h2 {
  margin: 0;
}

.control-card {
  display: grid;
  gap: 8px;
  padding: 0;
  border: 0;
  background: transparent;
}

.online-controls {
  display: grid;
  gap: 10px;
}

.online-controls strong {
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
}

.online-flow {
  display: grid;
  gap: 6px;
}

.online-flow-label {
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
}

.online-controls button,
.invite-join-row input,
.invite-links input {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #111720;
  color: var(--ink);
}

.online-controls button {
  cursor: pointer;
  font-weight: 800;
}

.online-controls button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.invite-join-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
}

.invite-link-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
}

.invite-join-row input,
.invite-links input {
  width: 100%;
  padding: 0 9px;
}

.invite-links {
  display: grid;
  gap: 6px;
}

.handoff-card {
  display: grid;
  gap: 6px;
  padding: 9px;
  border: 1px solid rgba(85, 197, 129, 0.42);
  border-radius: 7px;
  background: rgba(38, 82, 56, 0.18);
}

.handoff-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.35;
}

.invite-link-item {
  display: grid;
  gap: 4px;
}

.invite-link-item label {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
}

select {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #111720;
  color: var(--ink);
  padding: 0 9px;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.segmented button,
.mini-button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.05);
  cursor: pointer;
}

.segmented button {
  display: grid;
  place-items: center;
  gap: 2px;
  padding: 6px 4px;
  color: var(--muted);
  font-size: 0.56rem;
  font-weight: 800;
  line-height: 1;
}

.segmented button.active {
  color: var(--ink);
  background: rgba(67, 135, 232, 0.25);
  border-color: rgba(67, 135, 232, 0.62);
}

.mini-button {
  background: #111720;
}

.play-mode-icon {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.counts {
  justify-content: space-between;
}

.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 4px;
}

.inspector {
  display: grid;
  gap: 7px;
  padding: 9px;
  font-size: 0.78rem;
  color: var(--muted);
}

.inspector[hidden] {
  display: none;
}

.inspector strong {
  color: var(--ink);
}

.toolbar {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.toolbar.online-chess {
  grid-template-columns: repeat(5, 1fr);
}

.toolbar button,
.actions button {
  padding: 0;
  font-weight: 800;
}

.slider-row output {
  width: 42px;
  color: var(--muted);
  font-size: 0.76rem;
  text-align: right;
}

input[type="range"] {
  min-width: 0;
  flex: 1;
  accent-color: var(--gold);
}

.actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.actions.online-chess {
  grid-template-columns: repeat(2, 1fr);
}

.actions .action-button {
  display: grid;
  place-items: center;
  gap: 1px;
  min-height: 42px;
  font-size: 0.7rem;
  line-height: 1;
}

.actions .action-button span:first-child {
  font-size: 1.05rem;
}

.actions button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.move-log-panel {
  min-height: 112px;
  flex: 1 0 112px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.move-log-panel header {
  justify-content: space-between;
  padding: 9px 10px 0;
}

#move-log-toggle {
  display: none;
  min-height: 24px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #111720;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
  cursor: pointer;
}

#move-count {
  color: var(--muted);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
}

#move-log {
  flex: 1;
  overflow-y: scroll;
  scrollbar-gutter: stable;
  scrollbar-color: #596575 #151b23;
  scrollbar-width: thin;
  margin: 0;
  padding: 6px 10px 10px 28px;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.45;
}

#move-log::-webkit-scrollbar {
  width: 9px;
}

#move-log::-webkit-scrollbar-track {
  background: #151b23;
}

#move-log::-webkit-scrollbar-thumb {
  border: 2px solid #151b23;
  border-radius: 999px;
  background: #596575;
}

#move-log li {
  padding: 4px 0;
}

dialog {
  width: min(380px, calc(100vw - 30px));
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--panel);
  box-shadow: 0 20px 70px rgba(0, 0, 0, 0.52);
}

dialog::backdrop {
  background: rgba(4, 6, 9, 0.66);
}

dialog h2 {
  margin: 0;
  font-size: 1rem;
}

.account-dialog {
  width: min(480px, calc(100vw - 30px));
  padding: 0;
}

.account-shell {
  padding: 18px;
}

.account-shell .dialog-head {
  align-items: flex-start;
}

.account-shell .dialog-head p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.4;
}

.account-content,
.account-card,
.account-code-row,
.account-actions,
.account-transfer-result,
.guest-form {
  display: grid;
  gap: 10px;
}

.account-card {
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
}

.account-card h3,
.account-card p {
  margin: 0;
}

.account-card h3 {
  font-size: 0.95rem;
}

.account-card p,
.account-transfer-result p,
.account-note,
.account-error {
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.45;
}

.account-error {
  color: #ff9e9e;
}

.account-success {
  color: #83dca6;
  font-size: 0.8rem;
}

.account-details {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 5px 12px;
  margin: 0;
  font-size: 0.8rem;
}

.account-details dt {
  color: var(--muted);
}

.account-details dd {
  margin: 0;
  text-align: right;
}

.guest-form label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
}

.guest-form input {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #111720;
  color: var(--ink);
  padding: 0 10px;
}

.account-primary,
.account-secondary {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  cursor: pointer;
  font-weight: 800;
}

.account-primary {
  border-color: rgba(230, 185, 74, 0.62);
  background: #292415;
}

.account-secondary {
  background: #111720;
}

.account-primary:disabled,
.account-secondary:disabled {
  cursor: wait;
  opacity: 0.55;
}

.recovery-code {
  padding: 9px;
  overflow-wrap: anywhere;
  border: 1px dashed rgba(230, 185, 74, 0.55);
  border-radius: 7px;
  background: #17150f;
  color: var(--gold);
  font: 0.76rem ui-monospace, SFMono-Regular, Menlo, monospace;
}

.account-code-row {
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
}

.account-code-row .recovery-code {
  min-width: 0;
}

.account-actions {
  justify-items: stretch;
}

.dialog-head {
  justify-content: space-between;
  margin-bottom: 12px;
}

.dialog-head button {
  width: 32px;
  min-height: 32px;
}

.promotion-options {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.promotion-options button {
  min-height: 64px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #111720;
  font-size: 1.6rem;
  cursor: pointer;
}

.history-list {
  display: grid;
  gap: 8px;
  max-height: 320px;
  overflow: auto;
}

.history-row {
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #111720;
  color: var(--muted);
  font-size: 0.82rem;
}

.history-row strong {
  display: block;
  color: var(--ink);
  margin-bottom: 3px;
}

.help-dialog {
  width: min(940px, calc(100vw - 30px));
  height: min(720px, calc(100vh - 30px));
  padding: 0;
}

.help-shell {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 18px;
}

.help-head {
  flex: 0 0 auto;
}

.help-head p,
.help-content header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.45;
}

.help-layout {
  min-height: 0;
  flex: 1;
  display: grid;
  grid-template-columns: 210px minmax(0, 1fr);
  gap: 16px;
}

.help-nav {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding-right: 10px;
  overflow: auto;
  border-right: 1px solid var(--line);
}

.help-nav button {
  min-height: 38px;
  padding: 7px 9px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  text-align: left;
  cursor: pointer;
}

.help-nav button.active {
  border-color: rgba(222, 183, 90, 0.45);
  background: #1d2530;
  color: var(--ink);
}

.help-content {
  min-height: 0;
  overflow: auto;
  padding-right: 4px;
}

.help-content h3 {
  margin: 0;
  font-size: 1.35rem;
}

.help-figure {
  margin: 14px 0 0;
}

.help-figure img {
  display: block;
  width: 100%;
  max-height: 420px;
  object-fit: contain;
  object-position: left center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0b1016;
}

.help-figure.compact img {
  width: auto;
  max-width: min(100%, 360px);
}

.help-figure figcaption {
  margin-top: 7px;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.4;
}

.help-card {
  margin-top: 14px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
}

.help-card h4 {
  margin: 0 0 9px;
  font-size: 0.94rem;
}

.help-card ul {
  margin: 0;
  padding-left: 20px;
  color: #d8dbe0;
  font-size: 0.86rem;
  line-height: 1.5;
}

.help-card li + li {
  margin-top: 7px;
}

.help-dialog[dir="rtl"] .help-nav {
  padding-right: 0;
  padding-left: 10px;
  border-right: 0;
  border-left: 1px solid var(--line);
}

.help-dialog[dir="rtl"] .help-nav button {
  text-align: right;
}

.help-dialog[dir="rtl"] .help-content {
  padding-right: 0;
  padding-left: 4px;
}

.help-dialog[dir="rtl"] .help-card ul {
  padding-right: 20px;
  padding-left: 0;
}

.help-dialog[dir="rtl"] .help-figure img {
  object-position: right center;
}

@media (max-width: 860px) {
  .app-shell {
    height: auto;
    min-height: 100svh;
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) auto;
  }

  #board {
    width: min(96vmin, 100vw - 20px);
    height: min(96vmin, 100vw - 20px);
  }

  .side-panel {
    height: auto;
    min-height: auto;
    max-height: 46svh;
    border-left: 0;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    overflow: auto;
  }

  .play-summary {
    margin: -14px -14px 0;
    padding: 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  }

  .move-log-panel {
    min-height: 130px;
    flex: 0 0 auto;
  }

  .move-log-panel.collapsed {
    min-height: 0;
  }

  .move-log-panel header {
    padding: 10px;
  }

  #move-log-toggle {
    display: inline-flex;
    align-items: center;
  }

  .move-log-panel.collapsed #move-log {
    display: none;
  }

  .move-log-panel.collapsed {
    min-height: 44px;
  }

  .help-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
  }

  .help-nav {
    flex-direction: row;
    padding: 0 0 10px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .help-nav button {
    flex: 0 0 auto;
  }
}
