:root {
  --paper: #f4ead5;
  --paper-deep: #e8d9ba;
  --ink: #2b2118;
  --ink-soft: #5b4a37;
  --wood-light: #e9c89a;
  --wood-dark: #9a6b43;
  --wood-frame: #5a3d28;
  --gold: #c8922c;
  --gold-bright: #e6b85c;
  --moss: #5d7a52;
  --berry: #a23b3b;
  --sky: #6d8aa8;
  --highlight: rgba(200, 146, 44, 0.45);
  --move-dot: rgba(93, 122, 82, 0.55);
  --check: rgba(162, 59, 59, 0.55);
  --shadow: 0 18px 40px -18px rgba(43, 33, 24, 0.55);
  --radius: 18px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Nunito', system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 20% 10%, rgba(230, 184, 92, 0.18), transparent 45%),
    radial-gradient(circle at 85% 80%, rgba(109, 138, 168, 0.16), transparent 40%),
    linear-gradient(160deg, #f8f0de 0%, #efe2c6 100%);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}

/* paper grain overlay */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.035'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 9999;
  mix-blend-mode: multiply;
}

#app { max-width: 980px; margin: 0 auto; padding: 24px 18px 60px; }

h1, h2, h3, .display { font-family: 'Fraunces', Georgia, serif; }

/* ---- Header ---- */
.masthead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand .crest {
  width: 54px; height: 54px;
  display: grid; place-items: center;
  font-size: 30px;
  background: radial-gradient(circle at 35% 30%, var(--gold-bright), var(--gold));
  color: #3a2a14;
  border-radius: 16px;
  box-shadow: var(--shadow), inset 0 2px 4px rgba(255,255,255,0.4);
  transform: rotate(-4deg);
}
.brand h1 { font-size: 28px; font-weight: 700; line-height: 1; letter-spacing: -0.5px; }
.brand .tag { font-size: 13px; color: var(--ink-soft); font-weight: 600; }

.identity {
  display: flex; align-items: center; gap: 10px;
  background: rgba(255,255,255,0.5);
  border: 1.5px solid var(--paper-deep);
  border-radius: 999px;
  padding: 6px 8px 6px 16px;
  box-shadow: 0 4px 14px -8px rgba(43,33,24,0.4);
}
.identity .who { display: flex; flex-direction: column; line-height: 1.1; }
.identity .who .nm { font-weight: 800; font-size: 14px; }
.identity .who .rt { font-size: 12px; color: var(--gold); font-weight: 700; }
.identity button {
  border: none; background: var(--ink); color: var(--paper);
  width: 34px; height: 34px; border-radius: 999px; cursor: pointer;
  font-size: 15px; transition: transform .15s;
}
.identity button:hover { transform: scale(1.08); }

/* ---- Cards / panels ---- */
.card {
  background: rgba(255, 252, 245, 0.78);
  border: 1.5px solid var(--paper-deep);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(4px);
}

/* ---- Home ---- */
.home-hero { text-align: center; margin-bottom: 26px; }
.home-hero h2 { font-size: clamp(26px, 5vw, 40px); font-weight: 700; letter-spacing: -1px; }
.home-hero p { color: var(--ink-soft); font-weight: 600; margin-top: 8px; font-size: 16px; }

.mode-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 640px) { .mode-grid { grid-template-columns: 1fr; } }

.mode {
  text-align: left; cursor: pointer; border: none;
  font: inherit; color: inherit;
  position: relative; overflow: hidden;
  transition: transform .2s, box-shadow .2s;
}
.mode:hover { transform: translateY(-4px); box-shadow: 0 26px 46px -20px rgba(43,33,24,0.6); }
.mode .icon { font-size: 40px; margin-bottom: 10px; display: block; }
.mode h3 { font-size: 22px; font-weight: 700; margin-bottom: 6px; }
.mode p { color: var(--ink-soft); font-weight: 600; font-size: 14px; }
.mode .corner {
  position: absolute; top: -20px; right: -20px;
  width: 90px; height: 90px; border-radius: 50%;
  background: radial-gradient(circle, rgba(200,146,44,0.18), transparent 70%);
}

.section-title {
  font-size: 15px; font-weight: 800; text-transform: uppercase;
  letter-spacing: 1.5px; color: var(--ink-soft); margin: 28px 0 12px;
  display: flex; align-items: center; gap: 10px;
}
.section-title::after { content: ""; flex: 1; height: 1.5px; background: var(--paper-deep); }

/* ---- Game layout ---- */
.game-wrap { display: grid; grid-template-columns: minmax(0,1fr) 280px; gap: 22px; align-items: start; }
@media (max-width: 820px) { .game-wrap { grid-template-columns: 1fr; } }

.board-frame {
  background: linear-gradient(145deg, var(--wood-frame), #43301f);
  padding: 16px; border-radius: 16px;
  box-shadow: var(--shadow), inset 0 0 0 2px rgba(255,255,255,0.06);
}
.board {
  display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr);
  width: 100%; aspect-ratio: 1; border-radius: 6px; overflow: hidden;
  box-shadow: inset 0 0 18px rgba(0,0,0,0.35);
}
.sq {
  position: relative; display: grid; place-items: center;
  cursor: pointer; user-select: none;
  font-size: clamp(22px, 7.5vw, 46px); line-height: 1;
}
.sq.light { background: var(--wood-light); }
.sq.dark { background: var(--wood-dark); }
.sq .piece { transition: transform .12s; filter: drop-shadow(0 2px 2px rgba(0,0,0,0.25)); }
.sq.sel::after {
  content: ""; position: absolute; inset: 0;
  background: var(--highlight); box-shadow: inset 0 0 0 3px var(--gold);
}
.sq.target::before {
  content: ""; position: absolute; width: 32%; height: 32%;
  border-radius: 50%; background: var(--move-dot);
}
.sq.target.capture::before {
  width: 86%; height: 86%; background: transparent;
  border: 5px solid var(--move-dot); box-sizing: border-box;
}
.sq.check::after {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(circle, var(--check), transparent 70%);
}
.sq.last { box-shadow: inset 0 0 0 4px rgba(230,184,92,0.5); }
.coord { position: absolute; font-size: 9px; font-weight: 800; opacity: 0.5; }
.coord.file { bottom: 2px; right: 3px; }
.coord.rank { top: 2px; left: 3px; }

/* player tags */
.seat {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; border-radius: 12px;
  background: rgba(255,252,245,0.7); border: 1.5px solid var(--paper-deep);
  margin: 0 0 10px;
}
.seat.bottom { margin: 10px 0 0; }
.seat .nm { font-weight: 800; display: flex; align-items: center; gap: 8px; }
.seat .dot { width: 9px; height: 9px; border-radius: 50%; background: #c0392b; }
.seat .dot.on { background: var(--moss); box-shadow: 0 0 8px var(--moss); }
.seat .clk { font-family: 'Fraunces'; font-weight: 600; color: var(--gold); }
.seat .turn-pill {
  font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: 1px;
  background: var(--gold); color: #3a2a14; padding: 3px 9px; border-radius: 999px;
}

/* side panel */
.side { display: flex; flex-direction: column; gap: 16px; }
.status-card { text-align: center; }
.status-card .big { font-family: 'Fraunces'; font-size: 22px; font-weight: 700; }
.status-card .sub { color: var(--ink-soft); font-weight: 600; font-size: 14px; margin-top: 4px; }
.moves {
  max-height: 220px; overflow-y: auto;
  display: grid; grid-template-columns: auto 1fr 1fr; gap: 2px 8px;
  font-size: 14px; font-weight: 600;
}
.moves .num { color: var(--ink-soft); }
.moves .mv { padding: 2px 6px; border-radius: 6px; }
.moves .mv.hl { background: var(--highlight); }

/* buttons */
.btn {
  font: inherit; font-weight: 800; cursor: pointer;
  border: none; border-radius: 12px; padding: 13px 18px;
  background: var(--ink); color: var(--paper);
  transition: transform .15s, box-shadow .15s; width: 100%;
  box-shadow: 0 8px 18px -10px rgba(43,33,24,0.7);
}
.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(0); }
.btn.gold { background: linear-gradient(135deg, var(--gold-bright), var(--gold)); color: #3a2a14; }
.btn.ghost { background: transparent; color: var(--ink); border: 2px solid var(--ink); box-shadow: none; }
.btn.berry { background: var(--berry); }
.btn.small { padding: 9px 14px; font-size: 13px; width: auto; }
.btn-row { display: flex; gap: 10px; }

/* share link box */
.share { display: flex; gap: 8px; margin-top: 12px; }
.share input {
  flex: 1; font: inherit; font-weight: 600; padding: 11px 14px;
  border: 1.5px solid var(--paper-deep); border-radius: 12px;
  background: rgba(255,255,255,0.6); color: var(--ink);
}

/* leaderboard / history */
.row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 11px 14px; border-radius: 12px;
  background: rgba(255,252,245,0.55); margin-bottom: 8px;
}
.row .rank { font-family: 'Fraunces'; font-weight: 700; color: var(--gold); width: 28px; }
.row .who { flex: 1; font-weight: 700; }
.row .score { font-weight: 800; color: var(--ink-soft); }
.row .res-w { color: var(--moss); font-weight: 800; }
.row .res-l { color: var(--berry); font-weight: 800; }
.row .res-d { color: var(--ink-soft); font-weight: 800; }

/* modal */
.overlay {
  position: fixed; inset: 0; background: rgba(43,33,24,0.55);
  display: grid; place-items: center; z-index: 100; padding: 20px;
  backdrop-filter: blur(3px);
}
.modal { max-width: 380px; width: 100%; text-align: center; }
.modal h2 { font-size: 26px; margin-bottom: 6px; }
.modal p { color: var(--ink-soft); font-weight: 600; margin-bottom: 18px; }
.modal input {
  width: 100%; font: inherit; font-weight: 700; padding: 13px 16px;
  border: 1.5px solid var(--paper-deep); border-radius: 12px;
  background: rgba(255,255,255,0.7); margin-bottom: 14px; text-align: center;
}
.diff-grid { display: grid; gap: 8px; margin-bottom: 6px; }
.diff {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; border-radius: 12px; cursor: pointer;
  border: 2px solid var(--paper-deep); background: rgba(255,255,255,0.4);
  font-weight: 700; transition: all .15s;
}
.diff:hover, .diff.on { border-color: var(--gold); background: var(--highlight); }
.diff small { color: var(--ink-soft); font-weight: 600; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--paper); padding: 12px 22px;
  border-radius: 999px; font-weight: 700; z-index: 200;
  box-shadow: var(--shadow); animation: pop .3s;
}
@keyframes pop { from { opacity: 0; transform: translate(-50%, 12px); } }

.fade-in { animation: fade .4s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(8px); } }

.back-link {
  background: none; border: none; font: inherit; font-weight: 700;
  color: var(--ink-soft); cursor: pointer; margin-bottom: 16px;
  display: inline-flex; align-items: center; gap: 6px;
}
.back-link:hover { color: var(--ink); }

.choose-color { display: flex; gap: 10px; margin-top: 10px; }
.choose-color .diff { flex: 1; justify-content: center; }
