/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Variables ── */
:root {
  --bg:       #070e1b;
  --surface:  #0e1a2e;
  --surface2: #152236;
  --text:     #e8edf5;
  --muted:    #8892aa;
  --accent:   #10b981;
  --accent2:  #059669;
  --gold:     #fbbf24;
  --border:   rgba(255,255,255,0.07);
  --start-bg: rgba(16,185,129,0.12);
  --start-border: rgba(16,185,129,0.45);
  --target-bg: rgba(251,191,36,0.10);
  --target-border: rgba(251,191,36,0.45);
  --changed:  rgba(16,185,129,0.25);
  --changed-border: #10b981;
}

/* ── Base ── */
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
}

/* ── Header ── */
header {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  gap: 10px;
  border-bottom: 1px solid var(--border);
}

.back-btn {
  color: var(--muted);
  display: flex;
  align-items: center;
  text-decoration: none;
  flex-shrink: 0;
}
.back-btn svg { width: 22px; height: 22px; }

.logo {
  flex: 1;
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: -0.01em;
}
.logo span { color: var(--accent); }

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.header-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  line-height: 1;
}
.header-btn--icon {
  width: 34px; height: 34px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-weight: 700;
}

/* ── Main ── */
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 16px 0;
  gap: 0;
}

/* ── Game area ── */
.game-area {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  flex: 1;
}

/* ── Word rows (history) ── */
#chain-history {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 6px;
}

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

/* ── Tiles ── */
.tile {
  width: 52px;
  height: 52px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  font-weight: 800;
  letter-spacing: 0;
  background: var(--surface2);
  border: 2px solid var(--border);
  color: var(--text);
  transition: background 0.15s, border-color 0.15s;
  cursor: default;
}

@media (max-width: 340px) {
  .tile { width: 46px; height: 46px; font-size: 1.1rem; }
}

/* Start word tile */
.tile--startword {
  background: var(--start-bg);
  border-color: var(--start-border);
  color: var(--accent);
}

/* Changed letter tile */
.tile--changed {
  background: var(--changed);
  border-color: var(--changed-border);
  color: var(--accent);
}

/* Target word tile */
.tile--target {
  background: var(--target-bg);
  border-color: var(--target-border);
  color: var(--gold);
}
.tile--target.tile--match {
  background: rgba(251,191,36,0.22);
  border-color: var(--gold);
}

/* Current word tile (interactive) */
#current-row {
  display: flex;
  gap: 5px;
  justify-content: center;
  margin-bottom: 6px;
}

.tile--current {
  cursor: pointer;
  border-color: rgba(16,185,129,0.25);
}
.tile--current:hover {
  border-color: rgba(16,185,129,0.5);
}
.tile--current.tile--selected {
  background: rgba(16,185,129,0.2);
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 0 0 3px rgba(16,185,129,0.15);
}
.tile--current.tile--changed {
  background: var(--changed);
  border-color: var(--changed-border);
  color: var(--accent);
}

/* ── Connector between rows ── */
.connector {
  width: 2px;
  height: 10px;
  background: var(--border);
  margin: 0 auto 6px;
}

/* ── Step counter ── */
.step-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 340px;
  margin-bottom: 8px;
  min-height: 20px;
}
#step-count {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* ── Target row ── */
#target-row {
  display: flex;
  gap: 5px;
  justify-content: center;
}

/* ── Target label ── */
.target-label {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 5px;
  opacity: 0.8;
}

/* ── Undo button ── */
.undo-row {
  margin-top: 10px;
  margin-bottom: 10px;
}
.btn-undo {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 20px;
  padding: 7px 18px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.btn-undo:not(:disabled):hover { color: var(--text); border-color: rgba(255,255,255,0.2); }
.btn-undo:disabled { opacity: 0.35; cursor: default; }

/* ── Shake animation ── */
@keyframes shake {
  0%,100% { transform: translateX(0); }
  20%     { transform: translateX(-6px); }
  40%     { transform: translateX(6px); }
  60%     { transform: translateX(-4px); }
  80%     { transform: translateX(4px); }
}
.shake { animation: shake 0.35s ease; }

/* ── Keyboard ── */
#keyboard {
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 4px 16px;
}
.kb-row {
  display: flex;
  justify-content: center;
  gap: 5px;
}
.kb-row--special { margin-top: 2px; }

.kb-key {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  width: 34px;
  height: 44px;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.1s, transform 0.08s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.kb-key:active { transform: scale(0.93); background: var(--surface); }

@media (max-width: 360px) {
  .kb-key { width: 30px; height: 40px; font-size: 0.82rem; }
  #keyboard { gap: 5px; }
  .kb-row { gap: 4px; }
}

/* ── Overlays ── */
.overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(7,14,27,0.82);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 24px;
}
.overlay.active { display: flex; }
.overlay[hidden]  { display: none; }

.overlay-card {
  background: var(--surface);
  border: 1px solid rgba(255,255,255,0.09);
  border-radius: 24px;
  padding: 32px 24px;
  width: 100%;
  max-width: 340px;
  text-align: center;
}

.overlay-emoji { font-size: 2.8rem; margin-bottom: 10px; line-height: 1; }
.overlay-card h2 { font-size: 1.5rem; font-weight: 800; margin-bottom: 16px; }

/* Win stats */
.win-stat-val {
  font-size: 3rem;
  font-weight: 800;
  color: var(--accent);
  line-height: 1;
}
.win-stat-label {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  margin-bottom: 10px;
}
.win-par {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 4px;
  min-height: 1.4em;
}
.win-par--good { color: var(--accent); }

/* ── Win stats-rad ── */
.win-stats-row {
  display: flex;
  gap: 10px;
  width: 100%;
  margin-bottom: 4px;
}
.win-mini-stat {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.win-mini-val {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1;
}
.win-mini-label {
  font-size: 0.62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
}

.btn-primary {
  display: block;
  width: 100%;
  padding: 16px;
  background: var(--accent);
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
  border: none;
  border-radius: 14px;
  cursor: pointer;
  margin-top: 20px;
  transition: opacity 0.15s;
}
.btn-primary:hover { opacity: 0.9; }

.btn-close {
  position: absolute;
  top: 14px; right: 14px;
  background: var(--surface2);
  border: none;
  color: var(--muted);
  width: 30px; height: 30px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Info modal ── */
.overlay-card--info {
  text-align: left;
  padding-top: 44px;
  max-height: calc(100dvh - 48px);
  overflow-y: auto;
  position: relative;
}
.overlay-card--info h2 { text-align: center; font-size: 1.4rem; margin-bottom: 20px; }

.info-section {
  display: flex;
  flex-direction: column;
}
.info-section > div {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.info-section > div:last-child { border-bottom: none; }
.info-icon { font-size: 1.4rem; }
.info-section > div > strong {
  display: block;
  font-size: 1rem;
  font-weight: 700;
  margin-top: 2px;
}
.info-section p {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.55;
}
.info-section p strong { display: inline; font-weight: 700; color: var(--text); }

/* ── Toast ─────────────────────────────────────────────────────── */
.kjeder-toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%) translateY(6px);
  background: rgba(14, 26, 46, 0.96);
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 22px;
  padding: 9px 20px;
  font-size: 0.88rem;
  font-weight: 700;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.18s ease, transform 0.18s ease;
  z-index: 200;
  white-space: nowrap;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.kjeder-toast--show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
