/* Kembar Tiga — token dari mockup Figma.
   Tema terang tetap: identitas game ini krem + ungu, bukan pilihan tema sistem. */
:root {
  --ink: #1F1A3D;
  --muted: #5B5577;
  --cream: #FFF3DC;
  --sand: #FFE7B8;
  --line: #E6DCC6;
  --purple: #6C4CF1;
  --purple-soft: #A893FF;
  --purple-text: #E3DDFF;
  --yellow: #FFC93C;
  --green: #22B07D;
  --green-text: #178A60;
  --red: #E5484D;
  --white: #FFFFFF;
  --r-panel: 20px;
  --r-btn: 14px;
  --r-chip: 8px;
  --stroke: 3px;
  --font-display: 'Lilita One', 'Arial Rounded MT Bold', system-ui, sans-serif;
  --font-ui: 'Fredoka', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--sand);
  color: var(--ink);
  font-family: var(--font-ui);
  font-weight: 500;
  -webkit-tap-highlight-color: transparent;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }
:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

#app {
  max-width: 480px;
  min-height: 100dvh;
  margin: 0 auto;
  background: var(--cream);
  position: relative;
  overflow-x: hidden;
}
@media (min-width: 520px) {
  #app { min-height: calc(100dvh - 32px); margin: 16px auto; border: 4px solid var(--ink); border-radius: 32px; overflow: hidden; }
}
.screen { padding: max(20px, env(safe-area-inset-top)) 16px calc(28px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 16px; min-height: inherit; }
.screen.purple { background: var(--purple); color: var(--white); }

/* ------------------------------------------------------------ tipografi */
.display { font-family: var(--font-display); font-weight: 400; letter-spacing: .01em; line-height: 1.05; margin: 0; }
.outlined { color: var(--white); -webkit-text-stroke: 5px var(--ink); paint-order: stroke fill; }
.h1 { font-size: clamp(30px, 9vw, 38px); }
.sub { color: var(--muted); font-size: 15px; margin: 0; }
.purple .sub { color: var(--purple-text); }
.label { font-weight: 700; font-size: 13px; color: var(--muted); letter-spacing: .08em; }

/* ------------------------------------------------------------ tombol */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 18px;
  background: var(--white); border: var(--stroke) solid var(--ink); border-radius: var(--r-btn);
  font-weight: 700; font-size: 16px; text-decoration: none; color: var(--ink);
  transition: transform .08s ease;
}
.btn:active:not(:disabled) { transform: translateY(2px); }
.btn:disabled { opacity: .45; }
.btn.sm { min-height: 44px; padding: 0 14px; font-size: 14px; border-width: 2.5px; }
.btn.yellow { background: var(--yellow); }
.btn.dark { background: var(--ink); color: var(--white); }
/* tombol utama: satu-satunya yang pill + bayangan solid */
.btn.primary {
  min-height: 60px; width: 100%; border-radius: 999px;
  background: var(--yellow); font-family: var(--font-display); font-weight: 400; font-size: 26px; letter-spacing: .02em;
  box-shadow: 0 6px 0 var(--ink); margin-bottom: 6px;
}
.btn.primary.violet { background: var(--purple); color: var(--white); }
.btn.primary:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 2px 0 var(--ink); }
.link-btn { display: inline-flex; align-items: center; min-height: 44px; background: none; border: 0; padding: 0 12px; font-weight: 600; color: inherit; text-decoration: underline; text-underline-offset: 3px; }
.icon-btn { width: 44px; height: 44px; min-height: 44px; padding: 0; border-radius: 12px; display: inline-grid; place-items: center; flex: none; }
.icon-btn svg { width: 22px; height: 22px; }

/* ------------------------------------------------------------ panel & chip */
.panel { background: var(--white); border: var(--stroke) solid var(--ink); border-radius: var(--r-panel); padding: 16px; }
.chip { display: inline-flex; align-items: center; height: 26px; padding: 0 10px; border: 2px solid var(--ink); border-radius: var(--r-chip); font-size: 12px; font-weight: 700; white-space: nowrap; }
.chip.host { background: var(--yellow); }
.chip.ready { background: #8BD346; }
.chip.wait { background: #E9E4F5; }
.trio-chip { display: inline-grid; place-items: center; width: 22px; height: 28px; border-radius: 6px; border: 2px solid var(--ink); background: var(--c); color: var(--white); font-weight: 700; font-size: 12px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-weight: 700; font-size: 14px; }
.input {
  height: 52px; padding: 0 14px; border: var(--stroke) solid var(--ink); border-radius: var(--r-btn); background: var(--white);
  font-size: 18px; font-weight: 600;
}
.input::placeholder { color: #9A93B3; font-weight: 500; }
.input.code { text-transform: uppercase; letter-spacing: .3em; font-family: var(--font-display); font-weight: 400; font-size: 22px; }
.row { display: flex; gap: 10px; align-items: center; }
.row > .grow { flex: 1; min-width: 0; }
.error { background: #FFE1E1; border: 2px solid var(--red); border-radius: 12px; padding: 10px 12px; font-weight: 600; font-size: 14px; }

.avatar { display: inline-block; width: var(--s); height: var(--s); flex: none; }
.avatar svg { width: 100%; height: 100%; display: block; }

/* ------------------------------------------------------------ kartu */
.cs { container-type: inline-size; flex: none; }
.card {
  position: relative; width: 100%; aspect-ratio: 180 / 252;
  background: var(--c); border: max(2px, 2.2cqw) solid var(--ink); border-radius: 13cqw;
  overflow: hidden; user-select: none; color: var(--ink);
  box-shadow: 0 max(2px, 3cqw) 0 var(--ink);
}
.card.face::before { /* pola titik khas kartu */
  content: ''; position: absolute; inset: 0;
  background-image: radial-gradient(circle, rgba(255,255,255,.2) 2.4cqw, transparent 2.6cqw);
  background-size: 24cqw 17cqw; background-position: 6cqw 30cqw;
}
.card.king::before { background-image: radial-gradient(circle, rgba(255,201,60,.18) 2.4cqw, transparent 2.6cqw); }
.card .num {
  position: absolute; left: 7cqw; top: 0; font-family: var(--font-display); font-size: 40cqw; line-height: 1.1;
  color: var(--white); -webkit-text-stroke: 2.4cqw var(--ink); paint-order: stroke fill;
}
.card.king .num { color: var(--yellow); }
.card .corner {
  position: absolute; right: 7cqw; top: 7cqw; width: 19cqw; height: 19cqw; display: grid; place-items: center;
  background: var(--white); border: 1.7cqw solid var(--ink); border-radius: 50%; font-weight: 700; font-size: 9cqw;
}
.card .monster { position: absolute; left: 18cqw; top: 46cqw; width: 64cqw; }
.card .name {
  position: absolute; left: 0; right: 0; bottom: 14cqw; text-align: center; font-weight: 700; font-size: 7.5cqw;
  color: var(--white); -webkit-text-stroke: 1.4cqw var(--ink); paint-order: stroke fill;
}
.card.king .name { color: var(--yellow); -webkit-text-stroke: 0; }
.card .king-note { position: absolute; left: 0; right: 0; bottom: 5cqw; text-align: center; font-weight: 700; font-size: 5.2cqw; color: var(--yellow); }
.card .link {
  position: absolute; bottom: 6cqw; width: 15.5cqw; height: 13.5cqw; display: grid; place-items: center;
  background: var(--c); border: 1.4cqw solid var(--ink); border-radius: 4.5cqw; color: var(--white); font-weight: 700; font-size: 7cqw;
}
.card .link.l { left: 6cqw; }
.card .link.r { right: 6cqw; }
.card.back { background: var(--purple); }
.card.back::before {
  content: ''; position: absolute; inset: 8cqw; border: 1.6cqw dashed var(--yellow); border-radius: 9cqw;
}
.card .back-badge {
  position: absolute; left: 19cqw; top: 31cqw; width: 62cqw; height: 62cqw; display: grid; place-items: center;
  background: var(--yellow); border: 2.2cqw solid var(--ink); border-radius: 50%;
  font-family: var(--font-display); font-size: 44cqw; color: var(--white); -webkit-text-stroke: 2.2cqw var(--ink); paint-order: stroke fill;
}
.card .back-title {
  position: absolute; left: 0; right: 0; bottom: 12cqw; text-align: center; font-family: var(--font-display); font-size: 11cqw; line-height: 1;
  color: var(--white); -webkit-text-stroke: 1.6cqw var(--ink); paint-order: stroke fill;
}
.card.flip { animation: flip .32s ease-out; }
@keyframes flip { from { transform: rotateY(90deg) scale(.9); } to { transform: none; } }
.card.pop { animation: pop .4s ease-out; }
@keyframes pop { 0% { transform: scale(.6); } 70% { transform: scale(1.08); } 100% { transform: none; } }

/* ------------------------------------------------------------ home */
.home-hero { background: var(--purple); margin: -20px -16px 0; padding: 28px 16px 36px; border-radius: 0 0 50% 50% / 0 0 36px 36px; text-align: center; color: var(--white); }
.fan { display: flex; justify-content: center; align-items: flex-end; height: 132px; margin-bottom: 10px; }
.fan .cs { width: 76px; margin: 0 -8px; }
.fan .cs:nth-child(1) { transform: rotate(-14deg) translateY(10px); }
.fan .cs:nth-child(2) { width: 84px; z-index: 1; }
.fan .cs:nth-child(3) { transform: rotate(14deg) translateY(10px); }
.home-hero .display { font-size: clamp(36px, 12vw, 48px); }
.home-hero p { margin: 8px 0 0; font-weight: 600; }
.or { display: flex; align-items: center; gap: 12px; color: var(--muted); font-weight: 600; font-size: 14px; }
.or::before, .or::after { content: ''; flex: 1; height: 2px; background: var(--line); }
details.rules { border: 2.5px solid var(--ink); border-radius: var(--r-panel); background: var(--white); padding: 0 16px; }
details.rules summary { padding: 14px 0; font-weight: 700; cursor: pointer; }
details.rules ol { margin: 0 0 16px; padding-left: 20px; line-height: 1.5; }
details.rules li + li { margin-top: 6px; }

/* ------------------------------------------------------------ lobby */
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.code-box { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.code-box .display { font-size: clamp(32px, 11vw, 44px); letter-spacing: .12em; }
.code-box .btn { white-space: nowrap; }
.players { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.player-row { display: flex; align-items: center; gap: 12px; background: var(--white); border: 2.5px solid var(--ink); border-radius: 18px; padding: 8px 12px 8px 8px; }
.player-row .pname { flex: 1; font-weight: 700; font-size: 17px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty-slot { border: 2.5px dashed #B5AECB; border-radius: 18px; padding: 12px; text-align: center; color: var(--muted); font-weight: 600; font-size: 14px; }
.segmented { display: inline-flex; border: 2.5px solid var(--ink); border-radius: 12px; background: var(--white); padding: 2px; }
.segmented button { border: 0; background: none; border-radius: 9px; min-height: 44px; padding: 0 12px; font-weight: 700; font-size: 13px; }
.segmented button[aria-pressed="true"] { background: var(--ink); color: var(--white); }
.segmented button:disabled { cursor: default; }
.lobby-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; }
.hint { text-align: center; font-size: 13px; color: var(--muted); margin: 0; }
.purple .hint { color: var(--purple-text); }

/* ------------------------------------------------------------ meja */
.table { background: var(--purple); color: var(--white); padding: max(12px, env(safe-area-inset-top)) 12px 0; gap: 12px; }
.turnbar { display: flex; align-items: center; gap: 10px; background: var(--ink); border-radius: 18px; padding: 6px 6px 6px 8px; }
.turnbar .who { flex: 1; min-width: 0; }
.turnbar .who b { display: block; font-family: var(--font-display); font-weight: 400; font-size: 20px; color: var(--yellow); line-height: 1.1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.turnbar .who span { font-size: 13px; color: #C9C2EA; }
.timer { background: var(--yellow); color: var(--ink); border-radius: 10px; padding: 4px 10px; font-weight: 700; font-variant-numeric: tabular-nums; }
.timer.low { background: #FF8A8A; }
.turnbar .icon-btn { background: transparent; border: 2px solid #3B3463; color: var(--white); }

.opponents { display: flex; gap: 8px; overflow-x: auto; scroll-snap-type: x mandatory; padding-bottom: 4px; margin: 0 -12px; padding-left: 12px; padding-right: 12px; scrollbar-width: none; }
/* Panel lawan: 4 baris dengan tinggi tetap (mockup "Panel lawan — anatomi").
   identitas 48 · kartu 38 · trio 24 · tombol 44 → semua panel sama tinggi, tombol selalu sejajar */
.opp { scroll-snap-align: start; flex: none; width: 132px; background: var(--cream); color: var(--ink); border: var(--stroke) solid var(--ink); border-radius: 18px; padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.opp.active { background: var(--yellow); }
.opp-head { display: flex; gap: 6px; align-items: flex-start; min-width: 0; height: 48px; }
.opp-head .avatar { margin-top: 1px; }
.opp-head > div { min-width: 0; }
.opp-head b { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; font-size: 14px; line-height: 1.1; overflow-wrap: anywhere; }
.opp-head small { display: block; margin-top: 2px; font-size: 11px; line-height: 1.2; color: var(--muted); }
.opp-cards { display: flex; align-items: center; justify-content: center; gap: 2px; height: 38px; flex: none; } /* maks 4 kartu × 26 + 3 × 2 = 110px = lebar isi panel */
.opp-cards .cs { width: 26px; }
.opp-cards .none { color: var(--muted); font-weight: 700; }
.opp-stack { display: flex; }
.opp-stack .cs + .cs { margin-left: -18px; }
.opp-trios { display: flex; gap: 4px; justify-content: center; align-items: center; height: 24px; flex: none; }
.opp-trios .trio-chip { width: 18px; height: 24px; font-size: 10px; border-radius: 5px; }
.opp-trios .empty { font-size: 11px; color: var(--muted); font-weight: 500; }
.opp-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: auto; padding-top: 2px; }
.opp-btns .btn { min-height: 44px; padding: 0; font-size: 14px; border-radius: 12px; border-width: 2.5px; }

.middle-head { display: flex; justify-content: space-between; align-items: baseline; }
.middle-head b { font-size: 14px; }
.middle-head span { font-size: 12px; color: #C9C2EA; }
.middle { display: grid; grid-template-columns: repeat(var(--cols, 3), minmax(0, 80px)); justify-content: center; gap: 12px 10px; }
.slot .cs { width: 100%; }
.slot { border: 0; background: none; padding: 0; border-radius: 12px; }
.slot:disabled { cursor: default; }
.slot.gone { border: 2.5px dashed var(--purple-soft); aspect-ratio: 180 / 252; }
.slot.can:hover .card, .slot.can:focus-visible .card { transform: translateY(-3px); }
.slot .card { transition: transform .12s ease; }
.slot.up .card { outline: 4px solid var(--yellow); outline-offset: 2px; }

.tray { background: var(--cream); color: var(--ink); border: var(--stroke) solid var(--ink); border-radius: 18px; padding: 10px 12px; display: flex; align-items: center; gap: 10px; min-height: 76px; }
.tray-cards { display: flex; gap: 4px; }
.tray-cards .cs { width: 34px; }
.tray-cards .ghost { width: 34px; aspect-ratio: 180 / 252; border: 2px dashed #B5AECB; border-radius: 6px; display: grid; place-items: center; font-family: var(--font-display); color: #B5AECB; }
.tray-msg { flex: 1; min-height: 40px; display: grid; place-items: center; text-align: center; border-radius: 14px; border: 2.5px solid var(--ink); font-weight: 700; font-size: 15px; padding: 6px 10px; background: var(--white); }
.tray-msg.good { background: var(--green); color: var(--white); }
.tray-msg.bad { background: var(--red); color: var(--white); }
.tray-msg.gold { background: var(--yellow); }

.myhand { margin: 0 -12px; margin-top: auto; background: var(--cream); color: var(--ink); border-top: 4px solid var(--ink); border-radius: 28px 28px 0 0; padding: 12px 16px calc(16px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 10px; }
.myhand.active { background: #FFF8E8; }
.myhand-head { display: flex; justify-content: space-between; align-items: center; }
.myhand-head b { font-size: 16px; }
.mytrios { display: flex; gap: 4px; align-items: center; font-size: 13px; color: var(--muted); font-weight: 600; }
.hand { display: flex; justify-content: center; padding: 10px 0 4px; min-height: 104px; }
.hand .cs { width: 62px; transition: transform .15s ease; }
.hand .cs + .cs { margin-left: var(--ov, -9px); }
.hand .cs.up { transform: translateY(-12px); }
.hand .cs.up .card { outline: 4px solid var(--yellow); outline-offset: 1px; }
.hand-empty { color: var(--muted); font-weight: 600; align-self: center; }
.hand-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ------------------------------------------------------------ menang */
.overlay { position: absolute; inset: 0; z-index: 20; display: flex; flex-direction: column; overflow-y: auto; }
.win { background: var(--purple); color: var(--white); text-align: center; padding: 52px 16px 28px; gap: 14px; }
.confetti { position: absolute; inset: 0 0 auto; height: 320px; pointer-events: none; overflow: hidden; }
.confetti i { position: absolute; top: -20px; width: 10px; height: 16px; border-radius: 2px; animation: fall 2.6s ease-in forwards; }
@keyframes fall { to { transform: translateY(360px) rotate(540deg); opacity: 0; } }
.win .winner-avatar { position: relative; width: 104px; margin: 30px auto 0; }
.win .winner-avatar .crown { position: absolute; left: 50%; top: -30px; width: 52px; transform: translateX(-50%); }
.win .display.big { font-size: clamp(30px, 10vw, 42px); overflow-wrap: anywhere; }
.trio-stacks { display: flex; justify-content: center; gap: 18px; flex-wrap: wrap; padding: 6px 0 8px; }
.stack { position: relative; width: 72px; height: 112px; }
.stack .cs { position: absolute; width: 64px; }
.stack .cs:nth-child(1) { left: 0; top: 0; transform: rotate(-6deg); }
.stack .cs:nth-child(2) { left: 4px; top: 3px; }
.stack .cs:nth-child(3) { left: 8px; top: 6px; transform: rotate(6deg); }
.score { list-style: none; margin: 0; padding: 0; text-align: left; }
.score li { display: flex; align-items: center; gap: 10px; padding: 6px 0; font-weight: 700; }
.score li + li { border-top: 1.5px solid var(--line); }
.score .t { margin-left: auto; color: var(--muted); font-weight: 600; }
.score .win-t { color: var(--green-text); }
.win .panel { color: var(--ink); }

/* ------------------------------------------------------------ share sheet */
.sheet-backdrop { position: absolute; inset: 0; z-index: 30; background: rgba(31, 26, 61, .55); display: flex; align-items: flex-end; }
.sheet { width: 100%; background: var(--cream); border-top: 4px solid var(--ink); border-radius: 32px 32px 0 0; padding: 12px 16px calc(24px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 12px; animation: up .22s ease-out; max-height: 100%; overflow-y: auto; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.sheet .grab { width: 48px; height: 6px; border-radius: 3px; background: #C4B9A0; margin: 0 auto 4px; }
.share-preview { width: min(240px, 62vw); margin: 0 auto; border: 3px solid var(--ink); border-radius: 18px; display: block; box-shadow: 0 5px 0 var(--ink); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ------------------------------------------------------------ leaderboard */
.podium { display: grid; grid-template-columns: 1fr 1fr 1fr; align-items: end; gap: 10px; padding-top: 34px; }
.pod { display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0; }
.pod .pname { font-weight: 700; font-size: 15px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pod-block { width: 100%; border: var(--stroke) solid var(--ink); border-radius: 14px; background: var(--white); text-align: center; padding: 6px 4px; }
.pod-block .display { font-size: 30px; }
.pod-block small { display: block; font-weight: 600; font-size: 12px; }
.pod.first .pod-block { background: var(--yellow); height: 100px; box-shadow: 0 5px 0 var(--ink); }
.pod.first .pod-block .display { font-size: 38px; }
.pod.second .pod-block { height: 74px; }
.pod.third .pod-block { height: 58px; }
.pod .crown-wrap { position: relative; }
.pod .crown { position: absolute; left: 50%; top: -24px; width: 30px; transform: translateX(-50%); }
.rank-table { width: 100%; border-collapse: collapse; }
.rank-table th { font-size: 11px; color: var(--muted); text-align: left; font-weight: 700; padding: 0 4px 6px; }
.rank-table td { padding: 6px 4px; border-top: 1.5px solid var(--line); font-weight: 700; font-size: 16px; }
.rank-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.rank-table .muted { color: var(--muted); font-weight: 500; }
.rank-table .who { display: flex; align-items: center; gap: 8px; }
.me-row { display: flex; align-items: center; gap: 10px; background: var(--yellow); border: var(--stroke) solid var(--ink); border-radius: 18px; padding: 8px 12px; }
.me-row .grow small { display: block; font-size: 12px; font-weight: 500; }
.empty-state { text-align: center; padding: 28px 12px; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.empty-state .ghosts { display: flex; gap: 6px; }
.empty-state .ghosts span { width: 54px; aspect-ratio: 180/252; border: 2.5px dashed #C4B9A0; border-radius: 10px; }
.empty-state .ghosts span:nth-child(2) { transform: translateY(-12px); }
.spinner-line { text-align: center; color: var(--muted); font-weight: 600; padding: 24px 0; }

/* ------------------------------------------------------------ toast */
.toast-wrap { position: fixed; left: 50%; top: max(12px, env(safe-area-inset-top)); transform: translateX(-50%); z-index: 50; display: flex; flex-direction: column; gap: 6px; width: min(440px, calc(100% - 32px)); pointer-events: none; }
.toast { background: var(--ink); color: var(--white); border-radius: 14px; padding: 10px 14px; font-weight: 600; font-size: 14px; text-align: center; animation: toast 2.8s ease forwards; }
.toast.gold { background: var(--yellow); color: var(--ink); border: 2.5px solid var(--ink); }
@keyframes toast { 0% { opacity: 0; transform: translateY(-8px); } 8%, 85% { opacity: 1; transform: none; } 100% { opacity: 0; } }

@media (min-width: 768px) {
  #app { max-width: 600px; }
  .middle { grid-template-columns: repeat(var(--cols, 3), minmax(0, 96px)); gap: 14px 12px; }
  .hand .cs { width: 72px; }
  .opp { width: 140px; }
  }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
  .confetti { display: none; }
}
