:root {
  --bg-wood-dark: #23160f;
  --bg-wood-mid: #51311c;
  --bg-wood-light: #87603b;
  --parchment: #ebdcc0;
  --parchment-soft: #f6edd9;
  --parchment-deep: #d0b17d;
  --ink: #2e1d12;
  --ink-soft: #6d543d;
  --gold: #c9a76c;
  --gold-deep: #866037;
  --copper: #a46743;
  --marble: #d9d1c3;
  --black-piece: #2a2420;
  --white-piece: #f0e7d2;
  --board-light: #d7c0a0;
  --board-dark: #70503a;
  --board-dark-2: #5b3e2c;
  --danger: #7e2f29;
  --success: #3d6844;
  --shadow-lg: 0 24px 46px rgba(19, 12, 8, 0.35);
  --shadow-md: 0 16px 28px rgba(28, 17, 10, 0.24);
  --radius-lg: 30px;
  --radius-md: 22px;
  --radius-sm: 14px;
  --transition: 180ms ease;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  color: var(--ink);
  font-family: "Cormorant Garamond", Georgia, serif;
  background:
    radial-gradient(circle at 18% 18%, rgba(255, 233, 192, 0.12), transparent 22%),
    radial-gradient(circle at 82% 10%, rgba(255, 240, 203, 0.08), transparent 18%),
    linear-gradient(180deg, rgba(15, 9, 6, 0.32), rgba(15, 9, 6, 0.08)),
    linear-gradient(150deg, var(--bg-wood-light), var(--bg-wood-mid) 34%, var(--bg-wood-dark));
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    repeating-linear-gradient(105deg, rgba(255, 255, 255, 0.03) 0 2px, transparent 2px 8px),
    repeating-linear-gradient(12deg, rgba(32, 20, 11, 0.07) 0 1px, transparent 1px 6px);
  mix-blend-mode: soft-light;
  opacity: 0.92;
}

button,
input {
  font: inherit;
}

.ambience {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.particle {
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(252, 238, 200, 0.68), rgba(252, 238, 200, 0));
  opacity: 0.25;
  animation: drift 18s linear infinite;
}

.particle--a { top: 14%; left: 8%; animation-duration: 16s; }
.particle--b { top: 34%; left: 80%; animation-duration: 22s; animation-delay: -6s; }
.particle--c { top: 76%; left: 20%; animation-duration: 20s; animation-delay: -9s; }
.particle--d { top: 74%; left: 70%; animation-duration: 21s; animation-delay: -4s; }
.particle--e { top: 52%; left: 52%; animation-duration: 17s; animation-delay: -8s; }
.particle--f { top: 18%; left: 62%; animation-duration: 24s; animation-delay: -13s; }

.app-shell {
  position: relative;
  width: min(1360px, calc(100% - 28px));
  margin: 0 auto;
  padding: 18px 0 42px;
}

.app-header,
.hero-card,
.frame,
.feature-card,
.hub-card,
.modal-card,
.loading-card {
  position: relative;
  overflow: hidden;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding: 24px;
  margin: 18px 0;
  border-radius: var(--radius-lg);
  background:
    linear-gradient(145deg, rgba(245, 232, 203, 0.92), rgba(217, 189, 139, 0.82)),
    linear-gradient(145deg, rgba(114, 77, 42, 0.22), rgba(255, 255, 255, 0));
  border: 1px solid rgba(116, 77, 42, 0.42);
  box-shadow: var(--shadow-lg);
}

.app-header::before,
.hero-card::before,
.frame::before,
.feature-card::before,
.hub-card::before,
.modal-card::before,
.loading-card::before {
  content: "";
  position: absolute;
  inset: 10px;
  border: 1px solid rgba(114, 77, 41, 0.24);
  border-radius: calc(var(--radius-lg) - 10px);
  pointer-events: none;
}

.eyebrow,
.section-kicker {
  margin: 0 0 8px;
  color: var(--gold-deep);
  font-family: "Cinzel", serif;
  font-size: 0.82rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  margin: 0;
  font-family: "Cinzel", serif;
  color: #422919;
}

h1 {
  font-size: clamp(2.5rem, 4vw, 4.2rem);
}

h2 {
  font-size: clamp(1.45rem, 2vw, 2.1rem);
}

h3 {
  font-size: 1rem;
}

.subtitle,
.hero-copy p,
.feature-card p,
.hub-card p,
.side-panel p,
.moves-panel,
.modal-card p {
  font-size: clamp(1.06rem, 1.3vw, 1.24rem);
  line-height: 1.5;
}

.view {
  display: none;
}

.view--active {
  display: block;
  animation: fadeUp 260ms ease both;
}

.hero-card,
.frame {
  padding: 24px;
  border-radius: var(--radius-lg);
  background:
    radial-gradient(circle at top left, rgba(255, 245, 220, 0.28), transparent 24%),
    linear-gradient(155deg, rgba(248, 236, 210, 0.95), rgba(219, 190, 138, 0.88));
  border: 1px solid rgba(122, 83, 45, 0.42);
  box-shadow: var(--shadow-lg);
}

.hero-card {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(280px, 0.9fr);
  gap: 24px;
  align-items: center;
}

.hero-actions,
.frame__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.app-header__actions {
  display: grid;
  gap: 10px;
  justify-items: end;
}

.hero-actions {
  margin-top: 22px;
}

.hero-board {
  width: min(100%, 360px);
  margin-inline: auto;
}

.hero-board__frame {
  position: relative;
  aspect-ratio: 1;
  border-radius: 28px;
  background:
    linear-gradient(135deg, #b48a58, #7c532f 62%, #4c2d18);
  box-shadow:
    inset 0 0 0 7px rgba(62, 39, 24, 0.58),
    inset 0 0 0 16px rgba(218, 186, 126, 0.14),
    0 24px 38px rgba(20, 12, 8, 0.34);
}

.hero-board__grid {
  position: absolute;
  inset: 22px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0;
  border-radius: 18px;
  overflow: hidden;
}

.hero-board__grid span:nth-child(1),
.hero-board__grid span:nth-child(4) { background: var(--board-light); }
.hero-board__grid span:nth-child(2),
.hero-board__grid span:nth-child(3) { background: var(--board-dark); }

.hero-board__piece {
  position: absolute;
  width: 88px;
  height: 88px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 30%, rgba(255, 244, 214, 0.72), transparent 28%),
    linear-gradient(180deg, rgba(255, 249, 239, 0.55), rgba(54, 34, 21, 0.88));
  filter: drop-shadow(0 12px 16px rgba(0, 0, 0, 0.24));
}

.hero-board__piece--king {
  top: 46px;
  left: 56px;
  clip-path: polygon(46% 0, 54% 0, 54% 12%, 66% 12%, 66% 20%, 54% 20%, 54% 30%, 70% 38%, 74% 64%, 30% 64%, 34% 38%, 46% 30%, 46% 20%, 34% 20%, 34% 12%, 46% 12%);
}

.hero-board__piece--queen {
  right: 56px;
  bottom: 42px;
  clip-path: polygon(20% 18%, 30% 50%, 40% 22%, 50% 50%, 60% 22%, 70% 50%, 80% 18%, 72% 64%, 28% 64%);
}

.feature-grid,
.hub-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
  margin-top: 18px;
}

.feature-card,
.hub-card,
.side-panel,
.board-panel,
.moves-panel {
  padding: 20px;
  border-radius: var(--radius-md);
  background:
    linear-gradient(180deg, rgba(251, 243, 223, 0.9), rgba(228, 198, 148, 0.86));
  border: 1px solid rgba(122, 82, 46, 0.34);
  box-shadow: var(--shadow-md);
}

.frame__topbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
}

.play-layout {
  display: grid;
  grid-template-columns: minmax(250px, 310px) minmax(0, 1fr) minmax(230px, 290px);
  gap: 18px;
  align-items: start;
}

.board-panel {
  min-width: 0;
}

.moves-panel {
  display: grid;
  gap: 14px;
}

.moves-panel__head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}

.status-line {
  font-weight: 700;
  color: #5f3320;
}

.info-ribbon,
.meta-block,
.identity-card {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: rgba(78, 51, 31, 0.08);
  border: 1px solid rgba(116, 79, 44, 0.22);
  color: var(--ink-soft);
}

.identity-card {
  margin-top: 14px;
  font-weight: 700;
}

.score-panel {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.score-chip {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: rgba(255, 248, 232, 0.72);
  border: 1px solid rgba(117, 80, 44, 0.22);
}

.score-chip strong {
  font-family: "Cinzel", serif;
  font-size: 0.94rem;
}

.score-chip span {
  font-size: 1.08rem;
  font-weight: 700;
}

.capture-section {
  display: grid;
  gap: 8px;
  margin-top: 18px;
}

.capture-section h3 {
  font-size: 0.96rem;
}

.capture-row {
  min-height: 48px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  padding: 10px;
  border-radius: var(--radius-sm);
  background: rgba(255, 248, 232, 0.68);
  border: 1px solid rgba(117, 80, 44, 0.22);
}

.capture-empty {
  opacity: 0.72;
}

.history-list {
  display: grid;
  gap: 8px;
  max-height: 520px;
  overflow: auto;
  padding-right: 4px;
}

.history-row {
  display: grid;
  grid-template-columns: 40px 1fr 1fr;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: rgba(255, 248, 232, 0.72);
  border: 1px solid rgba(117, 80, 44, 0.18);
}

.history-turn {
  font-family: "Cinzel", serif;
  font-size: 0.92rem;
}

.history-empty {
  padding: 14px;
  border-radius: var(--radius-sm);
  background: rgba(255, 248, 232, 0.68);
  border: 1px solid rgba(117, 80, 44, 0.18);
}

.board-shell {
  width: min(100%, 46rem);
  margin: 0 auto;
}

.board-frame {
  padding: 18px;
  border-radius: 30px;
  background:
    radial-gradient(circle at top left, rgba(255, 243, 211, 0.2), transparent 22%),
    linear-gradient(145deg, #a57847, #6f482c 62%, #442816);
  box-shadow:
    inset 0 0 0 7px rgba(62, 39, 24, 0.62),
    inset 0 0 0 16px rgba(214, 181, 123, 0.12),
    0 28px 42px rgba(22, 13, 8, 0.36);
}

.board-grid {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  aspect-ratio: 1;
  border-radius: 18px;
  overflow: hidden;
}

.board-square {
  position: relative;
  border: 0;
  min-width: 0;
  padding: 0;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition), filter var(--transition);
}

.board-square::before {
  content: "";
  display: block;
  padding-top: 100%;
}

.board-square > * {
  position: absolute;
}

.board-square--light {
  background:
    linear-gradient(145deg, rgba(255, 248, 230, 0.25), rgba(0, 0, 0, 0)),
    linear-gradient(180deg, #d6bea1, #c3a17a);
}

.board-square--dark {
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.06), rgba(0, 0, 0, 0)),
    linear-gradient(180deg, #6f513d, #5b3f2f);
}

.board-square--interactive:hover:not(:disabled),
.board-square--interactive:focus-visible:not(:disabled),
.board-square--selected {
  box-shadow: inset 0 0 0 4px rgba(223, 190, 125, 0.68);
  outline: none;
}

.board-square--last {
  box-shadow: inset 0 0 0 4px rgba(207, 167, 90, 0.42);
}

.board-square--check {
  box-shadow:
    inset 0 0 0 4px rgba(170, 65, 54, 0.65),
    inset 0 0 26px rgba(170, 65, 54, 0.24);
}

.legal-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(71, 116, 70, 0.42);
  box-shadow: 0 0 0 2px rgba(28, 56, 28, 0.12);
}

.legal-dot--capture {
  width: calc(100% - 12px);
  height: calc(100% - 12px);
  background: transparent;
  border: 4px solid rgba(120, 47, 37, 0.52);
  box-shadow: none;
}

.board-label {
  font-family: "Cinzel", serif;
  font-size: 0.78rem;
  opacity: 0.68;
}

.board-label--rank {
  top: 6px;
  left: 8px;
}

.board-label--file {
  right: 8px;
  bottom: 6px;
}

.piece {
  inset: 0;
  width: 86%;
  height: 86%;
  margin: auto;
  display: grid;
  place-items: center;
  filter: drop-shadow(0 8px 8px rgba(0, 0, 0, 0.18));
  animation: pieceAppear 180ms ease;
}

.piece svg {
  width: 100%;
  height: 100%;
}

.piece__body,
.piece__core,
.piece__base,
.piece__accent {
  stroke-width: 3.6;
  stroke-linejoin: round;
}

.piece__detail {
  stroke-width: 3.2;
  stroke-linecap: round;
}

.piece--white .piece__body,
.piece--white .piece__core,
.piece--white .piece__base,
.piece--white .piece__accent {
  fill: var(--white-piece);
  stroke: #7f6b4d;
}

.piece--white .piece__detail {
  stroke: #8d7552;
}

.piece--white .piece__accent {
  fill: #f8efdb;
}

.piece--black .piece__body,
.piece--black .piece__core,
.piece--black .piece__base,
.piece--black .piece__accent {
  fill: var(--black-piece);
  stroke: #d0b483;
}

.piece--black .piece__detail {
  stroke: #e4cb9a;
}

.piece--black .piece__accent {
  fill: #5b4c41;
}

.piece__base--heavy {
  opacity: 0.9;
}

.piece--small {
  width: 34px;
  height: 34px;
}

.capture-piece {
  display: inline-flex;
}

.ornate-btn,
.ghost-btn,
.promotion-card {
  border: 0;
  cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition), filter var(--transition);
}

.ornate-btn {
  padding: 14px 18px;
  border-radius: 14px;
  background:
    linear-gradient(180deg, #d8b67e, #b18145 52%, #805027);
  color: #26160d;
  font-family: "Cinzel", serif;
  font-weight: 700;
  letter-spacing: 0.03em;
  box-shadow:
    inset 0 0 0 2px rgba(255, 238, 203, 0.28),
    0 12px 18px rgba(41, 24, 14, 0.22);
}

.ornate-btn--accent {
  background:
    linear-gradient(180deg, #dfb672, #c28748 52%, #8d5129);
}

.ornate-btn--small {
  min-width: 180px;
}

.ghost-btn {
  padding: 12px 16px;
  border-radius: 14px;
  background: rgba(80, 53, 31, 0.1);
  border: 1px solid rgba(108, 72, 40, 0.28);
  color: var(--ink);
  font-weight: 700;
}

.portal-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.ghost-btn--tiny {
  padding: 8px 10px;
  font-size: 0.92rem;
}

.ornate-btn:hover,
.ornate-btn:focus-visible,
.ghost-btn:hover,
.ghost-btn:focus-visible,
.promotion-card:hover,
.promotion-card:focus-visible {
  transform: translateY(-2px);
  filter: brightness(1.03);
  outline: none;
}

.join-form {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

.field-label {
  font-weight: 700;
}

.field-input {
  width: 100%;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid rgba(113, 76, 42, 0.34);
  background: rgba(255, 249, 233, 0.84);
  color: var(--ink);
  font-size: 1.08rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.field-input:focus {
  outline: 2px solid rgba(192, 152, 87, 0.52);
  border-color: rgba(113, 76, 42, 0.52);
}

.modal-root {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  pointer-events: none;
  z-index: 30;
}

.modal-root.is-open {
  pointer-events: auto;
}

.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(16, 10, 6, 0.54);
  backdrop-filter: blur(6px);
}

.modal-card {
  position: relative;
  width: min(560px, 100%);
  padding: 26px;
  border-radius: 26px;
  background:
    linear-gradient(180deg, rgba(248, 236, 207, 0.98), rgba(223, 193, 139, 0.94));
  border: 1px solid rgba(123, 82, 46, 0.42);
  box-shadow: var(--shadow-lg);
  z-index: 1;
  animation: fadeUp 240ms ease;
}

.promotion-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 18px;
}

.promotion-card {
  padding: 14px;
  border-radius: 16px;
  background: rgba(255, 248, 232, 0.72);
  border: 1px solid rgba(117, 80, 44, 0.24);
  font-family: "Cinzel", serif;
  font-weight: 700;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 18px;
}

.toast-stack {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: grid;
  gap: 10px;
  z-index: 40;
}

.toast {
  min-width: min(340px, calc(100vw - 32px));
  max-width: 360px;
  padding: 14px 16px;
  border-radius: 16px;
  background: rgba(36, 22, 13, 0.88);
  color: #f8ead0;
  box-shadow: 0 18px 24px rgba(0, 0, 0, 0.22);
  border: 1px solid rgba(216, 187, 130, 0.22);
  animation: fadeUp 220ms ease;
}

.toast--error {
  background: rgba(109, 41, 33, 0.92);
}

.toast--success {
  background: rgba(56, 87, 54, 0.92);
}

.connection-pill {
  padding: 8px 10px;
  border-radius: 999px;
  background: rgba(109, 41, 33, 0.12);
  color: var(--danger);
  font-family: "Cinzel", serif;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
}

.connection-pill--ok {
  background: rgba(56, 87, 54, 0.12);
  color: var(--success);
}

.loading-curtain {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(16, 10, 6, 0.42);
  backdrop-filter: blur(5px);
  z-index: 45;
}

.loading-curtain[hidden] {
  display: none;
}

.loading-card {
  width: min(320px, calc(100vw - 32px));
  padding: 24px;
  border-radius: 24px;
  background:
    linear-gradient(180deg, rgba(248, 236, 207, 0.98), rgba(223, 193, 139, 0.94));
  border: 1px solid rgba(123, 82, 46, 0.42);
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.spinner {
  width: 54px;
  height: 54px;
  margin: 0 auto 14px;
  border-radius: 50%;
  border: 4px solid rgba(134, 95, 54, 0.24);
  border-top-color: rgba(134, 95, 54, 0.86);
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pieceAppear {
  from {
    opacity: 0;
    transform: scale(0.9);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes drift {
  0% { transform: translate3d(0, 0, 0) scale(0.78); }
  50% { transform: translate3d(34px, -24px, 0) scale(1); }
  100% { transform: translate3d(-18px, -46px, 0) scale(0.72); }
}

@media (max-width: 1120px) {
  .play-layout {
    grid-template-columns: 1fr;
  }

  .moves-panel {
    order: 3;
  }
}

@media (max-width: 960px) {
  .hero-card,
  .feature-grid,
  .hub-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .app-shell {
    width: min(100% - 16px, 100%);
    padding-top: 10px;
  }

  .app-header,
  .hero-card,
  .frame {
    padding: 18px;
    border-radius: 22px;
  }

  .app-header {
    flex-direction: column;
  }

  .frame__topbar {
    flex-wrap: wrap;
  }

  .frame__actions,
  .app-header__actions,
  .hero-actions,
  .modal-actions {
    display: grid;
    width: 100%;
  }

  .ornate-btn,
  .ghost-btn {
    width: 100%;
  }

  .feature-card,
  .hub-card,
  .side-panel,
  .board-panel,
  .moves-panel {
    padding: 16px;
  }

  .board-frame {
    padding: 10px;
  }

  .history-row {
    grid-template-columns: 34px 1fr 1fr;
    gap: 8px;
    padding: 8px 10px;
  }

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

  .toast-stack {
    right: 10px;
    left: 10px;
    bottom: 10px;
  }

  .toast {
    min-width: auto;
    max-width: none;
  }
}
