* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-2: #0f172a;
  --line: #334155;
  --line-thick: #94a3b8;
  --text: #e2e8f0;
  --muted: #64748b;
  --accent: #2563eb;
  --accent-soft: rgba(37, 99, 235, 0.45);
  --user: #38bdf8;
  --hint: #fbbf24;
  --danger: #f87171;
}

html, body { height: 100%; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  overflow-x: hidden;
}

/* ---------- atas ---------- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 18px 6px;
}
.head { display: flex; flex-direction: column; gap: 2px; }
.hello { font-size: 13px; color: var(--muted); }
.hello b { color: #dbeafe; font-weight: 700; }
.head-btns { display: flex; gap: 8px; }
.btn.small { padding: 8px 12px; font-size: 13px; }
.brand { font-size: 22px; font-weight: 800; letter-spacing: 3px; }
.brand span { color: #60a5fa; }

.btn {
  border: none;
  border-radius: 12px;
  padding: 10px 16px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  color: #fff;
  background: var(--accent);
}
.btn.ghost { background: var(--panel); color: #cbd5e1; }
.btn:active { filter: brightness(1.15); }

/* ---------- HUD ---------- */
.hud {
  display: flex;
  justify-content: space-around;
  align-items: center;
  padding: 12px 14px;
}
.stat {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--panel);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}
.stat .ico { font-size: 14px; }
.stat b { font-weight: 700; }
.badge { background: var(--accent); border-radius: 999px; padding: 7px 14px; font-weight: 700; font-size: 14px; }

/* ---------- papan ---------- */
.board-wrap {
  display: flex;
  justify-content: center;
  padding: 8px 10px;
}
.grid {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  width: min(92vw, 420px);
  background: var(--bg);
  border: 3px solid var(--line-thick);
  border-radius: 12px;
  overflow: hidden;
}

.cell {
  aspect-ratio: 1 / 1;
  border: none;
  background: var(--panel);
  color: var(--text);
  font-size: clamp(17px, 5.4vw, 28px);
  font-weight: 700;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  padding: 0;
  font-family: inherit;
}
.cell.bd-l { border-left: 3px solid var(--line-thick); }
.cell.bd-r { border-right: 3px solid var(--line-thick); }
.cell.bd-t { border-top: 3px solid var(--line-thick); }
.cell.bd-b { border-bottom: 3px solid var(--line-thick); }

.cell.selected { background: var(--accent-soft); }
.cell.related { background: rgba(255, 255, 255, 0.06); }
.cell.same { background: rgba(59, 130, 246, 0.35); }
.cell.conflict { background: rgba(248, 113, 113, 0.18); }

.cell .digit.given { color: #f8fafc; }
.cell .digit.user { color: var(--user); }
.cell .digit.hint { color: var(--hint); }
.cell.conflict .digit { color: var(--danger); }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}
.cell.flash { animation: shake 0.3s ease; background: rgba(248, 113, 113, 0.5); }

/* catatan kecil */
.cell .notes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  width: 100%;
  height: 100%;
}
.cell .notes i {
  display: flex;
  align-items: center;
  justify-content: center;
  font-style: normal;
  font-size: clamp(8px, 2.6vw, 14px);
  font-weight: 600;
  color: transparent;
}
.cell .notes i.on { color: var(--muted); }

/* ---------- panel bawah ---------- */
.panel { margin-top: auto; padding: 10px 12px calc(16px + env(safe-area-inset-bottom)); }
.digits {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 6px;
}
.dbtn {
  aspect-ratio: 1 / 1;
  border: none;
  border-radius: 12px;
  background: var(--panel);
  color: #f1f5f9;
  font-size: clamp(18px, 6vw, 26px);
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
}
.dbtn:active { background: var(--accent); }

.tools { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 10px; }
.tbtn {
  flex: 1;
  padding: 12px 0;
  border: none;
  border-radius: 12px;
  background: var(--panel);
  color: #cbd5e1;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.tbtn.active { background: var(--accent); color: #fff; }
.tbtn:active { filter: brightness(1.15); }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 32%;
  transform: translateX(-50%) translateY(20px);
  background: #334155;
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 15px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 60;
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(2, 6, 23, 0.74);
  backdrop-filter: blur(3px);
  z-index: 50;
  padding: 20px;
}
.modal.hidden { display: none; }

.modal-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 24px;
  width: min(92vw, 340px);
  text-align: center;
  max-height: 88vh;
  overflow-y: auto;
}
.modal-card h2 { margin-bottom: 14px; font-size: 22px; }

.name-input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-2);
  color: #f1f5f9;
  font-size: 16px;
  font-family: inherit;
  margin-bottom: 10px;
  outline: none;
}
.name-input:focus { border-color: var(--accent); }
.diff-note { color: var(--muted); font-size: 12px; margin: 0 0 6px; }
.confirm-msg { color: #cbd5e1; margin-bottom: 16px; line-height: 1.5; }
.best-by { color: var(--muted); font-size: 13px; }

.diff-option {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  margin: 8px 0;
  padding: 14px;
  border: none;
  border-radius: 14px;
  background: var(--panel-2);
  color: #f1f5f9;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
}
.diff-option span { color: var(--muted); font-size: 13px; font-weight: 500; }
.diff-option:active { background: var(--accent); }
.diff-option:active span { color: #dbeafe; }

.win h2 { font-size: 28px; }
.win .win-sub { color: #cbd5e1; margin-bottom: 12px; font-size: 16px; }
.win-stat { margin: 6px 0; color: #94a3b8; font-size: 16px; }
.win-stat b { color: #f1f5f9; }
.win-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 18px; }
.win-actions .btn { width: 100%; padding: 13px 0; font-size: 16px; }