/* ==========================================================
   Catur Online — tema kayu klasik, kontras tinggi & responsif
   Audit ulang: mobile-first, dvh, tap target >=44px, AA contrast
   ========================================================== */
:root {
  --frame: url('wood-frame.jpg');
  --light: url('wood-light.jpg');
  --dark: url('wood-dark.jpg');

  --ink: #fdf6e9;          /* teks utama, kontras tinggi */
  --ink-2: #e8d9bf;        /* teks sekunder */
  --ink-dim: #c8b696;      /* teks tersier (AA di atas felt) */
  --gold: #e8bf74;
  --gold-strong: #f6d99b;
  --felt-1: #221812;
  --felt-2: #0d0907;
  --surface: rgba(255, 255, 255, .055);
  --surface-2: rgba(255, 255, 255, .09);
  --line: rgba(232, 191, 116, .28);
  --line-strong: rgba(232, 191, 116, .5);
  --danger: #ff9b86;
  --ok: #a8e6a3;

  --radius: 16px;
  --shadow-soft: 0 18px 45px rgba(0, 0, 0, .55);
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Georgia, "Times New Roman", serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; padding: 0; }

body {
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  color: var(--ink);
  background:
    radial-gradient(120% 80% at 50% 0%, rgba(232, 191, 116, .14), transparent 62%),
    radial-gradient(140% 100% at 50% 110%, rgba(0, 0, 0, .85), transparent 60%),
    linear-gradient(160deg, var(--felt-1), var(--felt-2));
  background-attachment: fixed;
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed; inset: 0; z-index: 0;
  pointer-events: none;
  opacity: .3;
  background-image: radial-gradient(rgba(255, 255, 255, .05) 1px, transparent 1px);
  background-size: 3px 3px;
}

.wrap {
  position: relative; z-index: 1;
  max-width: 1180px;
  margin: 0 auto;
  padding: clamp(16px, 4vw, 30px) clamp(12px, 4vw, 24px) calc(48px + env(safe-area-inset-bottom));
}

:where(a, button, input, [tabindex]):focus-visible {
  outline: 3px solid var(--gold-strong);
  outline-offset: 2px;
  border-radius: 10px;
}

/* ---------- tipografi ---------- */
h1, h2, h3 { margin: 0 0 .45em; font-family: var(--serif); font-weight: 600; letter-spacing: .2px; line-height: 1.2; }
h1 { font-size: clamp(28px, 7vw, 44px); }
h2 { font-size: clamp(19px, 4.4vw, 23px); }
h3 { font-size: clamp(16px, 4vw, 19px); }

.brand { text-align: center; margin-bottom: clamp(20px, 5vw, 32px); }
.brand .kicker {
  font-size: 11px; font-weight: 700; letter-spacing: .3em;
  text-transform: uppercase; color: var(--gold); margin-bottom: 10px;
}
.brand h1 {
  color: var(--gold-strong);
  background: linear-gradient(180deg, #fff8ec, #e8bf74 62%, #b98c3c);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 2px 10px rgba(0, 0, 0, .4);
}
@supports not ((-webkit-background-clip: text) or (background-clip: text)) {
  .brand h1 { -webkit-text-fill-color: currentColor; color: var(--gold-strong); }
}
.brand p { margin: 6px auto 0; max-width: 46ch; }
.muted { color: var(--ink-dim); font-size: 14.5px; line-height: 1.65; }
.mono { font-family: var(--mono); }

/* ---------- panel ---------- */
.panel {
  position: relative;
  border-radius: var(--radius);
  padding: clamp(16px, 4.4vw, 24px);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, .085), rgba(0, 0, 0, .32)),
    rgba(18, 12, 8, .72);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-soft), inset 0 1px 0 rgba(255, 255, 255, .1);
  overflow: hidden;
}
.panel.dark { background: linear-gradient(180deg, rgba(255, 255, 255, .06), rgba(0, 0, 0, .38)), rgba(12, 8, 5, .75); }
.panel > h2:first-child, .panel > h3:first-child { margin-top: 0; }

.page-plain { display: grid; place-items: center; padding: 30px 16px; }
.page-plain .panel { max-width: 520px; }

/* ---------- form & tombol ---------- */
label {
  display: block; font-size: 11.5px; font-weight: 700; letter-spacing: .18em;
  text-transform: uppercase; color: var(--gold); margin: 16px 0 7px;
}
input[type=text] {
  width: 100%; padding: 14px; min-height: 50px;
  font-size: 16px; /* cegah zoom otomatis iOS */
  font-family: inherit;
  color: #241708;
  background: linear-gradient(180deg, #fdf7ea, #ece0c8);
  border: 1px solid rgba(0, 0, 0, .45);
  border-radius: 12px;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, .22);
}
input[type=text]::placeholder { color: #8a785d; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 13px 18px; min-height: 50px; width: 100%;
  font-family: var(--sans); font-size: 15.5px; font-weight: 700; line-height: 1.15;
  letter-spacing: .01em;
  border-radius: 12px; border: 1px solid rgba(0, 0, 0, .5);
  cursor: pointer; text-decoration: none; text-align: center;
  color: #2a1a07;
  background: linear-gradient(180deg, #f9e6c0, #d3ac60);
  transition: transform .12s ease, filter .12s ease, box-shadow .12s ease;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: translateY(1px); }
.btn-primary {
  color: #2a1a07;
  background: linear-gradient(180deg, #fbe9c2, #d6a745 55%, #b0812f);
  box-shadow: 0 8px 18px rgba(0, 0, 0, .45), inset 0 1px 0 rgba(255, 255, 255, .6);
}
.btn-ghost {
  color: var(--ink);
  background: linear-gradient(180deg, rgba(255, 255, 255, .13), rgba(255, 255, 255, .04));
  border-color: var(--line-strong);
}
.btn-ghost:hover { background: linear-gradient(180deg, rgba(255, 255, 255, .2), rgba(255, 255, 255, .07)); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; filter: none; }

.btn-row { display: grid; gap: 10px; grid-template-columns: 1fr 1fr; margin-top: 16px; }
@media (max-width: 400px) { .btn-row { grid-template-columns: 1fr; } }
.btn-row.single { grid-template-columns: 1fr; }
.stack { display: grid; gap: 12px; }

.grid-2 { display: grid; gap: 18px; align-items: start; }
@media (min-width: 860px) { .grid-2 { grid-template-columns: 1fr 1fr; gap: 24px; } }

.side-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.side-pick button {
  padding: 13px 10px; min-height: 50px; border-radius: 12px; cursor: pointer;
  font-family: var(--sans); font-size: 14px; font-weight: 600;
  color: var(--ink); background: rgba(0, 0, 0, .35);
  border: 1px solid var(--line);
}
.side-pick button[aria-pressed="true"] {
  color: #2a1a07; background: linear-gradient(180deg, #fbe9c2, #d6a745);
  border-color: #8b6524; font-weight: 800;
}

.error { margin-top: 12px; font-size: 14.5px; font-weight: 600; color: var(--danger); }
.notice { margin-top: 12px; font-size: 14.5px; font-weight: 600; color: var(--ok); }

/* ---------- layout meja ---------- */
.board-shell { display: grid; gap: 16px; justify-items: stretch; }
@media (min-width: 1000px) {
  .board-shell {
    grid-template-columns: minmax(0, 1fr) 340px;
    align-items: start;
    gap: 22px;
  }
  .board-col { display: grid; gap: 14px; min-width: 0; }
  .side-col { display: grid; gap: 14px; position: sticky; top: 22px; }
  .board-frame { max-width: min(100%, 620px, max(340px, calc(100dvh - 380px))); }
}
.board-col, .side-col { display: grid; gap: 14px; min-width: 0; }

/* ---------- papan catur ---------- */
.board-frame {
  position: relative;
  width: 100%;
  max-width: min(100%, 620px, max(320px, calc(100dvh - 300px)));
  margin: 0 auto;
  padding: clamp(10px, 3vw, 26px);
  border-radius: 14px;
  background-image: linear-gradient(160deg, #2b2b2b, #101010);
  background-size: cover;
  background-color: #1a1a1a;
  box-shadow:
    0 30px 60px rgba(0, 0, 0, .6),
    inset 0 1px 0 rgba(255, 255, 255, .12);
  border: 1px solid #000;
}
.board-frame::before {
  content: ""; position: absolute; inset: 0; border-radius: 14px; pointer-events: none;
  background: linear-gradient(150deg, rgba(255, 255, 255, .08), transparent 40%, rgba(0, 0, 0, .25));
}

.board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  aspect-ratio: 1 / 1;
  width: 100%;
  max-width: 100%;
  border-radius: 2px;
  overflow: hidden;
  box-shadow: 0 0 0 2px #000;
  touch-action: manipulation;
}

.sq {
  position: relative;
  width: 100%;
  height: 100%;
  aspect-ratio: 1 / 1;
  min-width: 0;
  min-height: 0;
  display: grid; place-items: center;
  cursor: default;
  background-color: #ffffff;
}
.sq.l { background-color: #ffffff; background-image: none; }
.sq.d { background-color: #111111; background-image: none; }
.sq.pickable { cursor: pointer; }

/* koordinat: kontras tinggi, tetap terbaca di layar kecil */
.sq .coord {
  position: absolute; z-index: 3;
  font-family: var(--sans);
  font-size: clamp(8px, 1.6vw, 11px);
  font-weight: 800; line-height: 1;
  letter-spacing: .04em;
  opacity: .95;
}
.sq .coord.f { right: 3px; bottom: 3px; }
.sq .coord.r { left: 3px; top: 3px; }
.sq.l .coord { color: #111111; text-shadow: none; }
.sq.d .coord { color: #ffffff; text-shadow: none; }

.piece {
  position: relative; z-index: 2;
  width: 92%; height: 92%;
  object-fit: contain;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, .45));
  transition: transform .12s ease;
  pointer-events: none;
  user-select: none; -webkit-user-drag: none;
}
/* jaga kontras bidak di kotak sewarna */
.sq.d .piece.pb {
  filter:
    drop-shadow(0 0 1px rgba(255, 255, 255, .95))
    drop-shadow(0 0 2px rgba(255, 255, 255, .8))
    drop-shadow(0 2px 3px rgba(0, 0, 0, .5));
}
.sq.l .piece.pw {
  filter:
    drop-shadow(0 0 1px rgba(0, 0, 0, .8))
    drop-shadow(0 0 2px rgba(0, 0, 0, .45))
    drop-shadow(0 2px 3px rgba(0, 0, 0, .35));
}
.sq.sel .piece { transform: translateY(-6%) scale(1.06); }

.sq.sel::before {
  content: ""; position: absolute; inset: 0; z-index: 1;
  background: radial-gradient(circle at 50% 55%, rgba(255, 214, 120, .6), rgba(255, 200, 80, .14) 70%);
  box-shadow: inset 0 0 0 3px rgba(255, 220, 140, .95);
}
.sq.last::before {
  content: ""; position: absolute; inset: 0; z-index: 1;
  background: rgba(255, 226, 150, .28);
  box-shadow: inset 0 0 0 2px rgba(255, 230, 160, .6);
}
.sq .dot {
  position: absolute; z-index: 3; width: 28%; height: 28%; border-radius: 50%;
  opacity: .85;
}
.sq.l .dot { background: rgba(0, 0, 0, .45); }
.sq.d .dot { background: rgba(255, 255, 255, .55); }
.sq.cap .ring {
  position: absolute; z-index: 3; inset: 6%; border-radius: 50%;
  border: 4px solid rgba(255, 130, 100, .9);
  box-shadow: 0 0 12px rgba(255, 90, 60, .65);
}
.sq.check::before {
  content: ""; position: absolute; inset: 0; z-index: 1;
  background: radial-gradient(circle, rgba(255, 70, 50, .72), transparent 72%);
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* ---------- kartu pemain ---------- */
.players { width: 100%; display: grid; gap: 10px; }
.pcard {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center; gap: 12px;
  padding: 12px 14px; border-radius: 14px;
  background: linear-gradient(180deg, rgba(255, 255, 255, .09), rgba(0, 0, 0, .34));
  border: 1px solid var(--line);
}
.pcard.active { border-color: var(--gold); box-shadow: 0 0 20px rgba(232, 191, 116, .3); }
.disc {
  width: 30px; height: 30px; border-radius: 50%; flex: none;
  box-shadow: inset 0 2px 4px rgba(255, 255, 255, .5), 0 3px 6px rgba(0, 0, 0, .5);
}
.disc.w { background: radial-gradient(circle at 35% 30%, #fffdf5, #d8c9a6); }
.disc.b { background: radial-gradient(circle at 35% 30%, #6a645c, #14110e); }
.pcard .who { display: block; font-size: 15.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pcard .tag { display: block; font-size: 11px; font-weight: 700; color: var(--ink-dim); letter-spacing: .12em; text-transform: uppercase; }
.pcard .turnflag {
  justify-self: end; white-space: nowrap;
  font-size: 10.5px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase;
  color: #2a1a07; background: linear-gradient(180deg, #fbe9c2, #d6a745);
  padding: 5px 9px; border-radius: 999px;
}

.statusbar {
  width: 100%; text-align: center;
  padding: 13px 14px; border-radius: 14px; font-size: 15.5px;
  background: linear-gradient(180deg, rgba(255, 255, 255, .08), rgba(0, 0, 0, .32));
  border: 1px solid var(--line);
}
.statusbar strong { color: var(--gold-strong); }

.invite { width: 100%; }
.invite .link {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: center; margin-top: 10px;
  padding: 10px; border-radius: 12px; background: rgba(0, 0, 0, .4);
  border: 1px solid var(--line);
}
.invite .link input { min-width: 0; font-size: 14px; padding: 11px 12px; min-height: 44px; }
.invite .code {
  font-family: var(--mono); font-size: clamp(24px, 8vw, 32px); font-weight: 700; line-height: 1.1;
  letter-spacing: .22em; text-indent: .22em; color: var(--gold-strong);
  text-align: center; padding: 8px 0 2px;
}
.copybtn { width: auto; padding: 10px 16px; min-height: 44px; }

.movelist { width: 100%; }
.movelist .scroll { max-height: 210px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.movelist table { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: 13.5px; }
.movelist td { padding: 6px 8px; border-bottom: 1px solid rgba(232, 191, 116, .14); }
.movelist td.n { color: var(--ink-dim); width: 40px; }

.actions { display: grid; gap: 10px; grid-template-columns: 1fr 1fr; }
.actions .full { grid-column: 1 / -1; }

/* ---------- dialog promosi ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50; display: none;
  place-items: center; padding: 20px;
  background: rgba(8, 5, 3, .82);
  -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
}
.overlay.on { display: grid; }
.promo { text-align: center; max-width: 400px; width: 100%; }
.promo .opts { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 14px; }
.promo .opts button {
  padding: 8px; border-radius: 12px; cursor: pointer; min-height: 56px;
  background: linear-gradient(180deg, rgba(255, 255, 255, .16), rgba(0, 0, 0, .3));
  border: 1px solid var(--line-strong);
}
.promo .opts button:hover { background: linear-gradient(180deg, rgba(255, 255, 255, .26), rgba(0, 0, 0, .25)); }
.promo .opts img { width: 100%; display: block; filter: drop-shadow(1px 3px 3px rgba(0, 0, 0, .6)); }

footer.credit {
  margin-top: 32px; text-align: center;
  font-size: 12.5px; color: var(--ink-dim); opacity: .85;
}

/* ---------- layar sangat kecil / landscape HP ---------- */
@media (max-height: 520px) and (orientation: landscape) {
  .board-frame { max-width: min(100%, 78vh); padding: 8px; }
}
