:root {
  --bg-wood-dark: #2d1f17;
  --bg-wood-mid: #5e3b24;
  --bg-wood-light: #8a5a35;
  --parchment: #e9d6ad;
  --parchment-soft: #f1e4c5;
  --parchment-deep: #d1b47b;
  --ink: #342115;
  --ink-soft: #654830;
  --gold: #caa66b;
  --gold-deep: #8a6534;
  --copper: #9d5d3e;
  --stone: #94836d;
  --success: #4d7042;
  --danger: #8c3b2f;
  --shadow: 0 22px 48px rgba(12, 8, 5, 0.36);
  --panel-shadow: 0 16px 34px rgba(32, 20, 11, 0.28);
  --radius-lg: 28px;
  --radius-md: 20px;
  --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 top, rgba(255, 224, 163, 0.16), transparent 28%),
    radial-gradient(circle at 20% 20%, rgba(255, 236, 188, 0.08), transparent 22%),
    linear-gradient(145deg, rgba(13, 8, 5, 0.4), rgba(13, 8, 5, 0.15)),
    linear-gradient(180deg, 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.028) 0 2px, transparent 2px 8px),
    repeating-linear-gradient(12deg, rgba(33, 21, 12, 0.07) 0 1px, transparent 1px 6px);
  mix-blend-mode: soft-light;
  opacity: 0.85;
}

button,
input {
  font: inherit;
}

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

.dust {
  position: absolute;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 241, 208, 0.75), rgba(255, 241, 208, 0));
  filter: blur(0.5px);
  opacity: 0.32;
  animation: drift 18s linear infinite;
}

.dust--a { top: 12%; left: 10%; animation-duration: 17s; }
.dust--b { top: 36%; left: 82%; animation-duration: 22s; animation-delay: -5s; }
.dust--c { top: 70%; left: 18%; animation-duration: 19s; animation-delay: -2s; }
.dust--d { top: 82%; left: 70%; animation-duration: 24s; animation-delay: -10s; }
.dust--e { top: 46%; left: 50%; animation-duration: 20s; animation-delay: -7s; }
.dust--f { top: 20%; left: 62%; animation-duration: 16s; animation-delay: -11s; }

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

.app-header,
.frame,
.hero-card,
.info-card {
  position: relative;
  overflow: hidden;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding: 24px;
  margin: 22px 0 18px;
  border-radius: var(--radius-lg);
  background:
    linear-gradient(135deg, rgba(241, 228, 197, 0.92), rgba(222, 194, 143, 0.78)),
    linear-gradient(135deg, rgba(95, 62, 33, 0.24), rgba(255, 255, 255, 0));
  border: 1px solid rgba(117, 75, 38, 0.4);
  box-shadow: var(--shadow);
}

.app-header::after,
.frame::before,
.hero-card::before,
.info-card::before,
.hub-card::before,
.loading-card::before,
.modal-card::before {
  content: "";
  position: absolute;
  inset: 10px;
  border: 1px solid rgba(110, 72, 39, 0.28);
  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;
}

.brand-block h1,
.hero-card h2,
.frame h2,
.hub-card h2,
.info-card h3,
.modal-card h3 {
  margin: 0;
  font-family: "Cinzel", serif;
  color: #412818;
}

.brand-block h1 {
  font-size: clamp(2.4rem, 4vw, 3.8rem);
}

.tagline,
.hero-card p,
.side-panel p,
.hub-card p,
.info-card p,
.modal-card p {
  font-size: clamp(1.08rem, 1.3vw, 1.28rem);
  line-height: 1.45;
}

.app-main {
  display: grid;
}

.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, 243, 210, 0.25), transparent 22%),
    linear-gradient(155deg, rgba(247, 234, 204, 0.95), rgba(221, 193, 139, 0.88));
  border: 1px solid rgba(122, 82, 44, 0.44);
  box-shadow: var(--shadow);
}

.hero-card {
  display: grid;
  grid-template-columns: 1.25fr 0.9fr;
  gap: 26px;
  align-items: center;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 22px;
}

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

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

.info-card,
.hub-card {
  padding: 22px;
  border-radius: var(--radius-md);
  background:
    linear-gradient(180deg, rgba(250, 241, 216, 0.92), rgba(227, 198, 144, 0.88));
  border: 1px solid rgba(127, 86, 49, 0.4);
  box-shadow: var(--panel-shadow);
}

.relic-board {
  position: relative;
  aspect-ratio: 1;
  width: min(100%, 360px);
  margin-inline: auto;
  border-radius: 30px;
  background:
    radial-gradient(circle at 50% 12%, rgba(255, 244, 210, 0.45), transparent 25%),
    linear-gradient(180deg, rgba(81, 53, 31, 0.2), rgba(41, 24, 15, 0.26)),
    linear-gradient(135deg, #a16c3d, #5f3a22 68%, #412618);
  box-shadow:
    inset 0 0 0 6px rgba(58, 34, 20, 0.55),
    inset 0 0 0 14px rgba(206, 168, 103, 0.18),
    0 24px 38px rgba(30, 18, 11, 0.34);
}

.relic-board__grid,
.board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.relic-board__grid {
  position: absolute;
  inset: 28px;
}

.relic-board__grid::before,
.relic-board__grid::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, transparent calc(33.333% - 3px), rgba(232, 203, 146, 0.72) calc(33.333% - 3px), rgba(103, 66, 37, 0.9) calc(33.333% + 3px), transparent calc(33.333% + 3px), transparent calc(66.666% - 3px), rgba(232, 203, 146, 0.72) calc(66.666% - 3px), rgba(103, 66, 37, 0.9) calc(66.666% + 3px), transparent calc(66.666% + 3px)),
    linear-gradient(180deg, transparent calc(33.333% - 3px), rgba(232, 203, 146, 0.72) calc(33.333% - 3px), rgba(103, 66, 37, 0.9) calc(33.333% + 3px), transparent calc(33.333% + 3px), transparent calc(66.666% - 3px), rgba(232, 203, 146, 0.72) calc(66.666% - 3px), rgba(103, 66, 37, 0.9) calc(66.666% + 3px), transparent calc(66.666% + 3px));
  border-radius: 18px;
}

.relic-board__piece {
  position: absolute;
  width: 92px;
  height: 92px;
  filter: drop-shadow(0 8px 10px rgba(0, 0, 0, 0.22));
}

.relic-board__piece--x {
  top: 40px;
  left: 50px;
}

.relic-board__piece--x::before,
.relic-board__piece--x::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(75, 52, 38, 0.15), rgba(34, 21, 13, 0.7), rgba(208, 174, 116, 0.45));
  border-radius: 999px;
  clip-path: polygon(40% 0, 60% 0, 100% 35%, 100% 58%, 60% 100%, 40% 100%, 0 60%, 0 35%);
}

.relic-board__piece--x::before { transform: rotate(45deg); }
.relic-board__piece--x::after { transform: rotate(-45deg); }

.relic-board__piece--o {
  right: 46px;
  bottom: 56px;
  border-radius: 50%;
  background:
    radial-gradient(circle, transparent 43%, rgba(58, 36, 20, 0.74) 44%, rgba(213, 184, 120, 0.9) 57%, rgba(95, 62, 30, 0.88) 64%, transparent 65%);
}

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

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

.side-panel,
.board-panel {
  padding: 20px;
  border-radius: var(--radius-md);
  background:
    linear-gradient(180deg, rgba(251, 243, 221, 0.86), rgba(231, 204, 153, 0.86));
  border: 1px solid rgba(120, 80, 44, 0.34);
  box-shadow: var(--panel-shadow);
}

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

.score-panel {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.score-chip {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(117, 78, 42, 0.32);
  background: rgba(251, 243, 221, 0.76);
}

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

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

.meta-list {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.info-ribbon {
  min-height: 56px;
  margin-top: 18px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: rgba(82, 50, 30, 0.08);
  border: 1px solid rgba(118, 80, 47, 0.22);
  color: var(--ink-soft);
  font-size: 1.04rem;
}

.board-shell {
  position: relative;
  width: min(100%, 38rem);
  margin-inline: auto;
}

.board {
  position: relative;
  aspect-ratio: 1;
  padding: 14px;
  border-radius: 30px;
  background:
    radial-gradient(circle at 50% 8%, rgba(255, 241, 211, 0.34), transparent 26%),
    linear-gradient(180deg, rgba(73, 49, 29, 0.24), rgba(35, 21, 12, 0.32)),
    linear-gradient(145deg, #9b6839, #714325 65%, #4c2d18);
  box-shadow:
    inset 0 0 0 7px rgba(68, 42, 25, 0.65),
    inset 0 0 0 16px rgba(224, 190, 128, 0.16),
    0 26px 42px rgba(24, 14, 8, 0.4);
}

.board--locked {
  filter: saturate(0.94);
}

.board-cell {
  position: relative;
  min-width: 0;
  border: 0;
  border-radius: 18px;
  background:
    linear-gradient(180deg, rgba(245, 228, 191, 0.72), rgba(207, 173, 115, 0.38)),
    linear-gradient(135deg, rgba(45, 28, 17, 0.12), rgba(255, 255, 255, 0));
  box-shadow:
    inset 0 0 0 2px rgba(80, 52, 29, 0.36),
    inset 0 0 18px rgba(255, 244, 220, 0.12);
  color: inherit;
  cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition), filter var(--transition);
}

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

.board-cell:hover:not(:disabled),
.board-cell:focus-visible:not(:disabled) {
  transform: translateY(-2px);
  box-shadow:
    inset 0 0 0 2px rgba(88, 56, 31, 0.48),
    0 14px 24px rgba(52, 30, 16, 0.16);
  outline: none;
}

.board-cell:disabled {
  cursor: default;
}

.board-cell--winning {
  background:
    linear-gradient(180deg, rgba(255, 235, 183, 0.92), rgba(209, 168, 83, 0.52)),
    linear-gradient(135deg, rgba(45, 28, 17, 0.1), rgba(255, 255, 255, 0));
  box-shadow:
    inset 0 0 0 2px rgba(112, 80, 38, 0.62),
    0 0 0 3px rgba(231, 203, 141, 0.38),
    0 18px 30px rgba(87, 56, 21, 0.18);
}

.board-cell--fresh {
  animation: pulseGlow 520ms ease;
}

.board-cell__content {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
}

.piece {
  width: 74%;
  height: 74%;
  opacity: 0;
  transform: scale(0.72) rotate(-3deg);
  animation: pieceAppear 240ms ease forwards;
  filter: drop-shadow(0 8px 10px rgba(0, 0, 0, 0.18));
}

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

.piece--x svg {
  fill: url(#ancientXFill);
}

.piece--o svg {
  fill: url(#ancientOFill);
}

.board__line {
  position: absolute;
  height: 10px;
  border-radius: 999px;
  background:
    linear-gradient(90deg, rgba(235, 219, 167, 0.1), rgba(235, 219, 167, 0.92), rgba(118, 76, 33, 0.86), rgba(235, 219, 167, 0.92), rgba(235, 219, 167, 0.08));
  box-shadow: 0 0 0 2px rgba(95, 64, 31, 0.16), 0 0 20px rgba(232, 198, 126, 0.4);
  transform-origin: center;
  animation: trailIn 420ms ease;
}

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

.ornate-btn {
  position: relative;
  padding: 14px 18px;
  border-radius: 14px;
  background:
    linear-gradient(180deg, #d4b179, #b18145 52%, #85552c);
  color: #26160d;
  font-family: "Cinzel", serif;
  font-weight: 700;
  letter-spacing: 0.03em;
  box-shadow:
    inset 0 0 0 2px rgba(255, 235, 193, 0.32),
    0 12px 18px rgba(41, 24, 14, 0.22);
}

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

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

.ghost-btn {
  padding: 12px 16px;
  border-radius: 14px;
  background: rgba(91, 60, 36, 0.1);
  border: 1px solid rgba(102, 68, 38, 0.28);
  color: var(--ink);
  font-weight: 700;
}

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

.ornate-btn:hover,
.ornate-btn:focus-visible,
.ghost-btn:hover,
.ghost-btn: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(111, 74, 42, 0.36);
  background: rgba(255, 249, 233, 0.85);
  color: var(--ink);
  font-size: 1.1rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.field-input:focus {
  outline: 2px solid rgba(186, 145, 79, 0.52);
  border-color: rgba(111, 74, 42, 0.5);
}

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

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

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

.modal-card {
  position: relative;
  width: min(520px, 100%);
  padding: 26px;
  border-radius: 26px;
  background:
    linear-gradient(180deg, rgba(248, 235, 202, 0.98), rgba(222, 193, 139, 0.94));
  border: 1px solid rgba(123, 82, 45, 0.44);
  box-shadow: var(--shadow);
  z-index: 1;
  animation: fadeUp 220ms ease;
}

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

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

.toast {
  min-width: min(320px, calc(100vw - 36px));
  max-width: 360px;
  padding: 14px 16px;
  border-radius: 16px;
  background: rgba(37, 22, 13, 0.88);
  color: #f6ead0;
  box-shadow: 0 16px 24px rgba(0, 0, 0, 0.24);
  border: 1px solid rgba(224, 193, 132, 0.22);
  animation: fadeUp 220ms ease;
}

.toast--error { background: rgba(111, 47, 37, 0.92); }
.toast--success { background: rgba(62, 85, 50, 0.92); }

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

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

.loading-card {
  position: relative;
  width: min(320px, calc(100vw - 34px));
  padding: 24px;
  border-radius: 24px;
  background:
    linear-gradient(180deg, rgba(247, 234, 202, 0.98), rgba(220, 189, 136, 0.94));
  border: 1px solid rgba(122, 79, 43, 0.4);
  box-shadow: var(--shadow);
  text-align: center;
}

.spinner {
  width: 52px;
  height: 52px;
  margin: 0 auto 14px;
  border-radius: 50%;
  border: 4px solid rgba(137, 94, 50, 0.22);
  border-top-color: rgba(137, 94, 50, 0.82);
  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.72) rotate(-8deg);
  }
  to {
    opacity: 1;
    transform: scale(1) rotate(0);
  }
}

@keyframes trailIn {
  from {
    opacity: 0;
    transform: translate(-50%, -50%) scaleX(0.2);
  }
}

@keyframes pulseGlow {
  0% {
    box-shadow: inset 0 0 0 2px rgba(88, 56, 31, 0.48), 0 0 0 0 rgba(229, 201, 143, 0.46);
  }
  100% {
    box-shadow: inset 0 0 0 2px rgba(88, 56, 31, 0.48), 0 0 0 14px rgba(229, 201, 143, 0);
  }
}

@keyframes drift {
  0% {
    transform: translate3d(0, 0, 0) scale(0.7);
  }
  50% {
    transform: translate3d(40px, -25px, 0) scale(1);
  }
  100% {
    transform: translate3d(-22px, -54px, 0) scale(0.78);
  }
}

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

  .relic-board {
    max-width: 320px;
  }
}

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

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

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

  .frame__topbar {
    flex-wrap: wrap;
  }

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

  .board {
    padding: 10px;
    gap: 9px;
  }

  .board-cell {
    border-radius: 14px;
  }

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

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

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

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