:root {
  --felt: #1b3a2a;
  --felt-deep: #12261c;
  --ivory: #f3e6c9;
  --cream: #efe2c4;
  --walnut: #7a4e2d;
  --walnut-deep: #4a2c18;
  --gold: #c9a227;
  --gold-soft: #e6c75a;
  --ink: #1a120b;
  --paper: #f7ecd4;
  --light-sq: #f0d9b5;
  --dark-sq: #b58863;
  --last: rgba(201, 162, 39, 0.45);
  --legal: rgba(26, 18, 11, 0.28);
  --check: rgba(168, 42, 32, 0.55);
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

html {
  font-size: 18px;
}

html:has(#view-play:not([hidden])),
body:has(#view-play:not([hidden])) {
  height: 100%;
  max-height: 100dvh;
  overflow: hidden;
}

body {
  font-family: "EB Garamond", "Noto Serif", "Times New Roman", serif;
  color: var(--ivory);
  background: var(--felt-deep);
}

.felt {
  min-height: 100vh;
  min-height: 100dvh;
  background:
    radial-gradient(ellipse at top, rgba(255, 255, 255, 0.06), transparent 50%),
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 2px,
      rgba(0, 0, 0, 0.04) 2px,
      rgba(0, 0, 0, 0.04) 3px
    ),
    linear-gradient(180deg, #234a35 0%, var(--felt) 40%, var(--felt-deep) 100%);
  display: flex;
  flex-direction: column;
}

.felt:has(#view-play:not([hidden])) {
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

.masthead {
  display: flex;
  justify-content: center;
  padding: 1.25rem 1.5rem 0;
  max-width: none;
  margin: 0 auto;
  width: 100%;
}

.brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  background: none;
  border: 0;
  color: inherit;
  cursor: pointer;
  padding: 0;
  font: inherit;
}

.brand-mark {
  width: 2.5rem;
  height: 2.5rem;
  display: grid;
  place-items: center;
  border: 1px solid var(--gold);
  border-radius: 4px;
  font-size: 1.4rem;
  background: rgba(0, 0, 0, 0.2);
}

.brand-text {
  display: flex;
  flex-direction: column;
  text-align: left;
  line-height: 1.15;
}

.brand-text strong {
  font-family: Cinzel, serif;
  font-weight: 700;
  letter-spacing: 0.08em;
  font-size: 0.95rem;
}

.brand-text em {
  font-family: "EB Garamond", "Noto Serif", serif;
  font-style: italic;
  font-size: 0.95rem;
  color: var(--gold-soft);
  font-weight: 500;
}

.felt:has(#view-play:not([hidden])) .masthead {
  padding-top: 0.7rem;
  flex: 0 0 auto;
}

main {
  flex: 1;
  width: 100%;
  max-width: 1600px;
  margin: 0 auto;
  padding: 1rem 1.5rem 1rem;
}

.felt:has(#view-play:not([hidden])) main {
  flex: 1 1 auto;
  min-height: 0;
  padding: 0.45rem 1.5rem 0.55rem;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.view[hidden] {
  display: none !important;
}

.view-home {
  padding: 2rem 0 1rem;
  max-width: 820px;
  margin: 0 auto;
  text-align: center;
}

.eyebrow {
  font-family: "EB Garamond", "Noto Serif", serif;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-size: 0.92rem;
  color: var(--gold);
  margin: 0 0 0.75rem;
}

.view-home h1 {
  font-family: "EB Garamond", "Noto Serif", serif;
  font-weight: 600;
  font-size: clamp(2.4rem, 6vw, 4.2rem);
  line-height: 1.08;
  margin: 0 0 1rem;
  color: var(--paper);
}

.lede {
  font-size: 1.2rem;
  line-height: 1.55;
  max-width: 38rem;
  color: rgba(243, 230, 201, 0.85);
  margin: 0 auto 2.25rem;
}

.choice-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}

.choice-card {
  text-align: center;
  align-items: center;
  background:
    linear-gradient(180deg, rgba(255, 248, 230, 0.08), transparent 40%),
    #2a1a10;
  border: 1px solid rgba(201, 162, 39, 0.35);
  color: var(--ivory);
  padding: 1.5rem 1.4rem 1.3rem;
  cursor: pointer;
  box-shadow: var(--shadow);
  font: inherit;
  display: flex;
  flex-direction: column;
  min-height: 280px;
  transition: transform 0.18s ease, border-color 0.18s ease;
}

.choice-card:hover,
.choice-card:focus-visible {
  transform: translateY(-4px);
  border-color: var(--gold);
  outline: none;
}

.choice-card:disabled,
.choice-card[aria-disabled="true"] {
  opacity: 0.48;
  cursor: not-allowed;
  filter: grayscale(0.25);
}

.choice-card:disabled:hover,
.choice-card:disabled:focus-visible {
  transform: none;
  border-color: rgba(201, 162, 39, 0.35);
}

.choice-card-gold {
  background:
    linear-gradient(180deg, rgba(201, 162, 39, 0.18), transparent 45%),
    #3a2714;
}

.choice-icon {
  font-size: 2rem;
  margin-bottom: 0.85rem;
}

.choice-kicker {
  font-family: "EB Garamond", "Noto Serif", serif;
  font-size: 0.85rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gold);
}

.choice-title {
  font-family: "EB Garamond", "Noto Serif", serif;
  font-size: 2rem;
  margin: 0.35rem 0 0.6rem;
}

.choice-copy {
  color: rgba(243, 230, 201, 0.78);
  line-height: 1.5;
  flex: 1;
}

.choice-cta {
  margin-top: 1.1rem;
  font-family: "EB Garamond", "Noto Serif", serif;
  font-size: 0.95rem;
  letter-spacing: 0.08em;
  color: var(--gold-soft);
}

.view-play {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: flex;
}

.table {
  display: grid;
  grid-template-columns: 320px auto 320px;
  justify-content: space-between;
  align-items: start;
  width: 100%;
  flex: 1;
  min-height: 0;
}

.panel {
  background: rgba(18, 12, 8, 0.45);
  border: 1px solid rgba(201, 162, 39, 0.22);
  padding: 1rem 1rem 1.1rem;
  backdrop-filter: blur(6px);
  width: 100%;
  min-width: 0;
}

.panel-left {
  height: fit-content;
}

.panel-title {
  font-family: "EB Garamond", "Noto Serif", serif;
  font-size: 0.95rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  margin: 0 0 0.9rem;
  color: var(--gold);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.85rem;
  font-size: 0.95rem;
}

.field span {
  color: rgba(243, 230, 201, 0.8);
}

.field em {
  font-style: italic;
  opacity: 0.7;
}

input,
select,
textarea {
  font: inherit;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid #cbb894;
  padding: 0.5rem 0.6rem;
  width: 100%;
}

select:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid var(--gold);
  outline-offset: 1px;
}

.panel-actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.4rem;
  margin: 0.4rem 0 0.45rem;
}

.panel-actions .btn {
  white-space: nowrap;
  padding: 0.45rem 0.4rem;
}

.panel-actions .btn-icon {
  display: none;
}

.panel-actions .btn-icon svg {
  width: 1.35rem;
  height: 1.35rem;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.panel-actions #btn-end {
  grid-column: 1 / -1;
}

.btn {
  font-family: "EB Garamond", "Noto Serif", serif;
  font-size: 0.95rem;
  letter-spacing: 0.04em;
  background: var(--walnut);
  color: var(--ivory);
  border: 1px solid var(--gold);
  padding: 0.5rem 0.75rem;
  cursor: pointer;
}

.btn:hover,
.btn:focus-visible {
  background: #8a5a34;
}

.btn-ghost {
  background: transparent;
}

.btn-ghost:hover,
.btn-ghost:focus-visible {
  background: rgba(122, 78, 45, 0.35);
}

.btn-gold {
  background: linear-gradient(180deg, #e6c75a, #b8891a);
  color: #2a1a10;
  border-color: #8a6a16;
  width: 100%;
  padding: 0.8rem 1rem;
  font-size: 1.05rem;
}

.btn-gold:hover {
  filter: brightness(1.05);
}

.captured-stack {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin-top: 0.4rem;
}

.captured-box {
  min-height: 3.4rem;
  padding: 0.4rem 0.45rem;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  align-items: center;
  gap: 0.1rem;
  border: 1px solid rgba(201, 162, 39, 0.35);
}

.captured-box.is-white {
  background: #f3e6c9;
}

.captured-box.is-black {
  background: #24180f;
  box-shadow: inset 0 0 0 1px rgba(243, 230, 201, 0.22);
}

.captured-box.is-black .captured-piece {
  filter: drop-shadow(0 0 0.6px #efe2c4);
}

.captured-piece {
  width: 1.55rem;
  height: 1.55rem;
  display: block;
  flex: 0 0 auto;
}

.captured-piece svg {
  width: 100%;
  height: 100%;
  display: block;
}

.board-wrap {
  height: 100%;
  max-height: 100%;
  min-height: 0;
  width: auto;
  max-width: 50vw;
  align-self: stretch;
  justify-self: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
}

.board-frame {
  box-sizing: border-box;
  height: min(50vw, calc(100% - 3.5rem));
  width: auto;
  aspect-ratio: 1;
  max-width: 50vw;
  padding: 14px;
  background:
    linear-gradient(145deg, #6b4226, #3a2212 55%, #2a170c);
  box-shadow:
    inset 0 0 0 2px #c9a227,
    inset 0 0 0 6px #5a341c,
    var(--shadow);
  flex: 0 0 auto;
}

.board {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  grid-template-rows: repeat(8, minmax(0, 1fr));
  width: 100%;
  height: 100%;
  aspect-ratio: unset;
  user-select: none;
  touch-action: none;
  box-shadow: inset 0 0 0 1px #2a170c;
}

.sq {
  position: relative;
  min-width: 0;
  min-height: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.sq.light {
  background: var(--light-sq);
}

.sq.dark {
  background: var(--dark-sq);
}

.sq.last {
  box-shadow: inset 0 0 0 100px var(--last);
}

.sq.selected {
  box-shadow: inset 0 0 0 100px rgba(90, 160, 90, 0.4);
}

.sq.check {
  box-shadow: inset 0 0 0 100px var(--check);
}

.coord {
  position: absolute;
  font-size: 0.68rem;
  font-family: "EB Garamond", "Noto Serif", serif;
  pointer-events: none;
  opacity: 0.72;
  font-weight: 700;
  z-index: 3;
}

.coord-file {
  right: 3px;
  bottom: 2px;
}

.coord-rank {
  left: 3px;
  top: 2px;
}

.sq.light .coord {
  color: var(--walnut);
}

.sq.dark .coord {
  color: var(--light-sq);
}

.piece {
  position: absolute;
  inset: 6%;
  width: auto;
  height: auto;
  cursor: grab;
  z-index: 2;
  filter: drop-shadow(0 2px 1px rgba(0, 0, 0, 0.35));
}

.piece:active {
  cursor: grabbing;
}

.piece svg {
  width: 100%;
  height: 100%;
  display: block;
  max-width: 100%;
  max-height: 100%;
}

.legal-dot,
.legal-ring {
  position: absolute;
  pointer-events: none;
  z-index: 1;
}

.legal-dot {
  top: 50%;
  left: 50%;
  width: 28%;
  height: 28%;
  border-radius: 50%;
  background: var(--legal);
  transform: translate(-50%, -50%);
}

.legal-ring {
  inset: 6%;
  border-radius: 50%;
  border: 5px solid var(--legal);
}

.turn-banner {
  margin-top: 0.55rem;
  width: 100%;
  flex: 0 0 auto;
  box-sizing: border-box;
  text-align: center;
  font-family: "EB Garamond", "Noto Serif", serif;
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  border: 1px solid var(--gold);
  box-shadow:
    inset 0 0 0 3px #5a341c,
    0 8px 18px rgba(0, 0, 0, 0.28);
  padding: 0.45rem 0.85rem;
}

.turn-banner.is-white {
  color: #2a1a10;
  background: linear-gradient(180deg, #f7ecd4, #e6d3a8);
}

.turn-banner.is-black {
  color: #f7ecd4;
  background: linear-gradient(180deg, #2a2118, #14100c);
}

.think {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 3.55rem;
  margin: 0;
  text-align: center;
  font-style: italic;
  color: var(--gold-soft);
  pointer-events: none;
}

.moves-head,
.moves li {
  display: grid;
  grid-template-columns: 2rem 1fr 1fr;
  gap: 0.4rem;
  align-items: center;
}

.moves-head {
  margin-bottom: 0.35rem;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid rgba(201, 162, 39, 0.35);
  font-size: 0.88rem;
}

.moves-head .n {
  color: var(--gold);
}

.moves-side {
  text-align: center;
  padding: 0.18rem 0.2rem;
  font-weight: 600;
}

.moves-side.is-white {
  color: #2a1a10;
  background: #f3e6c9;
}

.moves-side.is-black {
  color: #f7ecd4;
  background: #24180f;
}

.moves {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: min(28rem, calc(100vh - 16rem));
  overflow: auto;
  font-variant-numeric: tabular-nums;
  font-size: 0.95rem;
}

.moves li {
  padding: 0.2rem 0;
  border-bottom: 1px solid rgba(243, 230, 201, 0.08);
}

.moves .w,
.moves .b {
  text-align: center;
}

.moves .n {
  color: var(--gold);
  font-family: "EB Garamond", "Noto Serif", serif;
  font-size: 0.85rem;
}

.modal[hidden] {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(8, 14, 10, 0.72);
}

.letter,
.promote {
  position: relative;
  z-index: 1;
  width: min(520px, 100%);
  background:
    linear-gradient(180deg, #fff8e8, #f0e0c0);
  color: var(--ink);
  padding: 1.75rem 1.6rem 1.5rem;
  box-shadow: var(--shadow);
  border: 1px solid #c9a227;
}

.letter-close {
  position: absolute;
  top: 0.6rem;
  right: 0.75rem;
  background: none;
  border: 0;
  font-size: 1.6rem;
  cursor: pointer;
  color: #5a341c;
  line-height: 1;
}

.letter-seal {
  font-family: "EB Garamond", "Noto Serif", serif;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-size: 0.85rem;
  color: #8a6a16;
  margin: 0 0 0.4rem;
}

.letter h2 {
  font-family: "EB Garamond", "Noto Serif", serif;
  font-size: 2.2rem;
  margin: 0 0 0.5rem;
}

.letter-intro {
  margin: 0 0 1.1rem;
  line-height: 1.5;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.form-note,
.form-error,
.form-ok {
  font-size: 0.92rem;
  line-height: 1.45;
}

.form-note {
  background: #fff3cc;
  border: 1px solid #d4b24a;
  padding: 0.6rem 0.7rem;
}

.form-error {
  color: #8a1f18;
}

.form-ok {
  color: #1e4d32;
}

.promote {
  text-align: center;
  width: min(360px, 100%);
}

.promote p {
  font-family: "EB Garamond", "Noto Serif", serif;
  letter-spacing: 0.08em;
  margin: 0 0 0.8rem;
}

.confirm-box {
  position: relative;
  z-index: 1;
  width: min(420px, 100%);
  background: linear-gradient(180deg, #fff8e8, #f0e0c0);
  color: var(--ink);
  padding: 1.5rem 1.4rem 1.25rem;
  box-shadow: var(--shadow);
  border: 1px solid #c9a227;
}

.confirm-box h2 {
  font-family: "EB Garamond", "Noto Serif", serif;
  font-size: 1.7rem;
  margin: 0 0 0.45rem;
}

.level-readout {
  margin: 0 0 0.85rem;
  color: var(--gold-soft);
  font-size: 1.05rem;
}

.ai-setup-box .field span {
  color: var(--ink);
}

.ai-setup-box {
  width: min(420px, 100%);
}

.ai-setup-intro {
  margin: 0 0 1rem;
  line-height: 1.45;
}

.ai-setup-box .btn-gold {
  margin-top: 0.35rem;
}

.confirm-box p {
  margin: 0 0 1.1rem;
  line-height: 1.5;
}

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.confirm-actions .btn {
  color: var(--ivory);
}

.confirm-actions .btn-ghost {
  color: var(--ink);
  border-color: #7a4e2d;
}

.promote-choices {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
}

.promote-choices button {
  background: #f0d9b5;
  border: 1px solid #7a4e2d;
  cursor: pointer;
  padding: 0.4rem;
  height: 72px;
}

.promote-choices button:hover {
  background: #e8c992;
}

.promote-choices svg {
  width: 100%;
  height: 100%;
}

@media (max-width: 900px) {
  html:has(#view-play:not([hidden])),
  body:has(#view-play:not([hidden])) {
    height: auto;
    max-height: none;
    overflow: auto;
  }

  .felt:has(#view-play:not([hidden])) {
    height: auto;
    min-height: 100dvh;
    overflow: visible;
  }

  .felt:has(#view-play:not([hidden])) main {
    overflow: visible;
    display: block;
    padding: 0.75rem 1rem 1rem;
  }

  .view-play {
    display: block;
    flex: none;
    min-height: 0;
  }

  .table {
    grid-template-columns: 1fr;
    height: auto;
    flex: none;
  }

  .choice-grid {
    grid-template-columns: 1fr;
  }

  .board-wrap {
    order: 1;
    height: auto;
    width: min(92vw, 70vh);
    max-width: 92vw;
    align-self: center;
  }

  .board-frame {
    width: 100%;
    height: auto;
    max-width: none;
    aspect-ratio: 1;
    padding: 12px;
  }

  .panel-left {
    order: 2;
    display: flex;
    flex-direction: column;
  }

  .panel-title {
    order: 0;
  }

  .panel-actions {
    order: 1;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.55rem;
    margin: 0.15rem 0 0.85rem;
  }

  .panel-actions #btn-end {
    grid-column: auto;
  }

  .panel-actions .btn {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 3.15rem;
    height: 3.15rem;
    margin: 0 auto;
    padding: 0;
    border-radius: 50%;
    background: rgba(18, 12, 8, 0.35);
    overflow: hidden;
  }

  .panel-actions .btn-icon {
    display: block;
    line-height: 0;
  }

  .panel-actions .btn-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
  }

  .captured-stack {
    order: 2;
    flex-direction: row;
    gap: 0.55rem;
    margin: 0 0 0.9rem;
  }

  .captured-box {
    flex: 1;
    min-height: 3.1rem;
  }

  .panel-setup {
    order: 3;
  }

  .panel-setup .field:last-child {
    margin-bottom: 0;
  }

  .panel-right {
    order: 3;
  }

  .moves {
    max-height: 180px;
  }
}

@media (max-width: 520px) {
  .field-row {
    grid-template-columns: 1fr;
  }

  .view-home {
    padding-top: 0.5rem;
  }
}

@media (max-width: 390px) {
  .panel-actions .btn {
    width: 2.85rem;
    height: 2.85rem;
  }
}

a.brand {
  text-decoration: none;
}

a.btn {
  display: inline-block;
  text-align: center;
  text-decoration: none;
  box-sizing: border-box;
}

.live-table {
  align-items: stretch;
}

.left-stack {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  height: 100%;
  min-height: 0;
  width: 320px;
}

.live-meta {
  margin: 0 0 0.45rem;
  color: rgba(243, 230, 201, 0.88);
  line-height: 1.4;
}

.chat-panel {
  flex: 1;
  min-height: 140px;
  display: flex;
  flex-direction: column;
}

.chat-log {
  flex: 1;
  min-height: 72px;
  overflow: auto;
  font-size: 0.92rem;
  line-height: 1.4;
  margin-bottom: 0.55rem;
}

.chat-row {
  margin-bottom: 0.4rem;
}

.chat-row.mine strong {
  color: var(--gold-soft);
}

.chat-row.theirs strong {
  color: #f3e6c9;
}

.chat-form {
  display: flex;
  gap: 0.4rem;
}

.chat-form input {
  flex: 1;
}

.chat-form .btn {
  flex: 0 0 auto;
  color: var(--ivory);
}

.gate {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 30;
  place-items: center;
  padding: 1rem;
  background: rgba(8, 14, 10, 0.78);
}

.gate.is-on {
  display: grid;
}

.result-page main {
  display: flex;
  justify-content: center;
  padding-top: 2rem;
}

.result-card {
  width: min(560px, 100%);
  background: linear-gradient(180deg, #fff8e8, #f0e0c0);
  color: var(--ink);
  padding: 1.6rem 1.5rem;
  border: 1px solid #c9a227;
  box-shadow: var(--shadow);
}

.result-card h1 {
  font-family: "EB Garamond", "Noto Serif", serif;
  margin: 0 0 0.7rem;
}

.result-card a {
  color: #5a341c;
}

.result-card .btn-gold {
  margin-top: 0.6rem;
}

@media (max-width: 900px) {
  .left-stack {
    width: 100%;
    height: auto;
    order: 2;
  }

  .chat-panel {
    min-height: 180px;
  }
}
