:root {
    --bg: #ffffff;
    --ink: #111111;
    --ink-soft: #4a4a4a;
    --line: #d8d8d8;
    --line-soft: #ebebeb;
    --accent: #f3c641;
    --accent-soft: #fde7a3;
    --accent-deep: #b88600;
    --pill-bg: #1c1c1c;
    --pill-fg: #ffffff;
    --error: #c8453a;
    --success: #2e8b57;
    --cross: #7a4dbf;
    --cross-soft: #e9d6ff;
}

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

html, body {
    margin: 0; padding: 0;
    height: 100%;
    background: linear-gradient(160deg, #fff8df 0%, #ffe7a8 60%, #f3c641 100%);
    color: var(--ink);
    font-family: -apple-system, BlinkMacSystemFont, "Inter", "Helvetica Neue", Helvetica, Arial, sans-serif;
    font-size: 16px;
    overscroll-behavior: none;
    touch-action: pan-x pan-y;
    -webkit-text-size-adjust: 100%;
    overflow: hidden;
}

body { user-select: none; -webkit-user-select: none; }
button, svg { touch-action: manipulation; }

/* Höhe an das _kleinste_ Viewport (svh) binden, damit alles auch bei sichtbarer
   Chrome-Adressleiste + Android-Gestenleiste in den Schirm passt — sonst hat man
   auf dem Pixel die Tastatur unten weggeschnitten und scrollt. */
.app {
    height: 100vh;
    height: 100svh;
    max-height: 100vh;
    max-height: 100svh;
    max-width: 540px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    overflow: hidden;
}

/* --- Topbar (Hinweis-Button, Runde, Score) --- */
.topbar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: max(env(safe-area-inset-top), 10px) 14px 4px;
    font-size: 13px;
    color: var(--ink-soft);
    flex: 0 0 auto;
}
.helpbtn {
    background: var(--bg);
    color: var(--ink);
    border: 1.5px solid var(--line);
    border-radius: 999px;
    width: 30px; height: 30px;
    display: inline-flex; align-items: center; justify-content: center;
    padding: 0; cursor: pointer;
    transition: background 0.12s, transform 0.08s;
    flex: 0 0 auto;
}
.helpbtn:active { background: var(--line-soft); transform: scale(0.94); }
.helpbtn.depleted { opacity: 0.4; }
.skipbtn { color: var(--ink-soft); }
.lvl { font-weight: 700; color: var(--ink); }
.meta-fill { flex: 1; font-size: 12px; color: var(--ink-soft); }
.scoreval { font-weight: 700; color: var(--ink); font-size: 14px; }

/* --- Gitter (Hauptbühne, nimmt den Großteil der Höhe) --- */
.grid-wrap {
    flex: 1 1 auto;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 6px 8px 4px;
    min-height: 0;
    min-width: 0;
    overflow: hidden;
}
#grid {
    display: block;
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
}
.g-cell-letter {
    fill: #ffffff;
    stroke: #c8c8c8;
    stroke-width: 1.2;
}
.g-cell-letter.in-word { fill: #fff7d6; stroke: #d8b450; }
.g-cell-letter.solved  { fill: #c8efd1; stroke: var(--success); stroke-width: 1.8; }
.g-cell-letter.cursor  { fill: var(--accent); stroke: var(--accent-deep); stroke-width: 2.4; }
.g-cell-letter.error   { animation: cellerror 0.55s ease; }
.g-cell-letter.reveal-bg { animation: cellreveal 0.7s ease; }
@keyframes cellerror {
    0%, 100% { fill: #ffe2e0; stroke: #c8453a; }
    50%      { fill: #ffb6b0; stroke: #8a2820; }
}
@keyframes cellreveal {
    0%   { fill: var(--accent); }
    60%  { fill: var(--accent-soft); }
    100% { fill: #ffffff; }
}
.g-cell-text {
    font-weight: 800;
    text-anchor: middle;
    dominant-baseline: central;
    pointer-events: none;
    fill: var(--ink);
}
.g-cell-text.solved { fill: var(--success); }
.g-cell-text.revealed {
    transform-box: fill-box;
    transform-origin: center;
    animation: letterreveal 0.55s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes letterreveal {
    0%   { opacity: 0; transform: scale(0.2) rotate(-8deg); }
    60%  { opacity: 1; transform: scale(1.25) rotate(2deg); }
    100% { opacity: 1; transform: scale(1) rotate(0deg); }
}
.g-cell-hint {
    fill: var(--accent-soft);
    stroke: var(--accent-deep);
    stroke-width: 1.2;
}
.g-cell-hint-text {
    font-weight: 700;
    fill: #4a3a00;
    text-anchor: middle;
}
.g-arrow { fill: var(--accent-deep); stroke: none; pointer-events: none; }
.g-tap   { fill: transparent; cursor: pointer; }

/* --- Eingabe-Leiste unten (Hinweis-Zeile + Slot-Reihe) --- */
.input-bar {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    padding: 6px 10px 8px;
    background: rgba(255, 255, 255, 0.55);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    border-top: 1px solid rgba(184, 134, 0, 0.25);
}
.hint-line {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 32px;
}
.hint-line-arrow {
    font-size: 18px;
    color: var(--accent-deep);
    font-weight: 800;
    flex: 0 0 auto;
    line-height: 1;
}
.hint-line-text {
    font-size: clamp(15px, 4vw, 19px);
    font-weight: 700;
    color: #2a2000;
    line-height: 1.15;
    flex: 1 1 auto;
    text-align: left;
    word-break: break-word;
}
.hint-line-len {
    font-size: 11px;
    color: var(--accent-deep);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    flex: 0 0 auto;
}

.slots-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    max-width: 100%;
}
.navbtn {
    background: var(--bg);
    border: 1.5px solid var(--line);
    border-radius: 999px;
    width: 32px; height: 32px;
    font-size: 17px; font-weight: 800;
    color: var(--ink);
    cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
    transition: background 0.12s, transform 0.08s;
    flex: 0 0 auto;
}
.navbtn:active { background: var(--accent-soft); transform: scale(0.94); }
.navbtn:disabled { opacity: 0.3; cursor: default; }

.slots-row {
    display: flex;
    gap: 5px;
    justify-content: center;
    align-items: stretch;
    flex: 1 1 auto;
    max-width: 100%;
}
.slot {
    position: relative;
    background: var(--bg);
    border: 2px solid var(--line);
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    font-size: clamp(18px, 6.5vw, 28px);
    font-weight: 800;
    color: var(--ink);
    min-width: 0;
    flex: 1 1 0;
    max-width: 42px;
    aspect-ratio: 1 / 1;
    transition: border-color 0.15s, background 0.15s, transform 0.08s;
    cursor: pointer;
}
.slot.active {
    border-color: var(--accent-deep);
    background: var(--accent);
}
.slot.cross {
    border-color: var(--cross);
    background: var(--cross-soft);
}
.slot.cross.active {
    background: linear-gradient(135deg, var(--accent) 50%, var(--cross-soft) 50%);
}
.slot.solved,
.slot.locked {
    border-color: var(--success);
    background: #c8efd1;
    color: var(--success);
    cursor: default;
}
.slot.flash-error { animation: sloterror 0.55s ease; }
@keyframes sloterror {
    0%, 100% { background: #ffe2e0; border-color: #c8453a; }
    50%      { background: #ffb6b0; border-color: #8a2820; }
}
.slot .cross-tag {
    position: absolute;
    top: -8px; right: -6px;
    background: var(--cross);
    color: #fff;
    font-size: 9px;
    font-weight: 700;
    border-radius: 999px;
    padding: 2px 5px;
    line-height: 1;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    pointer-events: none;
}

/* --- QWERTZ-Tastatur (Grid-Layout für deterministische Spaltenbreite) --- */
.keyboard {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    padding: 4px 3px max(env(safe-area-inset-bottom), 6px);
    gap: 5px;
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
}
.kbd-row {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(0, 1fr);
    gap: 3px;
    width: 100%;
    min-width: 0;
}
.kbd-key {
    height: clamp(34px, 6.2vh, 44px);
    border-radius: 6px;
    background: #ffffff;
    border: 1px solid var(--line);
    font-family: inherit;
    font-size: clamp(14px, 4.2vw, 17px);
    font-weight: 700;
    color: var(--ink);
    cursor: pointer;
    padding: 0;
    transition: transform 0.08s, background 0.12s;
    min-width: 0;
    width: 100%;
}
.kbd-key:active {
    background: var(--accent-soft);
    transform: scale(0.94);
}
.kbd-key.action {
    background: var(--pill-bg);
    color: var(--pill-fg);
    border-color: var(--pill-bg);
    font-size: 18px;
}
.kbd-key.action:active { background: #2a2a2a; }

/* --- Toast --- */
.toast {
    position: fixed;
    top: 70px;
    left: 50%;
    transform: translateX(-50%);
    background: #1c1c1c;
    color: #fff;
    padding: 8px 16px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 600;
    z-index: 100;
    pointer-events: none;
    transition: opacity 0.25s;
}
.toast.hidden { opacity: 0; }
.toast.success { background: var(--success); }
.toast.error   { background: var(--error); }

/* --- Feuerwerk --- */
#fireworkContainer {
    position: fixed; inset: 0;
    pointer-events: none;
    z-index: 200;
}
.firework {
    position: absolute;
    width: var(--sz, 10px);
    height: var(--sz, 10px);
    margin-left: calc(var(--sz, 10px) / -2);
    margin-top: calc(var(--sz, 10px) / -2);
    border-radius: 50%;
    box-shadow: 0 0 10px 1px currentColor;
    animation: fireworkpop 1.7s cubic-bezier(0.15, 0.7, 0.25, 1) forwards;
}
@keyframes fireworkpop {
    0%   { opacity: 1; transform: translate(0,0) scale(0.4); }
    15%  { opacity: 1; transform: translate(calc(var(--dx) * 0.25), calc(var(--dy) * 0.25)) scale(1.3); }
    100% { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(0.5); }
}
.celebrate-flash {
    position: absolute; inset: 0;
    background: radial-gradient(circle at 50% 40%, rgba(255,255,255,0.55), rgba(255,255,255,0) 65%);
    animation: celebflash 0.7s ease-out forwards;
}
@keyframes celebflash {
    0%   { opacity: 0; }
    20%  { opacity: 1; }
    100% { opacity: 0; }
}

/* --- Erfolgs-Banner („Alles gelöst") --- */
.celebrate-banner {
    position: fixed; inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 250;
    pointer-events: none;
    padding: 24px;
}
.celebrate-banner.hidden { display: none; }
.celebrate-banner-card {
    background: linear-gradient(135deg, #2e8b57 0%, #1f6a40 100%);
    color: #ffffff;
    padding: 22px 34px;
    border-radius: 20px;
    box-shadow: 0 14px 38px rgba(0, 0, 0, 0.35),
                0 0 0 4px rgba(255, 255, 255, 0.85),
                0 0 0 6px rgba(46, 139, 87, 0.55);
    text-align: center;
    animation: celebratepop 0.55s cubic-bezier(0.34, 1.56, 0.64, 1);
    max-width: 90vw;
}
.celebrate-banner-title {
    font-size: clamp(26px, 7vw, 34px);
    font-weight: 800;
    letter-spacing: 0.4px;
    line-height: 1.1;
}
.celebrate-banner-sub {
    margin-top: 8px;
    font-size: clamp(16px, 4.5vw, 20px);
    font-weight: 700;
    color: #fff7d6;
}
.celebrate-banner-hint {
    margin-top: 10px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.6px;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.85);
}
@keyframes celebratepop {
    0%   { opacity: 0; transform: scale(0.55) translateY(18px); }
    70%  { opacity: 1; transform: scale(1.06) translateY(-2px); }
    100% { opacity: 1; transform: scale(1) translateY(0); }
}

/* --- Kleinere Screens --- */
@media (max-height: 760px) {
    .kbd-key { height: 36px; font-size: 15px; }
    .keyboard { gap: 4px; padding-top: 3px; }
    .topbar  { font-size: 12px; padding-top: 8px; padding-bottom: 2px; }
    .input-bar { padding: 4px 10px 5px; gap: 4px; }
    .hint-line { min-height: 28px; }
    .hint-line-text { font-size: clamp(14px, 3.6vw, 17px); }
    .slot { max-width: 38px; font-size: clamp(16px, 5.5vw, 24px); }
    .navbtn { width: 28px; height: 28px; font-size: 15px; }
}
@media (max-height: 640px) {
    .kbd-key { height: 32px; font-size: 14px; }
    .keyboard { gap: 3px; padding-top: 2px; }
    .slot { max-width: 34px; }
}

.data-credits {
    text-align: center;
    padding: 10px 12px 14px;
    font-size: 11px;
    color: rgba(0, 0, 0, 0.45);
    line-height: 1.4;
}
.data-credits a {
    color: inherit;
    text-decoration: underline;
    text-decoration-color: rgba(0, 0, 0, 0.25);
}
.data-credits a:hover {
    color: rgba(0, 0, 0, 0.7);
}
