/* Layout: satu kolom sempit seperti meja kartu; baris slot kategori, baris dek, lalu kolom-kolom tableau.
   Satu tema gelap yang disengaja (meja kartu), bukan mengikuti tema sistem. */
:root {
  --felt: #11302a;
  --felt-2: #173d35;
  --felt-line: #2a5a4f;
  --paper: #f3f5ef;
  --ink: #18221e;
  --ink-soft: #55625c;
  --brass: #d9a441;
  --brass-ink: #2a1d05;
  --text: #e6eee9;
  --muted: #9db8ae;
  --bad: #e0694f;
  --good: #7fd3a8;
  --f-display: "Familjen Grotesk", "Helvetica Neue", Arial, sans-serif;
  --f-card: "Atkinson Hyperlegible", "Segoe UI", system-ui, sans-serif;
  --card-h: 86px;
  --gap: 6px;
  --radius: 7px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: radial-gradient(120% 80% at 50% 0%, var(--felt-2), var(--felt) 70%) fixed, var(--felt);
  color: var(--text);
  font-family: var(--f-card);
  font-size: 15px;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }
[hidden] { display: none !important; }

.screen {
  max-width: 760px;
  margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-top: max(14px, env(safe-area-inset-top, 0px));
  padding-bottom: max(20px, env(safe-area-inset-bottom, 0px));
}

/* ---------- Beranda ---------- */
#home { display: flex; flex-direction: column; gap: 22px; }
.home-head h1 {
  font-family: var(--f-display); font-weight: 700; font-size: clamp(40px, 11vw, 64px);
  line-height: 0.92; letter-spacing: -0.02em; margin: 18px 0 10px;
}
.home-head h1::after { content: ""; display: block; width: 56px; height: 6px; background: var(--brass); margin-top: 14px; border-radius: 2px; }
.home-head { display: flex; flex-direction: column; gap: 4px; }
.home-head h1 { margin-bottom: 6px; }
.version { margin: 0; font-size: 12px; letter-spacing: .08em; color: var(--brass); font-weight: 700; font-variant-numeric: tabular-nums; }
.author { margin: 0 0 10px; font-size: 14px; color: var(--text); }
.tagline { color: var(--muted); margin: 0; max-width: 40ch; }
.block { display: flex; flex-direction: column; gap: 10px; }
.block-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.block h2 { font-family: var(--f-display); font-weight: 600; font-size: 19px; margin: 0; }
.muted { color: var(--muted); font-size: 13px; }
.hint-text { color: var(--muted); font-size: 13.5px; margin: 0; min-height: 2.6em; }

.seg { display: grid; grid-template-columns: repeat(3, 1fr); background: rgba(0,0,0,.25); border-radius: 10px; padding: 4px; gap: 4px; }
.seg button { border: 0; background: transparent; padding: 10px; border-radius: 7px; font-weight: 700; color: var(--muted); cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--paper); color: var(--ink); }

.btn-primary { border: 0; background: var(--brass); color: var(--brass-ink); font-weight: 700; padding: 14px 16px; border-radius: 10px; cursor: pointer; font-size: 16px; }
.btn-primary:active { transform: translateY(1px); }
.btn-ghost { border: 1px solid var(--felt-line); background: transparent; padding: 10px 14px; border-radius: 9px; cursor: pointer; }
.wide { width: 100%; }

.level-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); gap: 6px; }
.lv { border: 1px solid var(--felt-line); background: rgba(0,0,0,.18); border-radius: 8px; padding: 6px 0 5px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 1px; font-variant-numeric: tabular-nums; }
.lv b { font-family: var(--f-display); font-size: 16px; }
.lv small { font-size: 10px; letter-spacing: 1px; color: var(--brass); min-height: 12px; }
.lv.next { border-color: var(--brass); }
.lv.perfect small { color: var(--good); }
.lv:disabled { opacity: .35; cursor: default; }

.endless-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.endless-btn { border: 1px solid var(--felt-line); background: rgba(0,0,0,.18); border-radius: 10px; padding: 12px 8px; cursor: pointer;
  display: flex; flex-direction: column; gap: 3px; align-items: flex-start; text-align: left; }
.endless-btn b { font-family: var(--f-display); font-size: 17px; }
.endless-btn span { font-size: 12px; color: var(--muted); }
.data-row { display: flex; flex-wrap: wrap; gap: 8px; }
.count-pill { display: inline-block; min-width: 1.6em; padding: 0 5px; border-radius: 99px; background: var(--felt-line); font-size: 12px; text-align: center; }

/* ---------- Papan ---------- */
#game { display: flex; flex-direction: column; gap: 10px; user-select: none; -webkit-user-select: none; }
.game-head { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; }
.icon-btn { border: 0; background: rgba(0,0,0,.22); padding: 8px 11px; border-radius: 8px; cursor: pointer; }
.game-title { display: flex; flex-direction: column; min-width: 0; }
.game-title > span:first-child { font-family: var(--f-display); font-weight: 600; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.moves { font-family: var(--f-display); font-weight: 700; font-size: 20px; font-variant-numeric: tabular-nums; text-align: right; line-height: 1.05; }
.moves small { display: block; font-family: var(--f-card); font-weight: 400; font-size: 11px; color: var(--muted); }
.moves.low { color: var(--bad); }
.toolbar { display: flex; gap: 6px; }
.tool { flex: 1; border: 1px solid var(--felt-line); background: rgba(0,0,0,.15); border-radius: 8px; padding: 7px 6px; cursor: pointer; font-size: 14px; }
.tool:disabled { opacity: .4; cursor: default; }

#board { display: flex; flex-direction: column; gap: 10px; touch-action: none; }
.found-row { display: grid; grid-template-columns: repeat(var(--slots, 4), 1fr); gap: var(--gap); }
.slot { border-radius: var(--radius); min-height: 66px; padding: 6px 5px 7px; display: flex; flex-direction: column; justify-content: space-between; gap: 4px; position: relative; }
.slot.empty { border: 1.5px dashed var(--felt-line); color: var(--muted); font-size: 11.5px; align-items: center; justify-content: center; text-align: center; }
.slot.filled { background: var(--brass); color: var(--brass-ink); box-shadow: 0 2px 0 rgba(0,0,0,.25); }
.slot .nm { font-family: var(--f-display); font-weight: 700; font-size: clamp(10.5px, 2.75vw, 14px); line-height: 1.1; overflow-wrap: break-word; }
.slot .pg { font-variant-numeric: tabular-nums; font-size: 12px; font-weight: 700; }
.slot .bar { height: 4px; background: rgba(42,29,5,.2); border-radius: 2px; overflow: hidden; }
.slot .bar i { display: block; height: 100%; background: var(--brass-ink); }
.slot.done { background: var(--good); color: #0b2a1d; animation: pop .5s ease; }
.slot.target-ok { outline: 2px solid var(--paper); }

.deck-row { display: grid; grid-template-columns: repeat(var(--cols, 5), 1fr); gap: var(--gap); align-items: stretch; }
.stock, .waste { height: var(--card-h); border-radius: var(--radius); position: relative; }
.stock { border: 0; cursor: pointer; background: repeating-linear-gradient(135deg, #2d6a5b 0 6px, #255a4d 6px 12px); box-shadow: inset 0 0 0 2px #3e7d6c;
  display: flex; flex-direction: column; align-items: center; justify-content: center; font-weight: 700; gap: 2px; }
.stock small { font-weight: 400; font-size: 11px; color: var(--muted); }
.stock.recycle { background: transparent; box-shadow: inset 0 0 0 1.5px var(--felt-line); color: var(--muted); }
.stock:disabled { opacity: .3; cursor: default; }
.waste { border: 1.5px dashed var(--felt-line); }
.waste .card { position: absolute; inset: 0; height: auto; }
.deck-info { grid-column: 3 / -1; align-self: center; color: var(--muted); font-size: 12.5px; line-height: 1.45; padding-left: 4px; }
.deck-info b { color: var(--text); font-weight: 700; }

.tableau { display: grid; grid-template-columns: repeat(var(--cols, 5), 1fr); gap: var(--gap); align-items: start; padding-bottom: 24px; }
.col { position: relative; min-height: var(--card-h); border-radius: var(--radius); }
.col.empty-col { box-shadow: inset 0 0 0 1.5px var(--felt-line); }
.col .card { position: absolute; left: 0; right: 0; }

.card {
  height: var(--card-h); border-radius: var(--radius); padding: 6px 6px 5px;
  font-size: clamp(10.5px, 2.75vw, 14.5px); line-height: 1.16; overflow: hidden; overflow-wrap: break-word; hyphens: manual;
  box-shadow: 0 1px 0 rgba(0,0,0,.35), 0 3px 8px rgba(0,0,0,.18); transition: transform .12s ease;
}
.card.word { background: var(--paper); color: var(--ink); font-weight: 700; cursor: grab; }
.card.cat { background: var(--ink); color: var(--paper); border: 2px solid var(--brass); cursor: grab; display: flex; flex-direction: column; gap: 2px; padding: 5px 5px 4px; }
.card.cat .tag { font-size: 8px; letter-spacing: .06em; text-transform: uppercase; color: var(--brass); font-weight: 700; }
.card.cat .nm { font-family: var(--f-display); font-weight: 700; }
.card.cat .sz { margin-top: auto; font-size: 10.5px; color: var(--muted); }
.card.back { background: repeating-linear-gradient(135deg, #2d6a5b 0 6px, #255a4d 6px 12px); box-shadow: inset 0 0 0 2px #3e7d6c, 0 1px 0 rgba(0,0,0,.3); }
.card.selected { outline: 3px solid var(--brass); outline-offset: -1px; transform: translateY(-3px); }
.card.dragging { opacity: .25; }
/* Kartu tertutup di tumpukan: satu baris nama sepanjang sisi lebar, dipotong elipsis bila kepanjangan. */
.card .tx { display: block; }
.card.covered .tx, .card.cat.covered .nm { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card.cat.covered .nm { min-width: 0; max-width: 100%; }
.card.cat.covered .tag, .card.cat.covered .sz { display: none; }
.card.covered { box-shadow: 0 1px 0 rgba(0,0,0,.35); }
.card.word.covered + .card.word { box-shadow: 0 -1px 0 rgba(24,34,30,.18), 0 3px 8px rgba(0,0,0,.18); }
.hint-pulse { animation: pulse 1.1s ease 2; }
.shake { animation: shake .38s ease; }

.ghost { position: fixed; left: 0; top: 0; pointer-events: none; z-index: 50; width: 80px; }
.ghost .card { position: absolute; left: 0; right: 0; box-shadow: 0 10px 24px rgba(0,0,0,.45); transform: rotate(-2deg); }

/* ---------- Toast, modal, loading ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 60;
  bottom: max(18px, calc(env(safe-area-inset-bottom, 0px) + 12px));
  width: min(560px, calc(100% - 28px)); background: #0b1f1b; border: 1px solid var(--felt-line); border-radius: 12px;
  padding: 11px 13px; display: flex; gap: 10px; align-items: center; box-shadow: 0 10px 30px rgba(0,0,0,.4); font-size: 14px;
}
.toast.bad { border-color: var(--bad); }
.toast .msg { flex: 1; min-width: 0; }
.toast button { border: 0; background: var(--paper); color: var(--ink); font-weight: 700; padding: 7px 10px; border-radius: 7px; cursor: pointer; white-space: nowrap; font-size: 13px; }

.modal { position: fixed; inset: 0; z-index: 70; background: rgba(4,14,12,.66); display: grid; place-items: center;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.modal-card { width: min(440px, 100%); max-height: 86vh; overflow: auto; background: var(--felt-2); border: 1px solid var(--felt-line); border-radius: 14px; padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.modal-card h3 { font-family: var(--f-display); font-size: 24px; margin: 0; text-wrap: balance; }
#modal-body { color: var(--text); display: flex; flex-direction: column; gap: 10px; font-size: 14.5px; }
.modal-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.modal-actions button { flex: 1 1 140px; }
.stars { font-size: 30px; letter-spacing: 4px; color: var(--brass); }
.stars .off { color: var(--felt-line); }
.badge { align-self: flex-start; background: var(--good); color: #0b2a1d; font-weight: 700; font-size: 13px; padding: 4px 10px; border-radius: 99px; }
.stat-row small { color: var(--muted); font-weight: 400; }
.mistake-list div { display: flex; justify-content: space-between; gap: 10px; }
.mistake-list b.n { font-variant-numeric: tabular-nums; color: var(--bad); }
.stat-row { display: flex; justify-content: space-between; border-bottom: 1px solid var(--felt-line); padding-bottom: 6px; font-variant-numeric: tabular-nums; }
.flag-list { display: flex; flex-direction: column; gap: 6px; max-height: 40vh; overflow: auto; font-size: 13.5px; }
.flag-list div { background: rgba(0,0,0,.2); border-radius: 8px; padding: 7px 9px; }
textarea { width: 100%; min-height: 120px; background: #0b1f1b; color: var(--text); border: 1px solid var(--felt-line); border-radius: 8px; padding: 8px; font: 12px ui-monospace, Menlo, monospace; }

.loading { position: fixed; inset: 0; z-index: 80; background: rgba(4,14,12,.55); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--felt-line); border-top-color: var(--brass); animation: spin .8s linear infinite; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-6px); } 50% { transform: translateX(5px); } 75% { transform: translateX(-3px); } }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(217,164,65,0); } 50% { box-shadow: 0 0 0 5px rgba(217,164,65,.85); } }
@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.06); } 100% { transform: scale(1); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
