:root {
  --bg: #f4f1ea;
  --surface: #fffdf8;
  --ink: #1f2a44;
  --muted: #6b7280;
  --line: #d9d3c4;
  --accent: #e0662f;
  --accent-ink: #fff;
  --hit: #2f9e63;
  --miss: #c2413a;
  --key: #ffffff;
  --key-shadow: #cfc8b6;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141a2a;
    --surface: #1d2539;
    --ink: #eef1f8;
    --muted: #97a0b5;
    --line: #2f3a55;
    --accent: #f08a4b;
    --accent-ink: #1a1206;
    --hit: #45c482;
    --miss: #f06a62;
    --key: #26304a;
    --key-shadow: #0d1220;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

button {
  font: inherit;
  color: inherit;
  touch-action: manipulation;
  cursor: pointer;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) 12px env(safe-area-inset-bottom);
}

/* Horní lišta */
.bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 0 6px;
}
.bar-title { flex: 1; display: flex; align-items: center; gap: 8px; min-width: 0; }
.bar h1 { font-size: 1.25rem; margin: 0; letter-spacing: .02em; }
.badge {
  font-size: .8rem;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.icon-btn {
  width: 44px; height: 44px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  font-size: 1.2rem;
}
.streak { font-weight: 700; font-variant-numeric: tabular-nums; }

/* Hrací plocha */
.stage {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.gallows {
  width: 100%;
  flex: 1;
  min-height: 120px;
  max-height: 34vh;
  stroke: var(--ink);
  stroke-width: 5;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}
.part {
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  opacity: 0;
  transition: stroke-dashoffset .45s ease-out;
}
.part.on { stroke-dashoffset: 0; opacity: 1; }
.face { opacity: 0; stroke-width: 3; }
.gallows.lost .face { opacity: 1; transition: opacity .4s .3s; }
.gallows.lost .part:nth-child(n+6) { stroke: var(--miss); }
.gallows.won { stroke: var(--hit); }

.clue {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 2.6rem;
  padding: 2px 16px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
}
.clue[hidden] { display: none; }
.clue-pic { font-size: 2rem; line-height: 1; }
.clue-pic:empty, .clue-text:empty { display: none; }
.clue-text { font-size: 1.15rem; font-weight: 700; }

.lives {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: .85rem;
  color: var(--muted);
  width: 100%;
  max-width: 320px;
  font-variant-numeric: tabular-nums;
}
.lives-bar {
  flex: 1;
  height: 8px;
  border-radius: 99px;
  background: var(--line);
  overflow: hidden;
}
#livesFill {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width .3s;
}

/* Hledané slovo */
.word {
  --n: 8;
  --tile: min(2.6rem, calc((100vw - 24px) / var(--n) - 5px));
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px 18px;
  padding: 6px 0 4px;
  min-height: 3.4rem;
}
.word-group { display: flex; gap: 5px; }
.tile {
  width: var(--tile);
  height: calc(var(--tile) * 1.25);
  display: grid;
  place-items: center;
  font-size: calc(var(--tile) * .68);
  font-weight: 800;
  border-bottom: 3px solid var(--ink);
  text-transform: uppercase;
}
.tile.sym { border-bottom-color: transparent; }
.tile.show { animation: pop .25s ease-out; }
.tile.missed { color: var(--miss); }
.word.shake { animation: shake .35s; }

@keyframes pop { from { transform: scale(.4); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes shake {
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}

/* Klávesnice */
.controls { padding: 6px 0 10px; }
.keyboard {
  display: grid;
  grid-template-columns: repeat(var(--cols, 7), 1fr);
  gap: 6px;
}
.key {
  min-height: 46px;
  border: none;
  border-radius: 10px;
  background: var(--key);
  box-shadow: 0 3px 0 var(--key-shadow);
  font-size: 1.15rem;
  font-weight: 700;
  transition: transform .06s, background .2s, opacity .2s;
}
.key:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 var(--key-shadow); }
.key:disabled { cursor: default; }
.key.hit { background: var(--hit); color: #fff; box-shadow: none; }
.key.miss { background: transparent; color: var(--muted); box-shadow: none; opacity: .45; text-decoration: line-through; }
.keyboard.hard .key { min-height: 42px; font-size: 1.05rem; }

.actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.actions .btn { flex: 1; }

.btn {
  min-height: 46px;
  padding: 0 16px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-weight: 600;
}
.btn small { display: block; font-size: .7rem; font-weight: 400; color: var(--muted); line-height: 1; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn:disabled { opacity: .45; }

/* Dialogy */
.sheet {
  width: min(520px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  border: none;
  border-radius: 20px;
  padding: 20px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .35);
}
.sheet::backdrop { background: rgba(10, 14, 25, .55); }
.sheet[open] { animation: rise .25s ease-out; }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } }
.sheet h2 { margin: 0 0 8px; }
.sheet h3 { margin: 18px 0 8px; font-size: .9rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.sheet-actions { display: flex; gap: 8px; margin-top: 20px; }
.sheet-actions .btn { flex: 1; }

#resultDialog { text-align: center; }
.result-emoji { font-size: 3rem; }
.result-word { font-size: 1.6rem; font-weight: 800; margin: 6px 0; letter-spacing: .04em; }
.result-translation { font-size: 1.1rem; margin: 0 0 10px; }
.result-translation:empty { display: none; }
.speak-btn { margin: 0 auto 10px; }
.speak-btn[hidden] { display: none; }
.result-meta { color: var(--muted); margin: 0; }

.chips { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.chip {
  min-height: 40px;
  padding: 4px 10px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: transparent;
  text-align: left;
  font-size: .9rem;
  line-height: 1.2;
}
.chip small { display: block; padding-left: 1.6em; font-size: .72rem; opacity: .7; }
button:focus:not(:focus-visible) { outline: none; }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }

.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.segmented.three { grid-template-columns: repeat(3, 1fr); }
.segmented.three button { padding: 8px 4px; }
.segmented button {
  display: flex; flex-direction: column; align-items: center;
  padding: 10px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: transparent;
  font-weight: 700;
}
.segmented small { font-weight: 400; color: var(--muted); font-size: .75rem; }
.segmented button[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 2px var(--accent); }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; text-align: center; }
.stats div { background: var(--bg); border-radius: 12px; padding: 8px 4px; }
.stats b { display: block; font-size: 1.3rem; }
.stats span { font-size: .75rem; color: var(--muted); }

.link {
  display: block;
  margin: 14px auto 0;
  background: none;
  border: none;
  color: var(--muted);
  text-decoration: underline;
  font-size: .85rem;
}

@media (max-height: 640px) {
  .gallows { max-height: 26vh; }
  .key { min-height: 40px; }
  .keyboard.hard .key { min-height: 36px; }
  .actions { margin-top: 6px; }
  .btn { min-height: 40px; }
}
.sheet:focus { outline: none; }
