/* Tetris Aksara Jawa — tema frontend (dunia batik gelap; dioleh dari token).
 *
 * Semua nilai visual mengalir dari :root --token supaya perubahan nuansa
 * (mis. mode terang, aksen lain) cukup menyentuh satu blok. Aksara juvena
 * merentang dari font bundel Noto Sans Javanese.
 */

@font-face {
  font-family: "Noto Sans Javanese";
  src: url("/static/fonts/NotoSansJavanese-javanese.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Plus Jakarta Sans";
  src: url("/static/fonts/PlusJakartaSans-latin.woff2") format("woff2");
  font-weight: 200 800;
  font-style: normal;
  font-display: swap;
}

:root {
  /* bidang (warna dasar dunia batik gelap) */
  --bg: #12100d;
  --bg-raise: #1c1813;
  --panel: #221d16;
  --panel-deep: #1b1712;
  --inset: #14110d;
  --hairline: #3a3226;

  /* tulisan */
  --ink: #efe4cf;
  --ink-soft: #cfc2ab;
  --muted: #a2947c;

  /* aksara semantik */
  --accent: #e9b45b;
  --accent-deep: #c9482f;
  --ok: #86c166;

  /* papan */
  --tile-bg: #241f18;
  --tile-line: rgba(233, 180, 91, 0.06);

  /* rima bentuk */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --shadow-card: 0 2px 10px rgba(0, 0, 0, 0.35);
  --shadow-board: 0 10px 26px rgba(0, 0, 0, 0.45), inset 0 0 0 1px rgba(233, 180, 91, 0.05);
  --ease-out: cubic-bezier(0.22, 0.61, 0.36, 1);
  --t-fast: 140ms;
  --t-med: 220ms;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  /* atmosfer batik gelap: hangat cahaya di atas, merah rempah di bawah. */
  background:
    radial-gradient(1200px 600px at 70% -10%, rgba(233, 180, 91, 0.08), transparent 60%),
    radial-gradient(900px 700px at 10% 110%, rgba(201, 72, 47, 0.07), transparent 55%),
    var(--bg);
  color: var(--ink);
  font-family: "Plus Jakarta Sans", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  text-rendering: optimizeLegibility;
}

/* ---------------------------------------------------------------- surface browser yang ikut di-tema */
::selection { background: var(--accent); color: #241a0a; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.ghost-btn:focus-visible, .primary-btn:focus-visible, .touch-btn:focus-visible { outline-offset: 3px; }

/* ---------------------------------------------------------------- bar atas */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 22px;
  border-bottom: 1px solid var(--hairline);
  background: linear-gradient(180deg, rgba(28, 24, 19, 0.92), rgba(18, 16, 13, 0.65));
}

.brand {
  margin: 0;
  font-size: 19px;
  font-weight: 800;
  letter-spacing: 0.5px;
  color: var(--accent);
  white-space: nowrap;
}
.brand span { color: var(--ink); font-weight: 300; letter-spacing: 3px; }

.hud { display: flex; align-items: center; gap: 26px; }
.hud-item { display: flex; flex-direction: column; align-items: flex-end; }
.hud-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 2.2px;
  color: var(--muted);
}
.hud-value { font-size: 21px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- komposisi tengah */
.layout {
  display: flex;
  gap: 24px;
  justify-content: center;
  align-items: flex-start;
  padding: 26px 16px 48px;
}

.board-wrap { position: relative; }

canvas#board {
  width: 320px;    /* COLS × CELL — awet disinkron dengan COLS/CELL game.js */
  height: 448px;   /* ROWS × CELL */
  background: var(--bg-raise);
  border: 1px solid var(--hairline);
  border-radius: 10px;
  box-shadow: var(--shadow-board);
  display: block;
}
canvas#board.shake { animation: shake 0.3s ease; }
canvas#board.shake-hard { animation: shake-hard 0.34s ease; }
@keyframes shake {
  0%, 100% { transform: translate(0, 0); }
  20% { transform: translate(-3px, 2px); }
  40% { transform: translate(3px, -2px); }
  60% { transform: translate(-2px, -2px); }
  80% { transform: translate(2px, 2px); }
}
@keyframes shake-hard {
  0%, 100% { transform: translate(0, 0) rotate(0deg); }
  18% { transform: translate(-5px, 3px) rotate(-0.5deg); }
  38% { transform: translate(5px, -3px) rotate(0.5deg); }
  58% { transform: translate(-4px, -2px) rotate(-0.4deg); }
  78% { transform: translate(4px, 3px) rotate(0.4deg); }
}

.banner {
  position: absolute;
  inset: auto 0 12px 0;
  text-align: center;
  font-weight: 800;
  font-size: 22px;
  color: var(--accent);
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.7);
  pointer-events: none;
  animation: pop 0.9s var(--ease-out) forwards;
}
.banner.big { font-size: 30px; color: var(--ok); }
@keyframes pop {
  0% { opacity: 0; transform: scale(0.6) translateY(12px); }
  22% { opacity: 1; transform: scale(1.08); }
  75% { opacity: 1; transform: scale(1) translateY(-6px); }
  100% { opacity: 0; transform: translateY(-26px); }
}

/* ---------------------------------------------------------------- panel samping */
.panel { display: flex; flex-direction: column; gap: 14px; width: 260px; }

.card {
  background: linear-gradient(180deg, var(--panel), var(--panel-deep));
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  padding: 14px 16px 16px;
}

.card-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 2.6px;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 10px;
}

.mission {
  font-family: "Noto Sans Javanese", "Plus Jakarta Sans", serif;
  font-size: 34px;
  line-height: 1.25;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 46px;
  margin: 0;
}
.mission .box {
  display: inline-flex;
  align-items: center;
  border-radius: var(--r-sm);
  padding: 1px 7px 3px;
  background: var(--tile-bg);
  border: 1px solid rgba(233, 180, 91, 0.18);
  box-shadow: var(--shadow-card);
}
.mission.flash, .mission-latin.flash { animation: mission-fl 0.6s ease; }
@keyframes mission-fl { 0%, 100% { opacity: 1; } 40% { opacity: 0.72; } }
/* kotak misi yang sudah tampil di papan menegaskan dirinya */
.mission .box.lit { border-color: var(--accent); box-shadow: 0 0 10px rgba(233, 180, 91, 0.28); }

.mission-latin { margin: 8px 0 0; color: var(--muted); font-size: 14px; letter-spacing: 1px; }
.mission-theme {
  margin: 0 0 6px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 1.6px;
  text-transform: uppercase;
  color: var(--accent-deep);
}
.mission-meaning { margin: 6px 0 0; color: var(--ok); font-size: 13px; }

/* ---------------------------------------------------------------- jalur misi di atas papan */
/* Copy kotak misi yang menempel di papan — mati bila belum terkumpul,
   menyala + underline berwarna bila sudah muncul sebagai kotak di papan. */
.mission-track {
  display: flex;
  gap: 6px;
  padding: 0 2px 8px;
  justify-content: center;
}
.track-slot {
  font-family: "Noto Sans Javanese", "Plus Jakarta Sans", serif;
  font-size: 24px;
  line-height: 1.15;
  padding: 1px 7px 3px;
  border-radius: var(--r-sm);
  background: var(--inset);
  border: 1px dashed rgba(233, 180, 91, 0.25);
  color: rgba(239, 228, 207, 0.38);
  filter: grayscale(1);
  transition: color var(--t-med) ease, border-color var(--t-med) ease, filter var(--t-med) ease, background var(--t-med) ease;
}
.track-slot.lit {
  color: var(--ink);
  filter: none;
  background: var(--tile-bg);
  border-style: solid;
  border-color: var(--accent);
  box-shadow: 0 0 10px rgba(233, 180, 91, 0.22);
}

/* ---------------------------------------------------------------- saku misi (hp) */
/* Bar saku di atas papan: kata misi + keping berikut selalu layar — biar
   pemain hp tak harus menggeser layar. Tersembunyi di desktop (panel sudah
   menampilkan keduanya); muncul pada pointer kasar bersama baris sentuh. */
.pocket { display: none; }
.pocket-goal {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}
.pocket-latin {
  font-size: 17px;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: 0.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pocket-meaning {
  font-size: 10.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pocket-next {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.pocket-next-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.6px;
  color: var(--muted);
}
.pocket-next-glyphs {
  display: flex;
  align-items: center;
  gap: 3px;
  font-family: "Noto Sans Javanese", "Plus Jakarta Sans", serif;
  font-size: 20px;
  min-height: 28px;
  padding: 1px 8px 3px;
  border-radius: var(--r-sm);
  background: var(--inset);
  border: 1px dashed rgba(233, 180, 91, 0.25);
}
.pocket-next-glyphs.pair { gap: 6px; }
.pocket-next-glyphs .next-plus { font-size: 11px; color: var(--muted); font-family: inherit; }

/* ---------------------------------------------------------------- keping berikut */
.next-piece {
  font-family: "Noto Sans Javanese", "Plus Jakarta Sans", serif;
  font-size: 40px;
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: var(--tile-bg);
  border: 1px dashed rgba(233, 180, 91, 0.25);
}
.next-label { margin: 8px 0 0; color: var(--muted); font-size: 12.5px; text-align: center; min-height: 1em; }
.next-piece { gap: 4px; }
.next-piece .next-plus { font-size: 18px; color: var(--muted); font-family: inherit; }
.next-piece .next-glyph { display: inline-block; }
.next-piece.pair { gap: 8px; }

/* ---------------------------------------------------------------- recap kata bertema */
.card-title-plain {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 2.2px;
  text-transform: uppercase;
  color: var(--muted);
  text-align: left;
  margin: 14px 0 8px;
}
.found-list {
  text-align: left;
  background: var(--inset);
  border: 1px solid var(--hairline);
  border-radius: 10px;
  padding: 8px 12px;
  margin-bottom: 14px;
  max-height: 132px;
  overflow: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--hairline) transparent;
}
.found-list::-webkit-scrollbar { width: 8px; }
.found-list::-webkit-scrollbar-thumb { background: var(--hairline); border-radius: 8px; }
.found-list::-webkit-scrollbar-track { background: transparent; }
.found-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  padding: 3px 0;
  font-size: 13px;
  color: var(--ink);
  border-bottom: 1px dashed rgba(58, 50, 38, 0.6);
}
.found-row:last-child { border-bottom: none; }
.found-latin { font-weight: 700; }
.found-mean { color: var(--ok); font-size: 12px; }

/* ---------------------------------------------------------------- bantuan tombol */
.help { margin: 0; padding: 0 0 12px; list-style: none; color: var(--muted); font-size: 13px; display: grid; gap: 7px; }
.help li { display: flex; align-items: center; gap: 8px; }

.keys { display: inline-flex; gap: 4px; margin-right: 2px; }
kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  background: var(--inset);
  border: 1px solid var(--hairline);
  border-bottom-width: 2px;
  border-radius: 6px;
  padding: 1px 6px 0;
  font-family: inherit;
  font-size: 11px;
  color: var(--ink);
}
kbd svg { width: 12px; height: 12px; display: block; }

.touch-row {
  display: none;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--hairline);
}
.touch-btn {
  flex: 1;
  height: 52px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--inset);
  color: var(--accent);
  border: 1px solid var(--hairline);
  border-radius: 10px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background var(--t-fast) ease, border-color var(--t-fast) ease, transform var(--t-fast) var(--ease-out);
}
.touch-btn svg { width: 22px; height: 22px; }
.touch-btn:hover, .touch-btn:active { background: #2a241b; border-color: var(--accent); }
.touch-btn:active { transform: scale(0.94); }

/* ---------------------------------------------------------------- tombol */
.primary-btn, .ghost-btn {
  font-family: inherit;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 700;
  letter-spacing: 0.3px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform var(--t-fast) var(--ease-out), box-shadow var(--t-med) ease, background var(--t-fast) ease, border-color var(--t-fast) ease, color var(--t-fast) ease;
}
.primary-btn {
  background: linear-gradient(180deg, #f0c069, var(--accent));
  color: #241a0a;
  border: none;
  padding: 12px 26px;
  font-size: 15px;
  box-shadow: 0 6px 18px rgba(233, 180, 91, 0.25);
}
.primary-btn:hover { transform: translateY(-1px); box-shadow: 0 8px 22px rgba(233, 180, 91, 0.32); }
.primary-btn:active { transform: translateY(1px); box-shadow: 0 3px 10px rgba(233, 180, 91, 0.2); }
.primary-btn:disabled { opacity: 0.55; cursor: default; transform: none; box-shadow: none; }

.ghost-btn {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--hairline);
  padding: 8px 14px;
  font-size: 12.5px;
}
.ghost-btn:hover { color: var(--ink); border-color: var(--muted); }
.ghost-btn:active { transform: translateY(1px); }
.ghost-btn:disabled { opacity: 0.5; cursor: default; }
.btn-icon { width: 14px; height: 14px; color: var(--accent); }

/* ---------------------------------------------------------------- overlay */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 8, 6, 0.78);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 18px;
}
.overlay[hidden] { display: none; }
.overlay-card {
  background: linear-gradient(180deg, #26211a, #191510);
  border: 1px solid var(--hairline);
  border-radius: var(--r-lg);
  padding: 30px 30px 26px;
  max-width: 432px;
  width: 100%;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
  text-align: center;
}
.ov-title { margin: 0 0 4px; font-size: 26px; font-weight: 800; color: var(--accent); letter-spacing: 1px; }
.ov-title span { color: var(--ink); font-weight: 300; letter-spacing: 5px; }
.ov-sub { color: var(--muted); font-size: 14px; line-height: 1.55; margin: 8px 0 14px; }

.rules {
  text-align: left;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
  margin: 0 0 18px;
  padding-left: 20px;
}
.rules b { color: var(--ink); }

.final-line { font-size: 22px; margin: 6px 0 10px; }
.muted { color: var(--muted); font-size: 13px; font-weight: 400; }
.save-note { color: var(--ok); }

/* ---------------------------------------------------------------- dewan juara */
.hof-list {
  text-align: left;
  background: var(--inset);
  border: 1px solid var(--hairline);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 14px;
  max-height: 180px;
  overflow: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--hairline) transparent;
}
.hof-list::-webkit-scrollbar { width: 8px; }
.hof-list::-webkit-scrollbar-thumb { background: var(--hairline); border-radius: 8px; }
.hof-list::-webkit-scrollbar-thumb:hover { background: var(--muted); }
.hof-list::-webkit-scrollbar-track { background: transparent; }

.hof-row {
  display: grid;
  grid-template-columns: 26px 1fr 76px;
  gap: 8px;
  padding: 5px 4px;
  font-size: 13px;
  color: var(--ink-soft);
  border-bottom: 1px dashed rgba(58, 50, 38, 0.6);
}
.hof-row:last-child { border-bottom: none; }
.hof-row .rank { color: var(--muted); font-variant-numeric: tabular-nums; }
.hof-row .pts { text-align: right; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }
.hof-row.mine { background: rgba(233, 180, 91, 0.08); border-radius: 6px; }
.hof-empty { color: var(--muted); font-size: 13px; padding: 6px 2px; }

/* ---------------------------------------------------------------- isian nama */
.field { margin: 14px auto 16px; max-width: 280px; }
.field-label {
  display: block;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--muted);
  margin-bottom: 6px;
}
.field input {
  width: 100%;
  background: var(--inset);
  border: 1px solid var(--hairline);
  color: var(--ink);
  caret-color: var(--accent);
  border-radius: var(--r-sm);
  padding: 9px 12px;
  font-family: inherit;
  font-size: 14px;
}
.field input::placeholder { color: rgba(162, 148, 124, 0.75); }
.field input:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(233, 180, 91, 0.18); }

.ov-actions { display: flex; gap: 10px; justify-content: center; }

/* ---------------------------------------------------------------- kredit + noscript */
.credit { padding: 0 16px 22px; text-align: center; }
.credit p { margin: 0; color: var(--muted); font-size: 11.5px; letter-spacing: 0.3px; }
.credit a { color: var(--muted); text-decoration: underline; text-underline-offset: 3px; }
.credit a:hover { color: var(--ink); }
.credit a:focus-visible { color: var(--accent); }

.noscript { position: fixed; inset: auto 16px 16px; text-align: center; color: var(--accent-deep); font-weight: 700; z-index: 60; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

/* ---------------------------------------------------------------- responsif */
@media (max-width: 840px) {
  .topbar { padding: 10px 14px; gap: 10px; }
  .brand { font-size: 18px; }
  .brand span { letter-spacing: 1.6px; }
  .hud { gap: 14px; }
  .hud-value { font-size: 17px; }
  .ghost-btn { padding: 8px 10px; }
  .layout { flex-direction: column; align-items: center; gap: 16px; padding-top: 14px; }
  .panel { width: min(340px, 92vw); flex-direction: row; flex-wrap: wrap; }
  .panel .card { flex: 1 1 44%; }
  .mission { font-size: 26px; }
}

/* layar sangat sempit: tombol dewan juara cukup ikon */
@media (max-width: 560px) {
  #btn-hof .btn-label { display: none; }
  #btn-hof { padding: 8px; }
}

/* baris sentuh muncul saat pointer kasar (hp/tablet) — menempel di dasar
   layar supaya selalu dapat dijangkau sambil memainkan papan yang panjang.
   Panel kartu (kata misi, ini aksara) diganti bar saku di atas papan, dan
   papan di-skala memenuhi tinggi layar — tak ada lagi yang di bawah lipatan. */
@media (pointer: coarse) {
  body { padding-bottom: 92px; }
  .layout { padding-bottom: 12px; }
  .panel { display: none; }
  .pocket {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 12px;
    padding: 0 2px 7px;
  }
  /* papan mengikuti tinggi sisa layar (rasio 320/448 dari atribut canvas) */
  canvas#board {
    height: min(448px, calc(100vh - 258px));
    height: min(500px, calc(100svh - 258px));
    width: auto;
  }
  .touch-row {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    z-index: 40;
    display: flex;
    gap: 10px;
    padding: 10px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    background: rgba(18, 16, 13, 0.9);
    border: 1px solid var(--hairline);
    border-radius: 14px;
    backdrop-filter: blur(8px);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  }
  .touch-btn { height: 56px; }
}

/* ---------------------------------------------------------------- hormati preferensi gerak */
@media (prefers-reduced-motion: reduce) {
  .banner { animation: none; opacity: 1; transform: none; }
  canvas#board.shake, canvas#board.shake-hard { animation: none; }
  .mission.flash, .mission-latin.flash { animation: none; }
  .primary-btn, .ghost-btn, .touch-btn { transition: none; }
  .primary-btn:hover, .ghost-btn:hover { transform: none; }
  .track-slot { transition: none; }
}
