* {
    box-sizing: border-box;
}

html, body {
    height: 100%;
}

main {
    height: 100%;
}

body {
    margin: 0;
    background: linear-gradient(180deg, #f4f7fb 0%, #edf2f7 100%);
    font-family: "Segoe UI", Arial, sans-serif;
    color: #1f2937;
    overflow: hidden;
}

.worksheet-page {
    height: calc(100vh - 120px);
    min-height: 0;
    padding: 1rem 1.25rem 1rem;
}

.worksheet-editor {
    height: 100%;
    max-width: 1500px;
    margin: 0 auto;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 22px;
    box-shadow: 0 22px 50px rgba(15, 23, 42, 0.08);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
    padding: 1rem 1.25rem;
    background: #f8fafc;
    border-bottom: 1px solid #e5e7eb;
}

.toolbar-group {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.toolbar-label {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 700;
    color: #64748b;
}

.toolbar-actions {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-wrap: wrap;
}

.toolbar input[type="number"] {
    width: 110px;
    min-width: 110px;
    padding: 0.7rem 0.8rem;
    border-radius: 10px;
    border: 1px solid #d1d5db;
    background: #fff;
}

.toolbar button {
    border: none;
    border-radius: 10px;
    padding: 0.7rem 1rem;
    font-weight: 700;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.toolbar button:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 14px rgba(15, 23, 42, 0.08);
}

.worksheet-body {
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr) 260px;
    flex: 1;
    min-height: 0;
    height: 100%;
}

.left-panel,
.right-panel {
    background: #f8fafc;
    border-right: 1px solid #e5e7eb;
    padding: 1rem;
}

.right-panel {
    border-right: none;
    border-left: 1px solid #e5e7eb;
}

.panel-header {
    margin-bottom: 1rem;
}

.panel-header h3 {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 800;
    color: #1f2937;
}

.section-type-list {
    display: flex;
    flex-direction: column;
    gap: 0.7rem;
}

.type-btn,
.add-choice {
    width: 100%;
    text-align: left;
    border: 1px solid #dbe4f0;
    background: #fff;
    color: #1f2937;
    border-radius: 12px;
    padding: 0.8rem 0.9rem;
    font-weight: 700;
    transition: all 0.15s ease;
}

.type-btn:hover,
.add-choice:hover {
    background: #eef6ff;
    border-color: #b9d7ff;
}

.worksheet-main {
    padding: 1.25rem 1.5rem 1.5rem;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.worksheet-canvas {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
}

.worksheet-canvas::-webkit-scrollbar {
    width: 10px;
}

.worksheet-canvas::-webkit-scrollbar-track {
    background: #eef2f7;
    border-radius: 999px;
}

.worksheet-canvas::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 999px;
}

.worksheet-header {
    margin-bottom: 1rem;
}

.worksheet-header h1 {
    margin: 0 0 0.75rem;
    font-size: clamp(2rem, 2.5vw, 3rem);
    font-weight: 800;
    color: #111827;
}

.title-input {
    width: 100%;
    padding: 0.9rem 1rem;
    border-radius: 12px;
    border: 1px solid #d1d5db;
    font-size: 1.1rem;
}

.header-options {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: center;
    margin: 1.25rem 0;
    padding: 0.9rem 1rem;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    background: #f8fafc;
}

.header-options label {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    margin: 0;
    font-weight: 600;
    color: #374151;
}

.header-options input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: #2563eb;
}

#sections-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.section {
    background: transparent;
    border: none;
    border-radius: 0;
    padding: 0;
    box-shadow: none;
}

.section-card {
    background: linear-gradient(180deg, #ffffff 0%, #f9fafb 100%);
    border: 1px solid #e5e7eb;
    border-radius: 18px;
    box-shadow: 0 8px 18px rgba(15, 23, 42, 0.05);
    overflow: hidden;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

.section.is-selected .section-card {
    border-color: #60a5fa;
    box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.18);
    transform: translateY(-1px);
}

.section-card__header {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 0.75rem;
    padding: 0.9rem 1rem;
    background: #f8fafc;
    border-bottom: 1px solid #e5e7eb;
}

.section-card__badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.35rem 0.7rem;
    border-radius: 999px;
    background: #dbeafe;
    color: #1d4ed8;
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.section-card__actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.45rem;
}

.section-card__actions button {
    background: #e5e7eb;
    color: #111827;
    border: none;
    border-radius: 8px;
    padding: 0.45rem 0.7rem;
    font-weight: 700;
    cursor: pointer;
}

.section-card__body {
    padding: 1rem;
}

.toggle-row {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 0.9rem;
    font-weight: 600;
    color: #374151;
}

.toggle-row input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: #2563eb;
}

.section-card__meta {
    margin-bottom: 0.75rem;
    color: #64748b;
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.section-title {
    width: 100%;
    margin: 0;
    border: 1px solid #d1d5db;
    border-radius: 10px;
    background: #fff;
    padding: 0.7rem 0.8rem;
    font-size: 1.05rem;
}

.word-list-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.add-word-row {
    border: 1px solid #dbeafe;
    background: #eff6ff;
    color: #1d4ed8;
    border-radius: 10px;
    padding: 0.45rem 0.75rem;
    font-weight: 700;
    cursor: pointer;
}

.word-list {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

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

.word-row input[type="text"] {
    min-height: 42px;
    border-radius: 10px;
    border: 1px solid #d1d5db;
    background: #fff;
    padding: 0.7rem 0.8rem;
}

.remove-word {
    height: 42px;
    width: 42px;
    border: 1px solid #fecaca;
    background: #fff1f2;
    color: #be123c;
    border-radius: 10px;
    font-size: 1.25rem;
    font-weight: 700;
    cursor: pointer;
}

.word-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.7rem;
    margin-top: 0.8rem;
}

.word-grid input[type="text"] {
    min-height: 46px;
    border-radius: 10px;
    border: 1px solid #d1d5db;
    background: #fff;
    padding: 0.7rem 0.8rem;
}

.question-entry {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 0.9rem;
}

.question-entry__label {
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #64748b;
}

.question-input {
    width: 100%;
    border: 1px solid #d1d5db;
    border-radius: 10px;
    background: #fff;
    padding: 0.8rem 0.9rem;
    font-size: 1rem;
}

.add-question {
    width: 100%;
    border: none;
    border-radius: 10px;
    background: #e0f2fe;
    color: #0f172a;
    font-weight: 700;
    padding: 0.8rem 1rem;
    margin-bottom: 1rem;
    cursor: pointer;
}

.question-list {
    margin: 0.5rem 0 0;
    padding-left: 1.2rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    color: #374151;
}

.question-list li {
    padding: 0.45rem 0.55rem;
    background: #f8fafc;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    line-height: 1.4;
}

.translation-options {
    margin-bottom: 0.9rem;
}

.translation-label {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    font-weight: 600;
    color: #374151;
}

.translation-direction {
    border: 1px solid #d1d5db;
    border-radius: 10px;
    background: #fff;
    padding: 0.6rem 0.8rem;
    font-size: 0.95rem;
}

.translation-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.add-translation-pair {
    border: 1px solid #dbeafe;
    background: #eff6ff;
    color: #1d4ed8;
    border-radius: 10px;
    padding: 0.45rem 0.75rem;
    font-weight: 700;
    cursor: pointer;
}

.translation-pairs {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.translation-pair-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 24px minmax(0, 1fr) 38px;
    gap: 0.5rem;
    align-items: center;
}

.translation-source,
.translation-target {
    min-height: 42px;
    border-radius: 10px;
    border: 1px solid #d1d5db;
    background: #fff;
    padding: 0.65rem 0.8rem;
}

.translation-arrow {
    display: flex;
    align-items: center;
    justify-content: center;
    color: #64748b;
    font-weight: 800;
}

.remove-translation-pair {
    height: 42px;
    width: 42px;
    border: 1px solid #fecaca;
    background: #fff1f2;
    color: #be123c;
    border-radius: 10px;
    font-size: 1.25rem;
    font-weight: 700;
    cursor: pointer;
}

.word-search-options {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.8rem;
    margin-bottom: 1rem;
}

.wordsearch-option {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    font-weight: 600;
    color: #374151;
}

.wordsearch-option select,
.wordsearch-instructions {
    width: 100%;
    border: 1px solid #d1d5db;
    border-radius: 10px;
    background: #fff;
    padding: 0.7rem 0.8rem;
    font-size: 0.95rem;
}

.instructions-block {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.bottom-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-top: 1.5rem;
}

.bottom-buttons button {
    width: 100%;
    padding: 0.9rem 1rem;
    border-radius: 12px;
    font-weight: 700;
}

.bold {
    font-weight: 700;
}

.italic {
    font-style: italic;
}

.underline {
    text-decoration: underline;
}

.inspector-empty {
    padding: 1rem;
    border: 1px dashed #cbd5e1;
    border-radius: 12px;
    background: #fff;
    color: #64748b;
    font-size: 0.95rem;
}

.overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
}

.overlay.hidden {
    display: none;
}

.overlay-card {
    width: min(460px, calc(100vw - 2rem));
    background: #fff;
    border-radius: 18px;
    padding: 1.2rem;
    border: 1px solid #e5e7eb;
    box-shadow: 0 22px 44px rgba(15, 23, 42, 0.2);
}

.overlay-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.overlay-header h3 {
    margin: 0;
    font-size: 1.3rem;
}

.close-overlay {
    border: none;
    background: transparent;
    font-size: 1.7rem;
    line-height: 1;
    cursor: pointer;
}

.overlay-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.8rem;
}

.add-choice {
    text-align: center;
    padding: 1rem 0.7rem;
}

.section-outline {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.section-outline li {
    border: 1px solid #dbe4f0;
    background: #fff;
    color: #1f2937;
    border-radius: 10px;
    padding: 0.7rem 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
}

.section-outline li:hover {
    background: #eef6ff;
    border-color: #b9d7ff;
}

.section-outline li.is-active {
    background: #e0f2fe;
    border-color: #7dd3fc;
    color: #0f172a;
}

.outline-empty {
    color: #64748b;
    font-style: italic;
    background: #f8fafc;
    border-style: dashed;
}

@media (max-width: 980px) {
    .worksheet-body {
        grid-template-columns: 1fr;
    }

    .left-panel,
    .right-panel {
        border: none;
        border-bottom: 1px solid #e5e7eb;
    }

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