* {
    box-sizing: border-box;
}

body {
    margin: 0;
    color: #172033;
    background: #f3f6f9;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a {
    color: inherit;
}

.page {
    display: grid;
    min-height: 100vh;
    place-items: center;
    padding: 24px;
}

.panel {
    width: min(100%, 420px);
    padding: 28px;
    background: #ffffff;
    border: 1px solid #d7dde5;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(31, 41, 55, 0.08);
}

h1,
h2,
h3,
p,
dl {
    margin-top: 0;
}

h1 {
    margin-bottom: 12px;
    font-size: 30px;
}

h2 {
    margin-bottom: 12px;
    font-size: 21px;
}

h3 {
    margin-bottom: 8px;
    font-size: 17px;
}

.form {
    display: grid;
    gap: 16px;
}

label {
    display: grid;
    gap: 6px;
    font-weight: 700;
}

input,
select,
textarea {
    width: 100%;
    min-height: 44px;
    padding: 10px 12px;
    color: #172033;
    background: #ffffff;
    border: 1px solid #aeb7c2;
    border-radius: 6px;
    font: inherit;
}

textarea {
    min-height: 140px;
    resize: vertical;
    line-height: 1.6;
}

button,
.button-link {
    min-height: 44px;
    padding: 10px 16px;
    color: #ffffff;
    background: #1767a8;
    border: 0;
    border-radius: 6px;
    font: inherit;
    font-weight: 700;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
}

button:hover,
.button-link:hover {
    background: #12598f;
}

.secondary-button {
    min-height: 36px;
    width: auto;
    padding: 7px 12px;
    color: #1767a8;
    background: #e9f2fb;
}

.secondary-button:hover {
    background: #d9eaf9;
}

.disabled-button {
    width: auto;
    min-width: 132px;
    color: #687385;
    background: #e1e6ed;
    cursor: not-allowed;
}

.disabled-button:hover {
    background: #e1e6ed;
}

.error {
    margin: 0;
    padding: 12px;
    color: #8a1f11;
    background: #fff0ed;
    border: 1px solid #f2b8ad;
    border-radius: 6px;
}

.app-header {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 14px clamp(16px, 4vw, 40px);
    background: #ffffff;
    border-bottom: 1px solid #dbe2ea;
}

.brand {
    font-size: 20px;
    font-weight: 800;
    text-decoration: none;
}

.header-user {
    display: flex;
    align-items: center;
    gap: 12px;
    color: #4b5565;
    font-size: 14px;
}

.header-user form {
    margin: 0;
}

.app-shell {
    width: min(1180px, 100%);
    margin: 0 auto;
    padding: 28px clamp(16px, 4vw, 40px) 48px;
}

.section-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 20px;
}

.section-head p {
    margin-bottom: 0;
    color: #647084;
}

.children-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 16px;
}

.child-card,
.drill-card {
    padding: 18px;
    background: #ffffff;
    border: 1px solid #d8e0e8;
    border-radius: 8px;
    box-shadow: 0 6px 18px rgba(23, 32, 51, 0.05);
}

.card-title-row,
.list-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.grade-pill,
.status-badge {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding: 4px 9px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
}

.grade-pill {
    color: #30566d;
    background: #e7f2f5;
}

.metric-list,
.drill-card dl {
    display: grid;
    gap: 10px;
    margin-bottom: 16px;
}

.metric-list div,
.drill-card dl div {
    display: flex;
    justify-content: space-between;
    gap: 14px;
}

dt {
    color: #647084;
    font-weight: 700;
}

dd {
    margin: 0;
    font-weight: 800;
}

.subject-links,
.subject-tabs,
.child-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.subject-links a,
.subject-tabs a,
.child-tabs a,
.back-link {
    min-height: 34px;
    padding: 7px 11px;
    color: #1767a8;
    background: #edf5fb;
    border: 1px solid #cfe2f3;
    border-radius: 6px;
    font-weight: 700;
    text-decoration: none;
}

.subject-links a:hover,
.subject-tabs a:hover,
.child-tabs a:hover,
.subject-tabs a.active,
.child-tabs a.active {
    color: #ffffff;
    background: #1767a8;
    border-color: #1767a8;
}

.empty-text {
    color: #718096;
    font-weight: 700;
}

.child-tabs {
    margin-bottom: 18px;
}

.subject-head {
    align-items: center;
}

.back-link {
    display: inline-flex;
    margin-bottom: 10px;
    color: #4b5565;
    background: #eef2f6;
    border-color: #d5dde6;
}

.filters {
    display: grid;
    grid-template-columns: repeat(5, minmax(120px, 1fr));
    align-items: end;
    gap: 12px;
    margin: 18px 0;
    padding: 16px;
    background: #ffffff;
    border: 1px solid #d8e0e8;
    border-radius: 8px;
}

.drill-list {
    margin-top: 18px;
}

.list-head {
    margin-bottom: 12px;
}

.list-head span {
    color: #647084;
    font-weight: 800;
}

.empty-state {
    padding: 28px;
    color: #647084;
    background: #ffffff;
    border: 1px dashed #b8c3cf;
    border-radius: 8px;
    text-align: center;
    font-weight: 700;
}

.muted-text {
    color: #647084;
}

.draft-form,
.info-panel,
.preview-panel,
.error-list {
    margin-bottom: 18px;
    padding: 18px;
    background: #ffffff;
    border: 1px solid #d8e0e8;
    border-radius: 8px;
}

.draft-form {
    display: grid;
    gap: 16px;
}

.error-list {
    color: #8a1f11;
    background: #fff0ed;
    border-color: #f2b8ad;
}

.error-list h2 {
    margin-bottom: 8px;
}

.summary-list {
    display: grid;
    gap: 10px;
    margin-bottom: 0;
}

.summary-list div {
    display: grid;
    grid-template-columns: minmax(120px, 180px) 1fr;
    gap: 12px;
    padding-bottom: 10px;
    border-bottom: 1px solid #e7ecf2;
}

.summary-list div:last-child {
    padding-bottom: 0;
    border-bottom: 0;
}

.preview-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.markdown-preview {
    line-height: 1.75;
}

.markdown-preview h2,
.markdown-preview h3,
.markdown-preview h4 {
    margin: 16px 0 8px;
}

.markdown-preview p,
.markdown-preview ul {
    margin-bottom: 14px;
}

.markdown-preview code {
    padding: 2px 5px;
    background: #eef2f6;
    border-radius: 4px;
}

.preview-placeholder {
    margin: 14px 0;
    padding: 12px;
    background: #f7f9fb;
    border: 1px dashed #b8c3cf;
    border-radius: 8px;
}

.preview-placeholder pre {
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}

.action-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 16px;
}

.secondary-link {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    padding: 10px 16px;
    color: #1767a8;
    background: #edf5fb;
    border: 1px solid #cfe2f3;
    border-radius: 6px;
    font-weight: 700;
    text-decoration: none;
}

.drill-table {
    width: 100%;
    border-collapse: collapse;
    background: #ffffff;
    border: 1px solid #d8e0e8;
    border-radius: 8px;
    overflow: hidden;
}

.drill-table th,
.drill-table td {
    padding: 12px;
    border-bottom: 1px solid #e3e8ee;
    text-align: left;
    vertical-align: top;
}

.drill-table th {
    color: #4b5565;
    background: #f7f9fb;
    font-size: 13px;
}

.drill-table tr:last-child td {
    border-bottom: 0;
}

.status-badge.unlearned {
    color: #6f4b00;
    background: #fff4d6;
}

.status-badge.overdue {
    color: #8a1f11;
    background: #ffe7e2;
}

.status-badge.studied {
    color: #196042;
    background: #ddf6e9;
}

.drill-cards {
    display: none;
}

@media (max-width: 760px) {
    .app-header,
    .header-user,
    .section-head {
        align-items: stretch;
        flex-direction: column;
    }

    .header-user {
        gap: 8px;
    }

    .header-user form,
    .header-user button,
    .disabled-button {
        width: 100%;
    }

    h1 {
        font-size: 25px;
    }

    .child-tabs,
    .subject-tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        padding-bottom: 4px;
    }

    .child-tabs a,
    .subject-tabs a {
        flex: 0 0 auto;
    }

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

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

    .summary-list div {
        grid-template-columns: 1fr;
        gap: 4px;
    }

    .drill-table {
        display: none;
    }

    .drill-cards {
        display: grid;
        gap: 12px;
    }

    .drill-card > div:first-child {
        display: grid;
        gap: 8px;
    }
}
