:root {
  --achi-panel: var(--site-surface);
  --achi-panel-alt: var(--site-surface-strong);
  --achi-panel-soft: var(--site-surface-alt);
  --achi-border: var(--site-border);
  --achi-border-strong: var(--site-border-strong);
  --achi-text: var(--site-text);
  --achi-muted: var(--site-text-muted);
  --achi-accent: var(--site-accent);
  --achi-accent-soft: var(--site-accent-soft);
  --achi-accent-strong: var(--site-accent-strong);
  --achi-white: #edf3ee;
  --achi-black: #1c2622;
}

body.achi-page {
  color: var(--achi-text);
}

.achi-shell {
  margin-top: 0.5rem;
  border: 1px solid var(--achi-border);
  border-radius: var(--site-radius-xl);
  background: rgba(19, 25, 22, 0.82);
  color: var(--achi-text);
  box-shadow: none;
  overflow: hidden;
}

.achi-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--achi-border);
  background: transparent;
}

.achi-header h2 {
  margin: 0;
  font-size: 1.02rem;
  letter-spacing: 0.02em;
}

.achi-subtitle {
  margin: 0;
  color: var(--achi-muted);
  font-size: 0.85rem;
}

.achi-role-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.6rem;
  padding: 0.8rem 1rem 0;
}

.achi-role {
  border: 1px solid var(--achi-border);
  border-radius: var(--site-radius-md);
  background: rgba(23, 31, 27, 0.48);
  padding: 0.55rem 0.65rem;
  text-align: left;
}

.achi-role-white {
  box-shadow: inset 0 0 0 1px rgba(237, 243, 238, 0.12);
}

.achi-role-black {
  box-shadow: inset 0 0 0 1px rgba(28, 38, 34, 0.44);
}

.achi-shell[data-active-turn='WHITE'] .achi-role-white,
.achi-shell[data-active-turn='BLACK'] .achi-role-black,
.achi-shell[data-active-phase='PLACEMENT'] .achi-role-objective {
  border-color: var(--achi-accent);
  box-shadow: 0 0 0 1px rgba(169, 196, 178, 0.18);
}

.achi-role-title {
  margin: 0;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--achi-muted);
}

.achi-role-text {
  margin: 0.3rem 0 0;
  color: var(--achi-text);
  font-size: 0.82rem;
}

.achi-progress-wrap {
  margin-top: 0.35rem;
  height: 7px;
  border-radius: 999px;
  background: var(--site-bg-soft);
  border: 1px solid var(--achi-border);
  overflow: hidden;
}

.achi-progress {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, rgba(169, 196, 178, 0.85), var(--achi-accent));
  transition: width 180ms ease;
}

.achi-win-banner {
  margin: 0.75rem 1rem 0;
  padding: 0.55rem 0.8rem;
  border-radius: var(--site-radius-md);
  border: 1px solid rgba(169, 196, 178, 0.2);
  border-left-width: 3px;
  background: rgba(169, 196, 178, 0.08);
  color: var(--achi-text);
  font-weight: 650;
}

.achi-main {
  display: grid;
  grid-template-columns: minmax(0, 1.14fr) minmax(285px, 328px);
  gap: 1rem;
  align-items: start;
  padding: 0.8rem 1rem 1rem;
}

.achi-board-wrap {
  display: grid;
  gap: 0.9rem;
  background: transparent;
  border: 0;
  border-radius: 0;
  padding: 0;
}

.achi-board {
  --achi-node-size: clamp(42px, 7vw, 64px);
  position: relative;
  aspect-ratio: 1 / 1;
  width: min(100%, 470px);
  margin: 0 auto;
  background:
    radial-gradient(circle at 50% 24%, rgba(169, 196, 178, 0.08), transparent 32%),
    rgba(24, 32, 28, 0.92);
  border-radius: 12px;
  border: 1px solid var(--achi-border);
  overflow: hidden;
}

.achi-lines,
.achi-win-line {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.achi-lines {
  z-index: 0;
}

.achi-line,
.achi-win-line {
  position: absolute;
  transform-origin: 0 0;
}

.achi-line {
  height: 2px;
  background: rgba(169, 196, 178, 0.28);
  opacity: 0.82;
}

.achi-win-line {
  height: 4px;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(202, 218, 207, 0.96), rgba(169, 196, 178, 0.92));
  box-shadow: 0 0 0 1px rgba(16, 21, 18, 0.18);
  z-index: 1;
}

.achi-node {
  position: absolute;
  width: var(--achi-node-size);
  height: var(--achi-node-size);
  margin-left: calc(var(--achi-node-size) * -0.5);
  margin-top: calc(var(--achi-node-size) * -0.5);
  border-radius: 999px;
  border: 2px solid rgba(169, 196, 178, 0.18);
  background: rgba(24, 32, 28, 0.96);
  box-shadow: none;
  cursor: pointer;
  z-index: 2;
  transition: transform 130ms ease, box-shadow 130ms ease, border-color 130ms ease, background-color 130ms ease;
}

.achi-node::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(169, 196, 178, 0.58);
  transform: translate(-50%, -50%);
}

.achi-node.is-white::before,
.achi-node.is-black::before {
  display: none;
}

.achi-node:hover,
.achi-node:focus-visible {
  transform: translateY(-1px);
  border-color: var(--achi-accent);
  box-shadow: 0 0 0 2px var(--achi-accent-soft);
  outline: none;
}

.achi-node.is-source {
  border-color: rgba(202, 218, 207, 0.76);
  box-shadow: 0 0 0 2px rgba(202, 218, 207, 0.16);
}

.achi-node.is-selected {
  border-color: var(--achi-accent);
  box-shadow: 0 0 0 2px rgba(169, 196, 178, 0.16);
}

.achi-node.is-legal::after {
  content: '';
  position: absolute;
  inset: 10px;
  border-radius: 50%;
  background: rgba(184, 214, 156, 0.54);
}

.achi-node.is-winning {
  border-color: rgba(202, 218, 207, 0.9);
  box-shadow: 0 0 0 2px rgba(202, 218, 207, 0.16);
}

.piece {
  position: absolute;
  inset: 5px;
  border-radius: 50%;
  z-index: 3;
}

.piece.white {
  background: radial-gradient(circle at 32% 28%, #ffffff 0%, #edf3ee 48%, #b9c6bc 100%);
  box-shadow: inset 0 -3px 7px rgba(98, 108, 101, 0.2);
}

.piece.black {
  background: radial-gradient(circle at 32% 28%, #536057 0%, #27322d 50%, #111714 100%);
  box-shadow: inset 0 -3px 8px rgba(0, 0, 0, 0.34);
}

.achi-side {
  display: grid;
  gap: 0.95rem;
  align-content: start;
}

.achi-card {
  background: transparent;
  border: 0;
  border-top: 1px solid rgba(238, 243, 239, 0.08);
  border-radius: 0;
  padding: 0.95rem 0 0;
}

.achi-side > :first-child {
  border-top: 0;
  padding-top: 0;
}

.achi-grid2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem;
}

.achi-setup-grid {
  grid-template-columns: 1fr;
}

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

.achi-field {
  display: grid;
  gap: 0.32rem;
  text-align: left;
}

.achi-field-stack {
  margin-top: 0.55rem;
}

.achi-field label,
.achi-label {
  font-size: 0.76rem;
  color: var(--achi-muted);
  margin: 0;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.achi-select,
.achi-button {
  font: inherit;
  color: var(--achi-text);
  background: rgba(23, 31, 27, 0.72);
  border: 1px solid var(--achi-border);
  border-radius: var(--site-radius-md);
  padding: 0.5rem 0.72rem;
  width: 100%;
  min-width: 0;
}

.achi-button {
  cursor: pointer;
}

.achi-button:hover,
.achi-button:focus-visible,
.achi-select:focus-visible,
.achi-tab:focus-visible {
  border-color: var(--achi-accent);
  box-shadow: 0 0 0 2px var(--achi-accent-soft);
  outline: none;
}

.achi-button[disabled],
.achi-select[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}

.achi-stat {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.9rem;
  border-bottom: 1px solid rgba(238, 243, 239, 0.06);
  padding: 0.34rem 0;
  font-size: 0.86rem;
  line-height: 1.35;
}

.achi-stat:last-of-type {
  border-bottom: 0;
}

.achi-status {
  margin: 0.35rem 0 0;
  color: var(--achi-text);
  font-size: 0.86rem;
}

.achi-thinking {
  margin: 0.32rem 0 0;
  font-size: 0.83rem;
  color: var(--achi-muted);
}

.achi-status-note {
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid rgba(238, 243, 239, 0.06);
  color: var(--achi-muted);
  font-size: 0.8rem;
  line-height: 1.45;
}

.achi-history {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 180px;
  overflow: auto;
  display: grid;
  gap: 0;
}

.achi-history-item {
  font-size: 0.82rem;
  color: var(--achi-text);
  border-top: 1px solid rgba(238, 243, 239, 0.06);
  padding: 0.42rem 0;
}

.achi-empty-history {
  color: var(--achi-muted);
  font-size: 0.82rem;
}

.achi-tabs {
  margin-top: 0.1rem;
}

.achi-tab-list {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin: 0;
  padding: 0 0 0.2rem;
  list-style: none;
  border-bottom: 1px solid var(--achi-border);
}

.achi-tab {
  border: 0;
  background: transparent;
  color: var(--achi-muted);
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: 0 0 0.7rem;
  cursor: pointer;
  font-size: 0.79rem;
  letter-spacing: 0.03em;
}

.achi-tab[aria-selected='true'] {
  color: var(--achi-text);
  border-bottom-color: var(--achi-accent);
}

.achi-tab-panel {
  margin-top: 0.58rem;
  background: transparent;
  border: 0;
  border-radius: 0;
  padding: 0;
  color: var(--achi-text);
  font-size: 0.89rem;
}

.achi-tab-panel[hidden] {
  display: none;
}

.achi-tab-panel p,
.achi-tab-panel ul,
.achi-tab-panel ol {
  margin: 0.3rem 0;
}

.achi-tab-panel ul,
.achi-tab-panel ol {
  padding-left: 1.1rem;
}

@media (prefers-reduced-motion: reduce) {
  .achi-node,
  .achi-button,
  .achi-select,
  .achi-progress {
    transition: none;
  }
}

@media (max-width: 1024px) {
  .achi-main {
    grid-template-columns: 1fr;
  }

  .achi-board {
    width: min(100%, 450px);
  }

  .achi-history {
    max-height: 180px;
  }
}

@media (max-width: 780px) {
  .achi-header {
    flex-direction: column;
    align-items: flex-start;
    padding: 0.72rem 0.75rem;
  }

  .achi-role-strip {
    padding: 0.6rem 0.85rem 0;
    grid-template-columns: 1fr;
  }

  .achi-main {
    gap: 0.65rem;
    padding: 0.7rem 0.8rem 0.85rem;
  }

  .achi-grid2 {
    grid-template-columns: 1fr;
  }

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

  .achi-board {
    --achi-node-size: clamp(36px, 12vw, 52px);
    width: 100%;
  }
}
