:root {
  --bg: #121213;
  --panel: #1a1a1b;
  --fg: #f5f5f5;
  --muted: #818384;
  --border: #3a3a3c;
  --key: #818384;
  --correct: #538d4e;
  --present: #b59f3b;
  --absent: #3a3a3c;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}

/* Header */
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.title { text-align: center; }
.title h1 { margin: 0; font-size: 1.6rem; letter-spacing: 0.15em; }
.title p { margin: 2px 0 0; color: var(--muted); font-size: 0.8rem; }

.icon {
  background: none;
  border: 1px solid var(--border);
  color: var(--fg);
  width: 38px;
  height: 38px;
  border-radius: 50%;
  font-size: 1rem;
  cursor: pointer;
}

/* Papan */
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 16px 8px 20px;
  gap: 16px;
}

.board {
  display: grid;
  grid-template-rows: repeat(6, auto);
  gap: 6px;
}

.row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  width: min(330px, 90vw);
}

.row.shake { animation: shake 0.5s; }

.tile {
  aspect-ratio: 1;
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1.3rem, 4vw, 2rem);
  font-weight: 700;
  text-transform: uppercase;
  user-select: none;
  transition: background 0.2s, border-color 0.2s;
}
.tile.filled { border-color: #565758; }
.tile.correct { background: var(--correct); border-color: var(--correct); }
.tile.present { background: var(--present); border-color: var(--present); }
.tile.absent { background: var(--absent); border-color: var(--absent); }
.tile.flip { animation: flip 0.5s ease both; }

@keyframes flip {
  0% { transform: rotateX(0); }
  50% { transform: rotateX(90deg); }
  100% { transform: rotateX(0); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}

/* Keyboard */
.keyboard {
  width: 100%;
  max-width: 500px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.krow {
  display: flex;
  justify-content: center;
  gap: 5px;
}

.key {
  flex: 1;
  max-width: 46px;
  height: 56px;
  border: 0;
  border-radius: 6px;
  background: var(--key);
  color: var(--fg);
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
}
.key.wide { flex: 1.6; max-width: none; font-size: 0.8rem; }
.key.correct { background: var(--correct); }
.key.present { background: var(--present); }
.key.absent { background: var(--absent); color: #8a8a8c; }

/* Toast */
.toast {
  position: fixed;
  top: 84px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--fg);
  color: #000;
  padding: 10px 16px;
  border-radius: 8px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 20;
  white-space: nowrap;
}
.toast.show { opacity: 1; }

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 10;
}
.modal[hidden] { display: none; }

.card {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  max-width: 420px;
  width: 100%;
  max-height: 90vh;
  overflow: auto;
  line-height: 1.5;
}
.card h2 { margin: 0 0 12px; }
.card h3 { margin: 16px 0 8px; font-size: 1rem; }
.card ul { padding-left: 20px; }
.card .muted { color: var(--muted); font-size: 0.9rem; }

.close {
  position: absolute;
  top: 8px;
  right: 12px;
  background: none;
  border: 0;
  color: var(--fg);
  font-size: 1.6rem;
  cursor: pointer;
}

.sw {
  display: inline-block;
  width: 18px;
  height: 18px;
  border-radius: 3px;
  margin-right: 8px;
  vertical-align: middle;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  text-align: center;
  gap: 8px;
  margin: 8px 0 16px;
}
.stat-num { font-size: 1.7rem; font-weight: 700; }
.stat-label { font-size: 0.75rem; color: var(--muted); }

.drow { display: flex; align-items: center; gap: 8px; margin: 4px 0; }
.dnum { width: 14px; text-align: right; }
.dbar {
  background: var(--absent);
  color: #fff;
  font-weight: 700;
  padding: 2px 8px;
  text-align: right;
  min-width: 2ch;
}
.dbar.hi { background: var(--correct); }

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 20px;
}

button.primary {
  background: var(--correct);
  color: #fff;
  border: 0;
  padding: 10px 18px;
  border-radius: 8px;
  font-weight: 700;
  cursor: pointer;
}

button.ghost {
  background: none;
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 10px 18px;
  border-radius: 8px;
  cursor: pointer;
}
