:root {
    --katica-green-950: #163b22;
    --katica-green-800: #245c2f;
    --katica-green-600: #4b8f31;
    --katica-green-400: #82bd45;
    --katica-cream: #fffaf0;
    --katica-red: #d92d36;
    --katica-orange: #f59e0b;
    --katica-blue: #2684ff;
    --katica-shadow: 0 18px 50px rgba(20, 63, 31, .2);
}

.katica-app,
.katica-app * {
    box-sizing: border-box;
}

.katica-app {
    position: relative;
    width: 100%;
    max-width: 1680px;
    min-height: 760px;
    margin: 0 auto;
    overflow: hidden;
    color: var(--katica-green-950);
    border-radius: 28px;
    background:
        radial-gradient(circle at 8% 18%, rgba(255, 255, 255, .23) 0 4px, transparent 5px),
        radial-gradient(circle at 88% 80%, rgba(255, 237, 132, .35) 0 5px, transparent 6px),
        linear-gradient(145deg, #b8dc68 0%, #6fac3b 48%, #559332 100%);
    box-shadow: var(--katica-shadow);
    font-family: Inter, "Segoe UI", Arial, sans-serif;
}

.katica-app::before,
.katica-app::after {
    position: absolute;
    z-index: 0;
    content: "🌼  🌿  🌼";
    color: rgba(255, 255, 255, .75);
    font-size: 24px;
    pointer-events: none;
}

.katica-app::before { left: 3%; bottom: 2%; transform: rotate(-5deg); }
.katica-app::after { right: 4%; top: 19%; transform: rotate(6deg); }

.katica-header {
    position: relative;
    z-index: 2;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 24px;
    padding: 18px 30px 12px;
}

.katica-header h1,
.katica-login h1,
.katica-closed h1,
.katica-empty h1 {
    margin: 0;
    color: #fff;
    font-size: clamp(1.8rem, 3vw, 2.75rem);
    font-weight: 900;
    letter-spacing: -.04em;
    text-shadow: 0 3px 0 rgba(27, 83, 35, .22);
}

.katica-eyebrow {
    margin: 0 0 3px;
    color: #fff7b0;
    font-size: .78rem;
    font-weight: 900;
    letter-spacing: .17em;
    text-transform: uppercase;
}

.katica-subtitle {
    max-width: 620px;
    margin: 3px 0 0;
    color: rgba(255, 255, 255, .95);
    font-size: .96rem;
    font-weight: 600;
}

.katica-header__actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.katica-sound,
.katica-logout {
    min-width: 44px;
    min-height: 44px;
    padding: 10px 14px;
    border: 1px solid rgba(255, 255, 255, .55);
    border-radius: 999px;
    color: #fff;
    background: rgba(30, 84, 38, .35);
    backdrop-filter: blur(8px);
    font-weight: 800;
    text-decoration: none;
    cursor: pointer;
}

.katica-layout {
    position: relative;
    z-index: 1;
    display: grid;
    grid-template-columns: minmax(280px, 320px) minmax(0, 1fr);
    gap: 26px;
    padding: 0 34px 36px;
}

.katica-sidebar,
.katica-stage {
    border: 1px solid rgba(255, 255, 255, .58);
    box-shadow: 0 14px 35px rgba(25, 70, 31, .16);
    backdrop-filter: blur(14px);
}

.katica-sidebar {
    align-self: start;
    padding: 22px;
    border-radius: 22px;
    background: rgba(255, 250, 240, .91);
}

.katica-sidebar label,
.katica-label {
    display: block;
    margin-bottom: 7px;
    color: var(--katica-green-800);
    font-size: .77rem;
    font-weight: 900;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.katica-sidebar select {
    width: 100%;
    min-height: 46px;
    padding: 8px 38px 8px 12px;
    border: 2px solid #b8d99b;
    border-radius: 12px;
    color: var(--katica-green-950);
    background: #fff;
    font-size: .98rem;
    font-weight: 750;
}

.katica-level-meta {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-top: 9px;
    color: var(--katica-green-600);
    font-size: .75rem;
    font-weight: 800;
}

#katica-level-description {
    min-height: 44px;
    margin: 8px 0 16px;
    color: #405b43;
    font-size: .92rem;
    line-height: 1.45;
}

.katica-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 7px;
    margin: 0 -4px 19px;
}

.katica-stats div {
    padding: 10px 4px;
    border-radius: 12px;
    text-align: center;
    background: #edf6e4;
}

.katica-stats strong,
.katica-stats span { display: block; }
.katica-stats strong { font-size: 1.28rem; font-weight: 900; }
.katica-stats span { margin-top: 2px; color: #617363; font-size: .69rem; font-weight: 700; }

.katica-history {
    display: flex;
    gap: 5px;
    min-height: 41px;
    margin-bottom: 16px;
    overflow-x: auto;
    padding: 5px;
    border-radius: 10px;
    background: #e6efdc;
}

.katica-history span {
    flex: 0 0 31px;
    display: grid;
    place-items: center;
    height: 31px;
    border-radius: 8px;
    color: #fff;
    background: var(--katica-green-600);
    font-weight: 900;
}

.katica-reset,
.katica-next {
    min-height: 43px;
    padding: 10px 18px;
    border: 0;
    border-radius: 12px;
    color: #fff;
    background: var(--katica-green-800);
    box-shadow: 0 5px 0 #163f21;
    font-weight: 850;
    cursor: pointer;
}

.katica-sidebar > .katica-reset { width: 100%; }
.katica-clear-progress {
    width: 100%;
    min-height: 40px;
    margin-top: 10px;
    padding: 9px 12px;
    border: 1px solid #d6aaa5;
    border-radius: 10px;
    color: #9c2e2e;
    background: #fff7f5;
    font-weight: 800;
    cursor: pointer;
}
.katica-clear-progress:hover { background: #ffebe7; }
.katica-reset:active,
.katica-next:active { transform: translateY(3px); box-shadow: 0 2px 0 #163f21; }
.katica-next { background: var(--katica-orange); box-shadow: 0 5px 0 #a55705; }

.katica-stage {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 0;
    padding: 20px 24px 24px;
    border-radius: 26px;
    background: rgba(79, 145, 48, .47);
}

.katica-message {
    min-height: 34px;
    margin-bottom: 6px;
    padding: 6px 15px;
    border-radius: 999px;
    color: var(--katica-green-950);
    background: rgba(255, 255, 255, .86);
    font-size: .86rem;
    font-weight: 850;
    text-align: center;
}

.katica-message--ok { color: #166534; background: #dcfce7; }
.katica-message--error { color: #991b1b; background: #fee2e2; }

.katica-board {
    --rows: 6;
    --cols: 8;
    display: grid;
    grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
    grid-template-rows: repeat(var(--rows), minmax(0, 1fr));
    width: min(100%, calc(76vh * var(--cols) / var(--rows)));
    max-height: none;
    aspect-ratio: var(--cols) / var(--rows);
    padding: 0;
    overflow: hidden;
    border: 2px solid rgba(255, 255, 255, .45);
    border-radius: 24px;
    background:
        radial-gradient(circle at 18% 26%, rgba(244, 255, 196, .18) 0 3px, transparent 4px),
        linear-gradient(180deg, #72a52e, #6b9f30);
    box-shadow: inset 0 0 30px rgba(24, 77, 29, .22), 0 10px 28px rgba(28, 77, 29, .25);
    touch-action: none;
}

.katica-cell {
    position: relative;
    display: grid;
    place-items: center;
    min-width: 0;
    min-height: 0;
}

.katica-rock {
    position: absolute;
    z-index: 2;
    inset: -2%;
    width: 104%;
    height: 104%;
    object-fit: contain;
    filter: drop-shadow(0 5px 4px rgba(39, 75, 38, .26));
    pointer-events: none;
}

.katica-goal {
    position: absolute;
    z-index: 4;
    inset: -8%;
    width: 116%;
    height: 116%;
    object-fit: contain;
    filter: drop-shadow(0 3px 2px rgba(0, 0, 0, .17));
    pointer-events: none;
}

.katica-decoration {
    position: absolute;
    z-index: 0;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    mix-blend-mode: normal;
    pointer-events: none;
}

.katica-bug {
    position: absolute;
    z-index: 6;
    width: 94%;
    height: 94%;
    object-fit: contain;
    filter: drop-shadow(0 5px 3px rgba(37, 45, 39, .35));
    transform: rotate(var(--bug-angle)) scaleX(var(--bug-flip, 1));
    transition: transform .16s ease;
    pointer-events: none;
}

.katica-board--editing .katica-cell {
    border: 1px dashed rgba(255, 255, 255, .2);
    cursor: crosshair;
}
.katica-board--editing .katica-cell:hover { z-index: 8; outline: 3px solid #fff4a6; }

.katica-board--shake { animation: katica-shake .32s ease; }
@keyframes katica-shake {
    20% { transform: translateX(-7px); }
    40% { transform: translateX(7px); }
    60% { transform: translateX(-4px); }
    80% { transform: translateX(4px); }
}

.katica-controls {
    display: grid;
    grid-template-columns: repeat(3, 72px);
    grid-template-rows: repeat(2, 72px);
    gap: 9px;
    margin-top: 15px;
}

.katica-arrow {
    display: grid;
    place-items: center;
    padding: 0;
    border: 0;
    border-radius: 50%;
    color: #fff;
    background: transparent;
    box-shadow: 0 7px 12px rgba(24, 60, 27, .25);
    cursor: pointer;
    transition: transform .12s ease, filter .12s ease;
}

.katica-arrow img { display: block; width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
.katica-arrow:hover { filter: brightness(1.09); transform: translateY(-2px) scale(1.03); }
.katica-arrow:active { transform: translateY(3px); box-shadow: 0 2px 5px rgba(44, 79, 42, .35); }

.katica-student-builder[hidden],
.katica-controls[hidden],
.katica-key-hint[hidden],
.katica-stats[hidden],
.katica-history-wrap[hidden],
.katica-reset[hidden],
.katica-builder-test[hidden],
.katica-builder-edit[hidden] { display: none !important; }

.katica-student-builder {
    margin: 10px 0 16px;
    padding: 14px;
    border: 1px solid #c8dcb7;
    border-radius: 14px;
    background: #f4faed;
}

.katica-student-builder h2 { margin: 0 0 4px; color: var(--katica-green-800); font-size: 1rem; }
.katica-student-builder > p { margin: 0 0 10px; color: #5d715e; font-size: .78rem; line-height: 1.35; }
.katica-builder-size { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin-bottom: 9px; }
.katica-builder-size label { margin: 0; font-size: .68rem; }
.katica-builder-size input { width: 100%; min-height: 34px; margin-top: 3px; padding: 5px 7px; border: 1px solid #a9c697; border-radius: 7px; }
.katica-builder-tools { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.katica-builder-tools button {
    display: flex;
    align-items: center;
    gap: 6px;
    min-height: 38px;
    padding: 5px 8px;
    border: 1px solid #b7ccb0;
    border-radius: 8px;
    color: #305b36;
    background: #fff;
    font: inherit;
    font-size: .75rem;
    font-weight: 800;
    cursor: pointer;
}
.katica-builder-tools button.active { color: #fff; border-color: var(--katica-green-800); background: var(--katica-green-800); }
.katica-builder-tools img,
.katica-builder-tools span { width: 25px; height: 25px; object-fit: contain; text-align: center; font-size: 1.2rem; }
.katica-builder-test,
.katica-builder-edit {
    width: 100%;
    min-height: 42px;
    margin-top: 9px;
    border: 0;
    border-radius: 9px;
    color: #fff;
    background: var(--katica-blue);
    font-weight: 850;
    cursor: pointer;
}
.katica-builder-edit { background: var(--katica-green-800); }
.katica-builder-status { min-height: 30px; margin: 8px 0 0 !important; font-size: .72rem !important; }

.katica-key-hint {
    margin: 9px 0 0;
    color: rgba(255, 255, 255, .88);
    font-size: .78rem;
    font-weight: 650;
}

.katica-dialog[hidden] { display: none; }
.katica-dialog {
    position: fixed;
    z-index: 10000;
    inset: 0;
    display: grid;
    place-items: center;
    overflow: hidden;
    padding: 20px;
    background: rgba(17, 44, 23, .67);
    backdrop-filter: blur(7px);
}

.katica-dialog__panel {
    position: relative;
    z-index: 2;
    width: min(430px, 100%);
    padding: 30px;
    border: 3px solid #fff;
    border-radius: 26px;
    background: var(--katica-cream);
    box-shadow: 0 24px 80px rgba(0, 0, 0, .3);
    text-align: center;
    animation: katica-pop .35s cubic-bezier(.2, .9, .3, 1.25);
}

@keyframes katica-pop { from { opacity: 0; transform: scale(.78); } }
.katica-dialog__icon { font-size: 3.8rem; }
.katica-dialog h2 { margin: 5px 0 8px; font-size: 2rem; }
.katica-dialog p { color: #4b5e4f; }
.katica-dialog .katica-eyebrow { color: var(--katica-green-600); }
.katica-stars { color: #f6b80f; font-size: 2.7rem; letter-spacing: .09em; }
.katica-dialog__actions { display: flex; justify-content: center; gap: 12px; margin-top: 18px; }

.katica-confetti {
    position: absolute;
    top: -20px;
    width: 10px;
    height: 18px;
    border-radius: 3px;
    animation: katica-confetti 1.9s linear forwards;
}

@keyframes katica-confetti {
    to { transform: translate(var(--drift), 110vh) rotate(680deg); }
}

.katica-login,
.katica-closed,
.katica-empty {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    width: min(620px, calc(100% - 32px));
    min-height: 590px;
    margin: 0 auto;
    padding: 48px 20px;
    color: #fff;
    text-align: center;
}

.katica-login__bug {
    display: block;
    width: 160px;
    max-width: 55vw;
    height: 112px;
    margin: 0 auto 12px;
    border-radius: 14px;
    object-fit: contain;
    filter: drop-shadow(0 9px 4px rgba(35, 67, 33, .25));
}
.katica-closed__icon,
.katica-empty > span { font-size: 6rem; filter: drop-shadow(0 9px 4px rgba(35, 67, 33, .25)); }
.katica-login > p:not(.katica-eyebrow),
.katica-closed > p:not(.katica-eyebrow),
.katica-empty p { margin: 12px auto 24px; font-size: 1.1rem; }
.katica-login__form { padding: 22px; border-radius: 20px; color: var(--katica-green-950); background: rgba(255, 250, 240, .94); box-shadow: var(--katica-shadow); text-align: left; }
.katica-login__form label { display: block; margin-bottom: 7px; font-weight: 850; }
.katica-password-row { display: flex; gap: 9px; }
.katica-password-row input { flex: 1; min-width: 0; min-height: 48px; padding: 10px 13px; border: 2px solid #b4d397; border-radius: 11px; font-size: 1rem; }
.katica-password-row button { padding: 10px 20px; border: 0; border-radius: 11px; color: #fff; background: var(--katica-green-800); font-weight: 850; cursor: pointer; }
.katica-alert { margin-top: 20px; padding: 15px; border-radius: 13px; }
.katica-alert--warning { color: #713f12; background: #fef3c7; }

.katica-arrow:focus-visible,
.katica-reset:focus-visible,
.katica-next:focus-visible,
.katica-sound:focus-visible,
.katica-logout:focus-visible,
.katica-sidebar select:focus-visible,
.katica-password-row input:focus-visible,
.katica-password-row button:focus-visible {
    outline: 4px solid #fff09c;
    outline-offset: 3px;
}

@media (max-width: 820px) {
    .katica-app { border-radius: 18px; }
    .katica-header { padding: 22px 20px 15px; }
    .katica-layout { grid-template-columns: 1fr; padding: 0 14px 20px; }
    .katica-sidebar { order: 2; }
    .katica-stage { order: 1; padding: 13px 8px 16px; }
    .katica-board { max-height: none; width: 100%; }
    .katica-sidebar { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; }
    .katica-sidebar label,
    .katica-sidebar select,
    .katica-level-meta,
    #katica-level-description,
    .katica-stats,
    .katica-history-wrap { grid-column: 1 / -1; }
    .katica-sidebar > .katica-reset { grid-column: 1 / -1; }
    .katica-sidebar > .katica-clear-progress,
    .katica-student-builder { grid-column: 1 / -1; }
}

@media (max-width: 520px) {
    .katica-header { align-items: center; }
    .katica-subtitle { display: none; }
    .katica-header h1 { font-size: 1.85rem; }
    .katica-controls { grid-template-columns: repeat(3, 52px); grid-template-rows: repeat(2, 52px); }
    .katica-key-hint { display: none; }
    .katica-password-row { flex-direction: column; }
    .katica-dialog__actions { flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
    .katica-app *, .katica-app *::before, .katica-app *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
