:root {
    --bg: #f6f9e8;
    --ink: #212529;
    --panel: #ffffff;
    --accent: #bccc34;
    --accent-soft: #a8b92f;
    --line: #d9e2a9;
    --warm: #f7f1e6;
    --warm-line: #e2d2b8;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
    background:
        radial-gradient(circle at top left, rgba(188, 204, 52, 0.18), transparent 30%),
        radial-gradient(circle at right 8%, rgba(168, 185, 47, 0.1), transparent 22%),
        var(--bg);
    color: var(--ink);
}

.school-header {
    position: relative;
    overflow: hidden;
    background: linear-gradient(135deg, #d4e35f, #bccc34 68%, #a8b92f);
    color: #243109;
    border-bottom: 4px solid #a8b92f;
}

.school-header::after {
    content: none;
}

.school-header-inner {
    max-width: 1460px;
    margin: 0 auto;
    padding: 0.8rem 1.5rem 1.1rem;
    display: flex;
    gap: 1rem;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
}

.school-brand {
    display: flex;
    align-items: center;
    gap: 0;
    color: inherit;
    text-decoration: none;
}

.school-brand img {
    width: 232px;
    height: auto;
    display: block;
}

.site-nav {
    margin-left: auto;
    display: flex;
    flex-wrap: wrap;
    gap: 0.55rem;
    align-items: center;
}

.site-nav-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 2.4rem;
    padding: 0.45rem 0.9rem;
    border-radius: 999px;
    background: rgba(31, 42, 7, 0.1);
    border: 1px solid rgba(31, 42, 7, 0.24);
    color: #1f2a07;
    text-decoration: none;
    font-weight: 700;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

.site-nav-link:hover {
    background: rgba(31, 42, 7, 0.17);
}

.site-nav-link.active {
    background: rgba(255, 255, 255, 0.28);
    border-color: rgba(31, 42, 7, 0.34);
}

.layout {
    flex: 1 0 auto;
    max-width: 1380px;
    margin: 0 auto;
    padding: 1.5rem 1.5rem 5.2rem;
    display: grid;
    gap: 1rem;
    grid-template-columns: 1fr;
}

.panel {
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--panel);
    box-shadow: 0 14px 34px rgba(134, 146, 32, 0.14);
}

.controls,
.menu-panel,
.canvas-wrap,
.admin-sidebar,
.admin-editor {
    padding: 1rem;
}

.menu-panel h2,
.admin-sidebar h1,
.admin-editor h2 {
    margin-top: 0;
}

.pattern-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 0.45rem;
}

.pattern-category {
    margin-top: 0.4rem;
    font-size: 0.82rem;
}

.pattern-category-toggle {
    width: 100%;
    text-align: left;
    background: #f2f8d2;
    color: #465614;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 0.42rem 0.55rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-size: 0.79rem;
}

.pattern-category-toggle:hover {
    background: #e9f2be;
}

.pattern-item {
    width: 100%;
    text-align: left;
    border: 1px solid var(--line);
    background: #ffffff;
    color: #29313b;
    border-radius: 10px;
    padding: 0.52rem 0.62rem;
    font-weight: 700;
}

.pattern-item.active {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(188, 204, 52, 0.38);
}

.pattern-item.solved {
    background: #f4f9db;
    border-color: #c1d45b;
    color: #4a5b13;
}

.current-pattern {
    margin: 0.2rem 0 0.55rem;
    color: #2e3742;
    font-weight: 700;
}

h1 {
    margin-top: 0;
    margin-bottom: 0.5rem;
}

label {
    display: block;
    margin-bottom: 0.35rem;
}

select,
textarea,
.task-filter,
.field input,
.field textarea {
    width: 100%;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: #ffffff;
    color: #27303b;
    padding: 0.55rem 0.7rem;
    font-size: 0.95rem;
}

textarea,
.command-box,
.field textarea {
    min-height: 260px;
    resize: vertical;
    font-family: "Consolas", "Courier New", monospace;
    font-size: 14px;
}

.task-filter,
.field input,
.field textarea {
    min-height: auto;
}

.task-filter:focus,
.field input:focus,
.field textarea:focus,
textarea:focus,
select:focus {
    outline: 2px solid rgba(188, 204, 52, 0.45);
    outline-offset: 1px;
}



.actions,
.admin-actions {
        margin-top: 0.55rem;
        display: flex;
        flex-wrap: nowrap;
        gap: 0.22rem;
}

@media (max-width: 600px) {
    .actions, .admin-actions {
        flex-wrap: wrap;
    }
}

.actions button {
    flex: 1 1 0;
    min-width: 0;
    padding: 0.32rem 0.32rem;
    font-size: 0.80rem;
    white-space: nowrap;
    margin: 0;
}

.speed-control {
    margin-top: 0.75rem;
    display: grid;
    gap: 0.3rem;
}

.speed-control input[type="range"] {
    width: 100%;
}

.speed-value {
    font-size: 0.9rem;
    color: #47515f;
    font-weight: 700;
}

.result {
    min-height: 1.4rem;
    margin: 0.65rem 0 0;
    font-weight: 700;
}

.result.ok {
    color: #4f6012;
}

.result.bad {
    color: #a33a2b;
}

button {
    border: none;
    border-radius: 10px;
    padding: 0.55rem 0.9rem;
    font-weight: 700;
    cursor: pointer;
    background: var(--accent);
    color: #fff;
}

button:hover {
    background: var(--accent-soft);
}

button.secondary {
    background: #57606f;
}

button.danger {
    background: #b63a2f;
}

button.danger:disabled {
    background: #cfa8a3;
    cursor: not-allowed;
}

.hint {
    margin: 0.8rem 0 0.4rem;
    color: #47515f;
}

.hint-container {
    margin: 0.4rem 0;
    display: grid;
    gap: 0.4rem;
}

.hint-toggle {
    background: #f2f8d2;
    color: #4a5b13;
    border: 1px solid #c9d97a;
    border-radius: 8px;
    padding: 0.35rem 0.75rem;
    font-size: 0.88rem;
    font-weight: 700;
    cursor: pointer;
    width: fit-content;
}

.hint-toggle:hover {
    background: #e9f2be;
}

.hint-body {
    margin: 0;
    background: #f8fbe9;
    border-left: 3px solid #bccc34;
    border-radius: 0 8px 8px 0;
    padding: 0.5rem 0.75rem;
    color: #42510f;
    font-size: 0.93rem;
}

.hint-used-badge {
    font-size: 0.72rem;
    font-weight: 700;
    color: #5a3a00;
    background: #ffe7a8;
    border-radius: 5px;
    padding: 0 4px;
    margin-left: 5px;
    vertical-align: middle;
}

.pattern-time {
    font-size: 0.7rem;
    font-weight: 700;
    color: #4a5b13;
    background: #edf4c8;
    border-radius: 999px;
    padding: 0 0.36rem;
    margin-left: 0.4rem;
    vertical-align: middle;
}

#log {
    min-height: 42px;
    margin: 0;
    color: #9b1c1c;
    white-space: pre-wrap;
}

.canvas-stack {
    display: grid;
    gap: 0.75rem;
}

.reference-label {
    font-size: 0.95rem;
    color: #7b848f;
    font-weight: 700;
}

canvas {
    width: 100%;
    max-width: 100%;
    border: 1px solid var(--line);
    border-radius: 12px;
    display: block;
    background: #ffffff;
}

.admin-layout {
    max-width: 1460px;
    align-items: start;
    grid-template-columns: 340px minmax(0, 1fr);
}

.sandbox-layout {
    max-width: 1380px;
    align-items: start;
    grid-template-columns: 300px minmax(0, 1fr) minmax(0, 1.15fr);
}

.sandbox-panel {
    max-width: 100%;
}

.sandbox-sidebar {
    padding: 1rem;
}

.sandbox-sidebar h2 {
    margin-top: 0;
}

.sandbox-shortcuts {
    display: grid;
    gap: 0.45rem;
    margin: 0.8rem 0 0.6rem;
}

.sandbox-shortcut {
    width: 100%;
    text-align: left;
}

.sandbox-canvas-wrap {
    min-width: 0;
}

@media (max-width: 899px) {
    .sandbox-layout {
        grid-template-columns: 1fr;
    }
}

.sandbox-terminal {
    display: grid;
    gap: 0.7rem;
    padding: 0.9rem;
    border: 1px solid #1b2a18;
    border-radius: 14px;
    background: linear-gradient(180deg, #111a12, #171f16);
    color: #d9f1d0;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.sandbox-history {
    min-height: 150px;
    max-height: 240px;
    overflow: auto;
    padding: 0.75rem;
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.22);
    border: 1px solid rgba(192, 230, 179, 0.12);
    font-family: "Consolas", "Courier New", monospace;
    white-space: pre-wrap;
}

.sandbox-history-line {
    line-height: 1.45;
}

.sandbox-history-line.command {
    color: #d9f1d0;
}

.sandbox-history-line.system {
    color: #a8d08d;
}

.sandbox-prompt-row {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto auto;
    gap: 0.55rem;
    align-items: center;
}

.sandbox-prompt {
    font-family: "Consolas", "Courier New", monospace;
    font-weight: 700;
    color: #b8df9f;
}

.sandbox-input {
    width: 100%;
    min-width: 0;
    border-radius: 10px;
    border: 1px solid rgba(192, 230, 179, 0.18);
    background: rgba(255, 255, 255, 0.08);
    color: #eff9ea;
    padding: 0.65rem 0.75rem;
    font-family: "Consolas", "Courier New", monospace;
    font-size: 0.95rem;
}

.sandbox-input::placeholder {
    color: rgba(239, 249, 234, 0.55);
}

.sandbox-input:focus {
    outline: 2px solid rgba(188, 204, 52, 0.35);
    outline-offset: 1px;
}

.task-list-wrap {
    margin-top: 0.8rem;
    max-height: 78vh;
    overflow: auto;
}

.task-list {
    display: grid;
    gap: 0.45rem;
    list-style: none;
    margin: 0;
    padding: 0;
}

.task-button {
    width: 100%;
    border: 1px solid var(--line);
    background: #ffffff;
    color: #29313b;
    border-radius: 12px;
    padding: 0.6rem 0.7rem;
    text-align: left;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.task-button.active {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(188, 204, 52, 0.34);
}

.task-button.overridden {
    background: #f6fae3;
}

.task-id {
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.task-badge {
    flex: 0 0 auto;
    font-size: 0.72rem;
    font-weight: 700;
    color: #5a3a00;
    background: #ffe7a8;
    border-radius: 999px;
    padding: 0.15rem 0.5rem;
}

.admin-editor {
    display: grid;
    gap: 0.9rem;
}

.editor-topbar {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 0.5rem;
    align-items: flex-start;
}

.field-grid {
    display: grid;
    gap: 0.75rem;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.field {
    display: grid;
    gap: 0.35rem;
}

.command-box {
    min-height: 320px;
}

#initialTextInput {
    min-height: 96px;
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}

#commandsInput::selection {
    background: #bccc34;
    color: #1f2a07;
}

::selection {
    background: #bccc34;
    color: #1f2a07;
}

.admin-note {
    margin: 0;
    color: #47515f;
}

.admin-status {
    margin: 0;
    font-weight: 700;
    color: #2e3742;
}

.admin-status.ok {
    color: #4f6012;
}

.admin-status.bad {
    color: #a33a2b;
}

.admin-preview {
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #f8fbe9;
    padding: 0.75rem;
    display: grid;
    gap: 0.55rem;
}

.admin-preview-topbar {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: baseline;
    gap: 0.35rem 0.8rem;
}

.admin-preview-topbar h3 {
    margin: 0;
    font-size: 1rem;
}

#previewFrame {
    width: 100%;
    min-height: 420px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #ffffff;
}

.app-footer {
    margin-top: auto;
    position: sticky;
    bottom: 0;
    z-index: 25;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.9rem;
    flex-wrap: wrap;
    padding: 0.55rem 1rem;
    background: rgba(168, 185, 47, 0.95);
    color: #1f2a07;
    border-top: 1px solid rgba(31, 42, 7, 0.2);
    backdrop-filter: blur(4px);
}

.footer-owner {
    font-size: 0.84rem;
    font-weight: 700;
    letter-spacing: 0.01em;
}

.footer-stats {
    display: flex;
    gap: 0.45rem;
    flex-wrap: wrap;
}

.footer-stat {
    display: inline-flex;
    align-items: center;
    min-height: 1.75rem;
    padding: 0.1rem 0.52rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.5);
    border: 1px solid rgba(31, 42, 7, 0.18);
    font-size: 0.8rem;
    font-weight: 700;
    white-space: nowrap;
}

@media (min-width: 900px) {
    .layout {
        grid-template-columns: 290px 380px 1fr;
        align-items: start;
    }

    .menu-panel {
        max-height: 88vh;
        overflow: auto;
        position: sticky;
        top: 1rem;
    }

    .admin-layout {
        grid-template-columns: 340px minmax(0, 1fr);
    }

    .task-list-wrap {
        max-height: calc(100vh - 240px);
    }
}

@media (max-width: 899px) {
    .admin-layout {
        grid-template-columns: 1fr;
    }

    .field-grid {
        grid-template-columns: 1fr;
    }

    .school-header-inner {
        padding: 0.7rem 1rem;
    }

    .school-brand img {
        width: 176px;
    }

    .task-list-wrap {
        max-height: none;
    }

    .app-footer {
        justify-content: center;
        padding: 0.5rem 0.7rem;
    }
}
