/* Lapisan desain bersama untuk semua permainan Arena Main.
   Dimuat setelah style.css tiap game: warna, tombol, panel, dan tata letak HP.
   Bila game dijalankan sendiri tanpa dashboard, berkas ini tidak ada dan game tetap berjalan. */
:root {
  --bg: #fff5e4;
  --surface: #fffdf8;
  --ink: #2a1f3d;
  --muted: #776a86;
  --line: #f0e1c8;
  --accent: #f2542d;
  --on-accent: #fff;
  --press: #c23a18;
  --sun: #ffc23d;
  --mint: #16a58c;
  --shadow: 0 1px 0 #fff inset, 0 10px 26px -18px #6b4a1e66;
  --font-display: "Fredoka", "Baloo 2", system-ui, sans-serif;
  --font-body: "Nunito", system-ui, sans-serif;
  --cell-a: #fff3da;
  --cell-b: #ffe6bb;
  --cell-ink: #5e4a35;
  --table: #1c9a80;
  --card-edge: #fffdf8;
  --sq-light: #f7e9cb;
  --sq-dark: #6ea78b;
  --tile: #fffaf0;
  --corner: #ffe7bd;
  --sea: #8fd8f2;
  --sea-line: #b9ebfa;
  --sand: #b8e675;
  --sand-edge: #7fb447;
}
:root[data-theme="dark"] {
  --bg: #14132a;
  --surface: #1f1e3d;
  --ink: #f7f1e8;
  --muted: #a3a0c2;
  --line: #33325c;
  --accent: #ff7a4d;
  --on-accent: #1a1330;
  --press: #c9502a;
  --shadow: 0 1px 0 #ffffff0d inset, 0 12px 30px -20px #000;
  --cell-a: #26254b;
  --cell-b: #2f2e5a;
  --cell-ink: #bdb9dd;
  --table: #15594f;
  --sq-light: #7a7cae;
  --sq-dark: #3c3d70;
  --tile: #26254b;
  --corner: #33326a;
  --sea: #123a5e;
  --sea-line: #1d5583;
  --sand: #4f8f4c;
  --sand-edge: #2d5c31;
}

body {
  font-size: 15px;
  font-weight: 600;
  background-color: var(--bg);
  background-image: radial-gradient(color-mix(in srgb, var(--ink) 7%, transparent) 1.2px, transparent 1.3px);
  background-size: 22px 22px;
  -webkit-tap-highlight-color: transparent;
  overflow-x: clip;
}
h1, h2, h3, .brand, .intro h1, .panel-heading h2, .dialog-heading h2, .dialog-head h2, .overlay-card h2, .turn-card h2, .turn-panel h2, .turn-content h2, .hand-heading h2 { letter-spacing: 0; font-family: var(--font-display); }
.brand { font-size: 20px; font-weight: 700; }

/* ---------- kepala halaman ---------- */
.topbar { border-bottom: 0; background: color-mix(in srgb, var(--surface) 82%, transparent); backdrop-filter: blur(8px); box-shadow: 0 1px 0 var(--line); }
.top-inner { min-height: 58px; }

/* ---------- tombol ---------- */
.button {
  min-height: 42px;
  padding: 8px 16px;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  font: 600 14px var(--font-display);
  box-shadow: 0 3px 0 var(--line);
  transition: transform .08s, box-shadow .08s, border-color .15s, filter .15s, background .15s;
  touch-action: manipulation;
  text-decoration: none;
}
.button:hover:not(:disabled) { border-color: var(--line); filter: brightness(1.03); transform: translateY(-1px); box-shadow: 0 4px 0 var(--line); }
.button:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 0 0 var(--line); }
.button.primary, .button.gold {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  box-shadow: 0 3px 0 var(--press);
}
.button.primary:hover:not(:disabled), .button.gold:hover:not(:disabled) { border-color: var(--accent); box-shadow: 0 4px 0 var(--press); }
.button.primary:active:not(:disabled), .button.gold:active:not(:disabled) { box-shadow: 0 0 0 var(--press); }
.icon-button, .button.square { width: 42px; padding: 0; }
.icon { stroke-width: 2; }
.roll-button {
  min-height: 50px;
  border-radius: 16px;
  background: var(--sun);
  color: #2a1f3d;
  font: 700 16px var(--font-display);
  box-shadow: 0 4px 0 #d9951a;
  transition: transform .08s, box-shadow .08s, filter .15s;
  touch-action: manipulation;
}
.roll-button:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 0 0 #d9951a; }
.roll-button:disabled { background: #ffffff1f; color: #fff7e6; box-shadow: none; opacity: .75; }
.segmented { border: 2px solid var(--line); border-radius: 14px; }
.segmented button { min-height: 40px; font: 600 14px var(--font-display); touch-action: manipulation; }
.segmented button[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }

/* ---------- panel ---------- */
.panel { border: 0; border-radius: 22px; background: var(--surface); box-shadow: var(--shadow), 0 0 0 1px var(--line); }
.panel-heading h2 { font-size: 17px; font-weight: 600; }
.badge, .tag { border-width: 0; background: color-mix(in srgb, var(--ink) 7%, transparent); font-weight: 700; padding: 3px 10px; }
.turn-card, .turn-panel {
  color: #fff7e6;
  background: linear-gradient(140deg, #3b2a68, #2a1f3d);
  box-shadow: 0 16px 30px -20px #2a1f3d;
}
.turn-card h2, .turn-panel h2 { color: #fff; }
.turn-kicker span, .turn-panel > span:first-child::before { background: var(--sun); }
.die { background: #fff; box-shadow: 0 4px 0 #d8cfe6, 0 8px 18px -8px #0009; border-radius: 14px; }
.die .pip, .pip { background: #2a1f3d; }

/* ---------- formulir & dialog ---------- */
input, select, select.small { border: 2px solid var(--line); border-radius: 12px; min-height: 44px; font-weight: 600; }
dialog { border: 0; border-radius: 24px; box-shadow: 0 30px 80px -20px #0009; }
dialog::backdrop { background: #1a133099; backdrop-filter: blur(3px); }
dialog[open] { animation: ui-sheet .28s cubic-bezier(.2,.9,.3,1.1) both; }
@keyframes ui-sheet { from { transform: translateY(26px) scale(.97); opacity: 0; } }
.toast { border-radius: 14px; font-weight: 700; z-index: 40; }
.overlay-card { border: 0; border-radius: 24px; box-shadow: 0 24px 60px -24px #0008; }
kbd { border-radius: 7px; }

/* ---------- penyesuaian per game ---------- */
.board-panel:has(.board-2d) > .panel-heading { display: none; }
.play-modes .button, .actions .button { padding-inline: 8px; font-size: 13px; white-space: nowrap; min-width: 0; }
.play-modes .button .icon, .actions .button .icon { display: none; }
body:has(.board-2d) .toast { bottom: 96px; }
canvas:focus-visible { outline: none; }
.hand .card:disabled { opacity: 1; filter: saturate(.5) brightness(.9); }
:root[data-theme="dark"] .hand .card:disabled { filter: saturate(.55) brightness(.62); }
:root[data-theme="dark"] .felt { background: radial-gradient(ellipse at 50% 45%, #1f7a6c 0%, var(--table) 75%); }
:root[data-theme="dark"] .hand-area { background: #00000022; }
.felt { min-height: 262px; border-radius: 18px; }
.felt-badge { border: 0; font-weight: 700; box-shadow: 0 2px 6px -3px #0006; }
.pile > span { color: #ffffffd9; font-weight: 700; }
.discard { border-color: #ffffff66; }
.hand-area { border: 0; border-radius: 18px; background: color-mix(in srgb, var(--ink) 4%, transparent); }
.handoff { background: linear-gradient(140deg, #3b2a68, #2a1f3d); color: #fff7e6; border-radius: 16px; }

/* ---------- lembar pilih mode (ui.js) ---------- */
.ui-start { width: min(94vw, 420px); padding: 22px; text-align: center; background: var(--surface); color: var(--ink); }
.ui-start h2 { margin: 0; font: 700 30px/1.1 var(--font-display); }
.ui-start p { margin: 6px 0 16px; color: var(--muted); }
.ui-start .choices { display: grid; gap: 10px; }
.ui-start .choice {
  display: grid; grid-template-columns: 46px 1fr; gap: 12px; align-items: center; width: 100%; padding: 10px 14px; text-align: left;
  border: 2px solid var(--line); border-radius: 18px; background: var(--bg); box-shadow: 0 3px 0 var(--line); cursor: pointer; color: var(--ink);
  transition: transform .08s, box-shadow .08s; touch-action: manipulation;
}
.ui-start .choice:hover { transform: translateY(-1px); }
.ui-start .choice:active { transform: translateY(3px); box-shadow: none; }
.ui-start .choice.main { background: var(--accent); border-color: var(--accent); color: var(--on-accent); box-shadow: 0 3px 0 var(--press); }
.ui-start .choice i { display: grid; place-items: center; width: 46px; height: 46px; border-radius: 14px; background: color-mix(in srgb, var(--surface) 88%, transparent); color: #2a1f3d; }
.ui-start .choice svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ui-start .choice b { display: block; font: 600 17px var(--font-display); }
.ui-start .choice small { display: block; opacity: .75; font-size: 12.5px; font-weight: 600; }
.ui-start .skip { margin-top: 12px; border: 0; background: none; color: var(--muted); font: 700 13px var(--font-body); cursor: pointer; padding: 8px; }

/* ---------- komputer: papan pas satu layar ---------- */
@media (min-width: 901px) {
  .intro { display: flex; align-items: baseline; gap: 16px; padding: 18px 0 14px; }
  .intro h1 { font-size: 34px; font-weight: 700; white-space: nowrap; }
  .intro p { margin: 0; font-size: 14px; min-width: 0; max-width: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .board-2d { width: min(100%, calc(100dvh - 205px)); min-width: 380px; }
  .board-wrap, .strip, .tools { width: min(100%, calc(100dvh - 250px)); min-width: 380px; }
  .arena-wrap, .hud, .legend { width: min(100%, calc(100dvh - 240px)); min-width: 380px; }
}

/* ---------- tablet ---------- */
@media (max-width: 900px) {
  .intro { padding: 14px 0 10px; }
  .intro h1 { font-size: 28px; font-weight: 700; }
  .intro p { display: none; }
}

/* ---------- HP: permainan dulu, tulisan belakangan ---------- */
@media (max-width: 680px) {
  body { font-size: 14px; }
  .intro { display: none; }
  .top-inner { min-height: 50px; padding-inline: 12px !important; gap: 6px; }
  .wrap, main { padding-inline: 8px; }
  .brand { font-size: 17px; }
  .top-actions { gap: 5px; }
  .top-actions .button { min-height: 38px; width: 38px; padding: 0; }
  .top-actions .button span { display: none; }
  .layout { padding-top: 8px; gap: 8px; }
  .panel { border-radius: 18px; }
  footer { display: none; }
  input, select { font-size: 16px; }

  dialog {
    width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: 24px 24px 0 0;
    padding: 20px 18px calc(18px + env(safe-area-inset-bottom));
    max-height: 90dvh;
  }
  dialog[open] { animation-name: ui-rise; }
  @keyframes ui-rise { from { transform: translateY(40%); opacity: .4; } }
  .ui-start { width: 100vw; }

  /* Pulau Tangga: tombol lempar selalu terlihat */
  body:has(.board-2d) main { padding-bottom: 116px; }
  .board-panel:has(.board-2d) { order: 0; padding: 8px; }
  .board-panel:has(.board-2d) > .panel-heading { display: none; }
  .board-2d { width: 100%; }
  .turn-card:has(.roll-button) {
    position: fixed; z-index: 20; left: 8px; right: 8px; bottom: calc(8px + env(safe-area-inset-bottom));
    display: grid; grid-template-columns: minmax(0, 1fr) 46px minmax(112px, auto); align-items: center; gap: 10px;
    padding: 10px 12px; border-radius: 20px; grid-row: auto;
  }
  .turn-card:has(.roll-button) .turn-content { min-height: 0; padding: 0; }
  .turn-card:has(.roll-button) .turn-kicker, .turn-card:has(.roll-button) #turn-info { display: none; }
  .turn-card:has(.roll-button) .turn-identity { margin: 0; }
  .turn-card:has(.roll-button) h2 { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .turn-card:has(.roll-button) .turn-identity .avatar { width: 28px; height: 28px; }
  .turn-card:has(.roll-button) .die { position: static; width: 46px; height: 46px; padding: 8px; border-radius: 12px; }
  .turn-card:has(.roll-button) .roll-button { margin: 0; min-height: 46px; padding-inline: 10px; font-size: 14px; }
  .turn-card:has(.roll-button) .roll-button .icon { display: none; }

  /* Kartu Satu: meja rapat, kartu besar, tombol sejajar */
  .table-panel { padding: 8px; }
  .table-panel > .panel-heading .label p, .hand-heading p, .pile > span { display: none; }
  .felt { min-height: 214px; margin-top: 6px; border-radius: 16px; }
  .flat-table { inset: 44px 10px 10px; gap: 28px; }
  .felt .card { --card-width: 82px; }
  .discard, .draw-pile { width: 96px; height: 124px; }
  .hand-area { margin-top: 8px; padding: 8px; border: 0; background: color-mix(in srgb, var(--ink) 4%, transparent); border-radius: 16px; }
  .hand { min-height: 128px; padding: 18px 12px 8px; -webkit-overflow-scrolling: touch; }
  .hand .card { --card-width: 68px; margin-left: -18px; }
  .hand-actions .button { flex: 1; min-height: 46px; padding-inline: 6px; font-size: 13px; }
  .turn-panel { min-height: 0; padding: 12px 14px; }
  .turn-panel h2 { font-size: 19px; margin: 2px 0; }

  /* Catur: papan selebar layar */
  .board-panel:has(.sq) { padding: 6px 8px 10px; }
  .tools .button { min-height: 46px; }
  .sq .coord { font-size: 9px; }

  /* Adu Domba: joystick di bawah arena, tidak menutupi pulau */
  .stage-panel { padding: 8px; }
  .hud { margin-bottom: 6px; }
}
@media (pointer: coarse) {
  .arena-wrap:has(.touch:not([hidden])) { overflow: visible; margin-bottom: 138px; border: 0; }
  .arena-wrap:has(.touch:not([hidden])) canvas { border-radius: 16px; }
  .touch { inset: calc(100% + 6px) 0 auto 0 !important; padding: 8px 16px !important; }
  .stick { width: 118px !important; height: 118px !important; }
  .zap { width: 104px !important; height: 104px !important; font-size: 15px !important; }
}
@media (prefers-reduced-motion: reduce) {
  dialog[open] { animation: none; }
}
