/* ============================================================
   Tähetrall — lastesõbralik kirjutamistreening
   Bränd: TERA (oranž #F49304 + süsi), Bricolage Grotesque + Hanken Grotesk
   ============================================================ */

:root {
  /* --- TERA värvid (OKLCH) --- */
  --brand:      oklch(0.745 0.163 63);   /* #F49304 marigold */
  --brand-deep: oklch(0.585 0.145 52);   /* AA oranž tekst valgel */
  --amber:      oklch(0.835 0.135 78);
  --coral:      oklch(0.685 0.185 38);
  --ink:        oklch(0.225 0.012 62);   /* süsi tekst */
  --ink-2:      oklch(0.42 0.012 62);    /* pehmem tekst */
  --paper:      oklch(0.985 0.003 80);   /* alusvalge */
  --surface:    oklch(1 0 0);
  --line:       oklch(0.9 0.008 70);
  --char:       oklch(0.205 0.01 60);    /* tume plokk */

  /* typing seisundid */
  --ok:         var(--ink);              /* õige = kindel süsi */
  --oops:       oklch(0.66 0.11 18);     /* pehme roosa - eksitus (mitte range punane) */
  --oops-soft:  oklch(0.94 0.04 20);
  --todo:       oklch(0.78 0.01 70);     /* veel trükkimata */

  --radius: 22px;
  --radius-lg: 30px;
  --shadow: 0 18px 40px -24px oklch(0.225 0.012 62 / 0.5);
  --ease: cubic-bezier(0.2, 0.7, 0.25, 1);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  overflow-x: hidden;
  color: var(--ink);
  background: var(--paper);
  background-image:
    radial-gradient(60% 45% at 85% -5%, oklch(0.835 0.135 78 / 0.4), transparent 70%),
    radial-gradient(50% 40% at 10% 0%, oklch(0.745 0.163 63 / 0.22), transparent 70%);
  background-repeat: no-repeat;
  font-family: "Hanken Grotesk", system-ui, sans-serif;
  font-size: clamp(1rem, 0.96rem + 0.2vw, 1.1rem);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
body { min-height: 100vh; }

h1, h2 {
  font-family: "Bricolage Grotesque", system-ui, sans-serif;
  font-weight: 800; line-height: 1.03; letter-spacing: -0.02em;
  text-wrap: balance; margin: 0 0 6px;
}
h1 { font-size: clamp(1.8rem, 1.3rem + 2vw, 2.7rem); }
h2 { font-size: clamp(1.4rem, 1.1rem + 1vw, 1.9rem); }

.wrap { max-width: 940px; margin: 0 auto; padding: 20px 18px 70px; }

/* ---- Header ---- */
.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 22px; }
.logo {
  display: flex; align-items: center; gap: 10px;
  font-family: "Bricolage Grotesque", sans-serif; font-weight: 800;
  font-size: 1.6rem; letter-spacing: -0.02em; color: var(--ink);
  text-decoration: none;
}
.logo:hover { color: var(--ink); }
.logo .mark { width: 34px; height: 34px; flex: none; }
.logo b { color: var(--brand-deep); font-weight: 800; }
.link {
  color: var(--ink-2); text-decoration: none; font-weight: 600; font-size: 0.95rem;
  padding: 9px 16px; border-radius: 999px; border: 2px solid var(--line);
  transition: border-color .2s, color .2s;
}
.link:hover { border-color: var(--ink); color: var(--ink); }

/* ---- Cards ---- */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-lg); box-shadow: var(--shadow);
  padding: clamp(20px, 3vw, 30px); margin-bottom: 20px;
}
.hidden { display: none !important; }

.sub { color: var(--ink-2); font-weight: 500; margin: 2px 0 20px; }

/* ---- Chips / valikud ---- */
.chips { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 18px; }
.chip {
  border: 2px solid var(--line); background: var(--surface); color: var(--ink);
  font-family: inherit; font-weight: 700; font-size: 1rem;
  padding: 10px 18px; border-radius: 999px; cursor: pointer;
  transition: transform .1s var(--ease), border-color .15s, background .15s, color .15s;
}
.chip:hover { transform: translateY(-2px); border-color: var(--brand); }
.chip.active { border-color: transparent; background: var(--brand); color: var(--char); }
.chip .lvl-emoji { margin-right: 6px; }

.label {
  font-family: "Bricolage Grotesque", sans-serif; font-weight: 700;
  font-size: 0.9rem; color: var(--ink-2); margin: 6px 0 10px;
}

/* ---- Teksti-nimekiri ---- */
.text-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; }
.text-tile {
  text-align: left; background: var(--surface); border: 2px solid var(--line);
  border-radius: 20px; padding: 18px; cursor: pointer; font-family: inherit;
  transition: transform .12s var(--ease), box-shadow .2s, border-color .2s;
  position: relative; overflow: hidden;
}
.text-tile::before {
  content: ""; position: absolute; top: 14px; right: 14px; width: 14px; height: 14px;
  background: var(--brand); clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
  opacity: .18; transition: opacity .2s, transform .3s var(--ease);
}
.text-tile:hover { transform: translateY(-3px); box-shadow: var(--shadow); border-color: transparent; }
.text-tile:hover::before { opacity: 1; transform: rotate(90deg); }
.text-tile .t-title { font-family: "Bricolage Grotesque", sans-serif; font-weight: 700; font-size: 1.25rem; }
.text-tile .t-cat {
  display: inline-block; margin-top: 8px; font-size: 0.8rem; font-weight: 700;
  color: var(--brand-deep); background: oklch(0.745 0.163 63 / 0.14);
  padding: 3px 11px; border-radius: 999px;
}
.text-tile .t-preview { color: var(--ink-2); font-size: 0.92rem; margin-top: 10px; font-weight: 500; }

/* ---- Nupud ---- */
.btn {
  --bg: var(--brand); --fg: var(--char);
  font-family: inherit; font-weight: 700; font-size: 1.05rem;
  border: 2px solid transparent; border-radius: 999px; padding: 13px 24px;
  background: var(--bg); color: var(--fg); cursor: pointer;
  display: inline-flex; align-items: center; gap: 8px;
  transition: transform .1s var(--ease), box-shadow .2s var(--ease), background .2s;
}
.btn:hover { transform: translateY(-2px); box-shadow: 0 12px 26px oklch(0.745 0.163 63 / 0.35); }
.btn:active { transform: translateY(0); }
.btn-primary { --bg: var(--brand); --fg: var(--char); }
.btn-sky { --bg: var(--char); --fg: #fff; }          /* teisene = süsi */
.btn-sky:hover { box-shadow: 0 12px 26px oklch(0.225 0.012 62 / 0.35); }
.btn-ghost { --bg: var(--surface); --fg: var(--ink); border-color: var(--line); }
.btn-ghost:hover { border-color: var(--ink); box-shadow: none; }
.btn-row { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 10px; }

/* ---- Mängu ekraan ---- */
.game-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; gap: 12px; }
.game-title { font-family: "Bricolage Grotesque", sans-serif; font-weight: 700; font-size: 1.4rem; }
.stats { display: flex; gap: 20px; }
.stat { text-align: center; }
.stat .val { font-family: "Bricolage Grotesque", sans-serif; font-size: 1.7rem; font-weight: 800; color: var(--brand-deep); line-height: 1; }
.stat .lbl { font-size: 0.75rem; font-weight: 600; color: var(--ink-2); }

/* Teksti kuva */
.typing {
  font-family: "Hanken Grotesk", sans-serif;
  font-size: clamp(1.7rem, 1.2rem + 2vw, 2.3rem);
  font-weight: 500; line-height: 1.7; letter-spacing: 0.3px; word-spacing: 3px;
  padding: 26px; background: var(--paper); border-radius: 20px;
  border: 2px solid var(--line); min-height: 120px; cursor: text; user-select: none;
  /* pikk tekst murrab ridu kasti sees, ei jookse üle serva */
  white-space: pre-wrap; overflow-wrap: break-word; word-break: break-word;
}
.typing .ch { position: relative; border-radius: 5px; padding: 0 1px; color: var(--todo); transition: color .08s; }
.typing .ch.ok { color: var(--ok); }
.typing .ch.bad { color: var(--oops); background: var(--oops-soft); }
.typing .ch.bad.space { background: var(--oops); }
.typing .ch.todo { color: var(--todo); }
.typing .ch.current { background: oklch(0.745 0.163 63 / 0.2); box-shadow: inset 0 -4px 0 var(--brand); color: var(--ink); }
.typing .ch.current.blink { animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { background: transparent; box-shadow: inset 0 -4px 0 transparent; } }

.capture { position: absolute; opacity: 0; pointer-events: none; left: -9999px; }

.progress-bar { height: 12px; background: var(--line); border-radius: 999px; overflow: hidden; margin: 18px 0 6px; }
.progress-bar > i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--brand), var(--coral)); border-radius: 999px; transition: width .15s ease; }

.hint { color: var(--ink-2); font-weight: 600; font-size: 0.95rem; text-align: center; margin-top: 10px; }

/* ---- Ekraaniklaviatuur ---- */
.keyboard { margin-top: 22px; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.kb-row { display: flex; gap: 6px; }
.key {
  min-width: 44px; height: 48px; border-radius: 13px; background: var(--surface);
  border: 2px solid var(--line); display: flex; align-items: center; justify-content: center;
  font-family: "Hanken Grotesk", sans-serif; font-weight: 700; font-size: 1rem;
  color: var(--ink-2); text-transform: lowercase; transition: .12s var(--ease);
}
.key.wide { min-width: 130px; }
.key.next {
  background: var(--brand); color: var(--char); border-color: var(--brand);
  transform: translateY(-3px); box-shadow: 0 8px 16px oklch(0.745 0.163 63 / 0.4);
}

/* ---- Tulemus ---- */
.result { text-align: center; }
.result .stars { font-size: 56px; letter-spacing: 8px; margin: 6px 0; }
.result .cheer { font-family: "Bricolage Grotesque", sans-serif; font-size: 2rem; font-weight: 800; color: var(--brand-deep); }
.result-stats { display: flex; justify-content: center; gap: 34px; margin: 24px 0; flex-wrap: wrap; }

/* ---- Confetti ---- */
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 50; overflow: hidden; }
.confetti-bit { position: absolute; top: -24px; font-size: 22px; animation: fall linear forwards; }
.confetti-bit.dia { width: 16px; height: 16px; clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%); }
@keyframes fall { to { transform: translateY(106vh) rotate(560deg); opacity: 0.85; } }

@media (prefers-reduced-motion: reduce) {
  .btn, .chip, .text-tile, .key, .typing .ch { transition: none !important; }
  .confetti-bit { display: none; }
  .current.blink { animation: none; }
}

@media (max-width: 560px) {
  .typing { font-size: 1.5rem; padding: 18px; }
  .keyboard { gap: 5px; }
  .kb-row { gap: 5px; }
  .key { min-width: 30px; height: 42px; font-size: 0.9rem; border-radius: 11px; }
  .key.wide { min-width: 84px; }
  .stat .val { font-size: 1.3rem; }
  .logo { font-size: 1.35rem; }
}
@media (max-width: 470px) {
  .wrap { padding: 16px 12px 60px; }
  .card { padding: 18px 14px; }
  .keyboard { gap: 4px; }
  .kb-row { gap: 4px; }
  .key { min-width: 26px; height: 40px; font-size: 0.82rem; border-radius: 9px; }
  .key.wide { min-width: 74px; }
}
