:root {
    --canvas: #ffffff;
    --surface: #f4f6f8;
    --surface-blue: #edf3ff;
    --ink: #111111;
    --muted: #62666d;
    --line: #111111;
    --line-soft: #c9cdd3;
    --blue: #2457ff;
    --blue-dark: #153dd1;
    --green: #178a43;
    --amber: #c06c00;
    --red: #d92525;
    --focus: #ffb800;
    --radius: 5px;
    --page-padding: clamp(1rem, 2.3vw, 2.25rem);
    --display: "Arial Narrow", "Helvetica Neue", Arial, sans-serif;
    --body: Arial, Helvetica, sans-serif;
}

* {
    box-sizing: border-box;
}

html {
    color-scheme: light;
    scroll-behavior: smooth;
}

body {
    margin: 0 auto;
    max-width: 1800px;
    min-width: 320px;
    background: var(--canvas);
    color: var(--ink);
    font-family: var(--body);
    font-size: 1rem;
    line-height: 1.45;
}

.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1rem;
    background: var(--surface);
}

.login-shell {
    width: min(100%, 520px);
}

.login-card {
    padding: clamp(1.5rem, 5vw, 3rem);
    border: 2px solid var(--line);
    border-radius: var(--radius);
    background: var(--canvas);
    box-shadow: 12px 12px 0 var(--blue);
}

.login-kicker {
    margin: 0 0 0.5rem;
    color: var(--blue);
    font-size: 0.82rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.login-card h1 {
    margin: 0;
    font-family: var(--display);
    font-size: clamp(2.5rem, 9vw, 4.5rem);
    font-weight: 900;
    letter-spacing: -0.045em;
    line-height: 0.95;
}

.login-intro {
    max-width: 38ch;
    margin: 1rem 0 1.5rem;
    color: var(--muted);
}

.login-form {
    display: grid;
    gap: 1rem;
}

.login-form label {
    display: grid;
    gap: 0.4rem;
    font-weight: 700;
}

.login-form input {
    width: 100%;
    min-height: 50px;
    padding: 0.7rem 0.8rem;
    border: 2px solid var(--line);
    border-radius: var(--radius);
    background: var(--canvas);
    color: var(--ink);
}

.login-form .button {
    width: 100%;
}

.login-error {
    margin: 0 0 1rem;
    padding: 0.75rem;
    border-left: 4px solid var(--red);
    background: #fff0f0;
    color: var(--red);
    font-weight: 700;
}

.logout-form {
    margin: 0;
}

button,
input,
select,
textarea {
    font: inherit;
}

button,
select {
    min-height: 44px;
}

button {
    cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex="0"]:focus-visible,
summary:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
}

.skip-link {
    position: fixed;
    left: 1rem;
    top: 1rem;
    z-index: 100;
    padding: 0.65rem 1rem;
    background: var(--ink);
    color: #fff;
    transform: translateY(-180%);
}

.skip-link:focus {
    transform: translateY(0);
}

.visually-hidden {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

.site-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 2rem;
    margin: 0 var(--page-padding);
    padding: 1.45rem 0 1.15rem;
    border-bottom: 2px solid var(--line);
}

.brand {
    display: flex;
    align-items: baseline;
    gap: clamp(1rem, 2.5vw, 2.5rem);
    min-width: 0;
}

.brand h1 {
    margin: 0;
    font-family: var(--display);
    font-size: clamp(2.2rem, 4vw, 4rem);
    font-weight: 900;
    letter-spacing: -0.045em;
    line-height: 0.95;
}

.brand p {
    margin: 0;
    color: var(--muted);
    white-space: nowrap;
}

.header-actions,
.detail-actions,
.copy-button-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 46px;
    padding: 0.7rem 1.15rem;
    border: 2px solid var(--blue);
    border-radius: var(--radius);
    background: var(--canvas);
    color: var(--blue);
    font-weight: 700;
    line-height: 1.1;
    text-decoration: none;
}

.button:hover {
    background: var(--surface-blue);
}

.button:active {
    transform: translateY(1px);
}

.button-primary {
    background: var(--blue);
    color: #fff;
}

.button-primary:hover {
    background: var(--blue-dark);
    border-color: var(--blue-dark);
}

.button-danger {
    border-color: var(--red);
    color: var(--red);
}

.summary-strip {
    display: grid;
    grid-template-columns: minmax(0, 3fr) minmax(260px, 1fr);
    gap: clamp(1.5rem, 4vw, 4rem);
    align-items: center;
    margin: 0 var(--page-padding);
    padding: 1.6rem 0 1.7rem;
    border-bottom: 2px solid var(--line);
}

.headline-stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 1.5rem;
    margin: 0;
}

.headline-stats div,
.topic-extremes div,
.detail-stats div {
    min-width: 0;
}

.headline-stats dt,
.topic-extremes dt,
.detail-stats dt {
    margin-bottom: 0.35rem;
    font-size: 0.9rem;
    font-weight: 700;
}

.headline-stats dd {
    margin: 0;
    font-family: var(--display);
    font-size: clamp(2.35rem, 4vw, 3.65rem);
    font-weight: 900;
    letter-spacing: -0.035em;
    line-height: 1;
    white-space: nowrap;
}

.headline-stats dd small {
    font-family: var(--body);
    font-size: 0.95rem;
    font-weight: 400;
    letter-spacing: 0;
}

.topic-extremes {
    display: grid;
    gap: 0.85rem;
    margin: 0;
}

.topic-extremes div {
    display: grid;
    grid-template-columns: 6rem minmax(0, 1fr);
    gap: 0.5rem;
}

.topic-extremes dt,
.topic-extremes dd {
    margin: 0;
}

.topic-extremes dd {
    overflow-wrap: anywhere;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: minmax(640px, 2.35fr) minmax(360px, 1fr);
    margin: 0 var(--page-padding);
    border-bottom: 2px solid var(--line);
}

.topic-section {
    min-width: 0;
    padding: 1.35rem 1.6rem 1.5rem 0;
}

.section-heading,
.detail-heading,
.form-heading,
.history-heading,
.chart-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.section-heading {
    margin-bottom: 0.8rem;
}

.section-heading h2,
.detail-heading h2,
.detail-empty h2 {
    margin: 0;
    font-family: var(--display);
    font-size: clamp(1.65rem, 2.4vw, 2.25rem);
    font-weight: 900;
    letter-spacing: -0.025em;
    line-height: 1.05;
}

.sort-control {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    white-space: nowrap;
}

.sort-control select {
    min-width: 190px;
    border: 1.5px solid var(--ink);
    border-radius: var(--radius);
    background: var(--canvas);
    padding: 0.55rem 2.2rem 0.55rem 0.7rem;
    color: var(--ink);
}

.table-scroll {
    overflow-x: auto;
    border-top: 1.5px solid var(--line);
    border-bottom: 1.5px solid var(--line);
}

.topic-table {
    width: 100%;
    min-width: 790px;
    border-collapse: collapse;
    font-variant-numeric: tabular-nums;
}

.topic-table th,
.topic-table td {
    padding: 0.72rem 0.65rem;
    border-bottom: 1px solid #9da2aa;
    text-align: left;
    vertical-align: middle;
    white-space: nowrap;
}

.topic-table th {
    font-size: 0.88rem;
    font-weight: 800;
}

.topic-table th:first-child,
.topic-table td:first-child {
    width: 34%;
    white-space: normal;
}

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

.topic-table tbody tr {
    cursor: pointer;
}

.topic-table tbody tr:hover {
    background: var(--surface);
}

.topic-table tbody tr:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: -3px;
}

.topic-table tbody tr[aria-selected="true"] {
    background: var(--surface-blue);
}

.topic-name {
    display: flex;
    align-items: baseline;
    gap: 0.55rem;
    font-weight: 700;
}

.topic-number {
    min-width: 1.8rem;
    color: var(--blue);
    font-variant-numeric: tabular-nums;
    font-weight: 800;
}

.status {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.status::before {
    width: 0.7rem;
    height: 0.7rem;
    flex: 0 0 auto;
    background: var(--status-colour, #777);
    content: "";
}

.status-not-started {
    --status-colour: #9da2aa;
}

.status-learning {
    --status-colour: var(--amber);
}

.status-tested {
    --status-colour: var(--blue);
}

.status-improving {
    --status-colour: var(--blue);
}

.status-strong {
    --status-colour: var(--green);
}

.positive {
    color: var(--green);
    font-weight: 700;
}

.negative {
    color: var(--red);
    font-weight: 700;
}

.muted {
    color: var(--muted);
}

.table-hint {
    margin: 0.65rem 0 0;
    color: var(--muted);
    font-size: 0.85rem;
}

.detail-panel {
    min-width: 0;
    padding: 1.35rem 0 1.5rem 1.8rem;
    border-left: 1.5px solid var(--line);
}

.detail-empty {
    display: grid;
    align-content: center;
    min-height: 500px;
    text-align: center;
}

.detail-empty p {
    max-width: 30rem;
    margin: 0.7rem auto 0;
    color: var(--muted);
}

.detail-empty .detail-index {
    margin: 0 0 0.6rem;
    color: var(--blue);
    font-family: var(--display);
    font-size: 3.5rem;
    font-weight: 900;
    letter-spacing: -0.03em;
}

.detail-heading {
    align-items: flex-start;
    padding-bottom: 0.8rem;
    border-bottom: 1.5px solid var(--line);
}

.detail-course-number {
    margin: 0 0 0.2rem;
    color: var(--blue);
    font-size: 0.85rem;
    font-weight: 800;
}

.text-button {
    min-height: 38px;
    padding: 0.35rem 0;
    border: 0;
    background: transparent;
    color: var(--blue);
    font-weight: 700;
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 0.18em;
}

.text-button:hover {
    color: var(--blue-dark);
}

.detail-close {
    display: none;
}

.detail-stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.8rem;
    margin: 0;
    padding: 1.1rem 0;
    border-bottom: 1px solid var(--line-soft);
}

.detail-stats dd {
    margin: 0;
    font-family: var(--display);
    font-size: clamp(1.5rem, 1.85vw, 2rem);
    font-weight: 900;
    letter-spacing: -0.025em;
    white-space: nowrap;
}

.mini-chart-block {
    padding: 1rem 0;
}

.mini-chart-block h3,
.history-heading h3,
.form-heading h3,
.chart-heading h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 800;
}

.line-chart {
    min-height: 170px;
    margin-top: 0.6rem;
}

.line-chart svg {
    display: block;
    width: 100%;
    height: auto;
    overflow: visible;
}

.chart-grid-line {
    stroke: #d4d7dc;
    stroke-width: 1;
}

.chart-axis-label,
.chart-point-label,
.chart-date-label {
    fill: var(--muted);
    font-family: var(--body);
    font-size: 11px;
}

.chart-point-label {
    fill: var(--ink);
    font-weight: 700;
}

.chart-line {
    fill: none;
    stroke: var(--blue);
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 3;
}

.chart-point {
    fill: #fff;
    stroke: var(--blue);
    stroke-width: 3;
}

.chart-empty {
    display: grid;
    place-items: center;
    min-height: 150px;
    margin: 0;
    border: 1px dashed var(--line-soft);
    color: var(--muted);
    text-align: center;
}

.detail-actions {
    margin-bottom: 1rem;
}

.detail-actions .button {
    flex: 1 1 0;
}

.entry-form {
    margin: 0 0 1rem;
    padding: 1rem;
    border: 1.5px solid var(--line);
    background: var(--surface);
}

.form-heading {
    margin-bottom: 0.8rem;
}

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

.form-grid-thirds {
    grid-template-columns: 1.2fr 1fr 1fr;
}

.entry-form label {
    display: block;
    margin-bottom: 0.75rem;
    color: var(--ink);
    font-size: 0.85rem;
    font-weight: 700;
}

.entry-form label span {
    display: block;
    margin-bottom: 0.3rem;
}

.entry-form label small {
    color: var(--muted);
    font-weight: 400;
}

.entry-form input,
.entry-form textarea {
    width: 100%;
    min-height: 44px;
    border: 1.5px solid #737780;
    border-radius: var(--radius);
    background: #fff;
    padding: 0.6rem 0.7rem;
    color: var(--ink);
}

.entry-form textarea {
    min-height: 74px;
    resize: vertical;
}

.score-preview {
    align-self: center;
    padding: 0.7rem;
    border-bottom: 2px solid var(--blue);
    color: var(--blue);
    font-weight: 800;
    text-align: center;
}

.form-submit {
    width: 100%;
}

.form-error {
    min-height: 1.25rem;
    margin: 0 0 0.5rem;
    color: var(--red);
    font-size: 0.85rem;
    font-weight: 700;
}

.history-section {
    margin-top: 1.1rem;
    padding-top: 0.9rem;
    border-top: 1.5px solid var(--line);
}

.history-heading {
    margin-bottom: 0.55rem;
}

.history-list {
    margin: 0;
    padding: 0;
    list-style: none;
}

.history-item {
    display: grid;
    grid-template-columns: 5.5rem minmax(6.5rem, 1fr) auto;
    gap: 0.65rem;
    align-items: center;
    padding: 0.65rem 0;
    border-bottom: 1px solid var(--line-soft);
    font-size: 0.86rem;
}

.history-item:last-child {
    border-bottom: 0;
}

.history-date,
.history-value {
    font-variant-numeric: tabular-nums;
}

.history-no-note {
    color: var(--muted);
    font-size: 0.82rem;
}

.history-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 0.7rem;
}

.history-actions button {
    min-height: 36px;
    padding: 0.2rem 0;
}

.delete-button {
    color: var(--red);
}

.empty-history {
    margin: 1rem 0;
    color: var(--muted);
}

.notes-dialog {
    width: min(720px, calc(100vw - 2rem));
    max-width: none;
    max-height: min(82vh, 760px);
    padding: 0;
    border: 2px solid var(--line);
    border-radius: var(--radius);
    background: var(--canvas);
    color: var(--ink);
    box-shadow: 0 1.25rem 4rem rgb(0 0 0 / 0.28);
}

.notes-dialog::backdrop {
    background: rgb(17 17 17 / 0.68);
}

.notes-dialog-shell {
    padding: clamp(1rem, 3vw, 1.75rem);
}

.notes-dialog-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid var(--line);
}

.notes-dialog-heading h2 {
    margin: 0;
    font-family: var(--display);
    font-size: clamp(1.8rem, 4vw, 2.5rem);
    font-weight: 900;
    letter-spacing: -0.03em;
}

.notes-dialog-heading form {
    margin: 0;
}

.notes-dialog-meta {
    margin: 0 0 0.25rem;
    color: var(--blue);
    font-size: 0.82rem;
    font-weight: 800;
    text-transform: uppercase;
}

.notes-dialog-content {
    max-height: min(58vh, 520px);
    margin: 0;
    padding: 1.25rem 0 0;
    overflow: auto;
    color: var(--ink);
    font-size: 1rem;
    line-height: 1.65;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}

.charts-section {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2.5rem;
    margin: 0 var(--page-padding);
    padding: 1.45rem 0 1.8rem;
    border-bottom: 2px solid var(--line);
}

.chart-panel {
    min-width: 0;
}

.chart-heading {
    align-items: baseline;
    margin-bottom: 1rem;
}

.chart-heading h3 {
    font-family: var(--display);
    font-size: 1.35rem;
    font-weight: 900;
}

.chart-heading p {
    margin: 0;
    color: var(--muted);
    font-size: 0.84rem;
}

.mastery-chart {
    display: grid;
    gap: 0.72rem;
}

.mastery-row {
    display: grid;
    grid-template-columns: minmax(150px, 1.1fr) minmax(120px, 2fr) 3.2rem;
    gap: 0.75rem;
    align-items: center;
    font-size: 0.84rem;
}

.mastery-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mastery-track {
    height: 0.72rem;
    background: #e3e6ea;
}

.mastery-fill {
    display: block;
    height: 100%;
    background: var(--blue);
}

.mastery-value {
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    text-align: right;
}

.overall-chart {
    min-height: 270px;
}

.copy-tools {
    margin: 0 var(--page-padding) 3rem;
    border-bottom: 2px solid var(--line);
}

.copy-tools summary {
    padding: 1rem 0;
    font-family: var(--display);
    font-size: 1.25rem;
    font-weight: 900;
    cursor: pointer;
}

.copy-tools-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0 0 1.25rem;
}

.copy-tools-content p {
    margin: 0;
    color: var(--muted);
}

.toast {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    z-index: 50;
    min-width: 150px;
    max-width: min(360px, calc(100vw - 2rem));
    padding: 0.8rem 1rem;
    border: 2px solid var(--ink);
    border-radius: var(--radius);
    background: var(--ink);
    color: #fff;
    font-weight: 700;
    opacity: 0;
    pointer-events: none;
    transform: translateY(0.5rem);
}

.toast.is-visible {
    opacity: 1;
    transform: translateY(0);
}

[hidden] {
    display: none !important;
}

@media (max-width: 1100px) {
    .summary-strip {
        grid-template-columns: 1fr;
        gap: 1.4rem;
    }

    .topic-extremes {
        grid-template-columns: 1fr 1fr;
    }

    .dashboard-grid {
        grid-template-columns: minmax(0, 1fr);
    }

    .topic-section {
        padding-right: 0;
    }

    .detail-panel {
        padding: 1.35rem 0 1.5rem;
        border-top: 2px solid var(--line);
        border-left: 0;
    }

    .detail-empty {
        min-height: 250px;
    }

    .detail-close {
        display: block;
    }
}

@media (max-width: 760px) {
    .site-header {
        align-items: flex-start;
        padding-top: 1rem;
    }

    .brand {
        display: block;
    }

    .brand h1 {
        font-size: 2.35rem;
    }

    .brand p {
        margin-top: 0.35rem;
        font-size: 0.85rem;
    }

    .header-actions {
        align-items: stretch;
        flex-direction: column;
        width: auto;
    }

    .header-actions .button {
        min-height: 42px;
        padding: 0.55rem 0.8rem;
    }

    .headline-stats {
        grid-template-columns: 1fr 1fr;
        row-gap: 1.4rem;
    }

    .headline-stats dd {
        font-size: 2.4rem;
    }

    .topic-extremes {
        grid-template-columns: 1fr;
    }

    .section-heading {
        align-items: stretch;
        flex-direction: column;
    }

    .sort-control {
        justify-content: space-between;
    }

    .sort-control select {
        flex: 1;
        min-width: 0;
    }

    .detail-stats {
        grid-template-columns: 1fr 1fr;
    }

    .detail-actions {
        align-items: stretch;
        flex-direction: column;
    }

    .form-grid,
    .form-grid-thirds {
        grid-template-columns: 1fr;
    }

    .history-item {
        grid-template-columns: 5.5rem minmax(0, 1fr);
    }

    .history-actions {
        grid-column: 1 / -1;
        justify-content: flex-end;
    }

    .notes-dialog-heading {
        align-items: stretch;
        flex-direction: column;
    }

    .notes-dialog-heading .button {
        width: 100%;
    }

    .charts-section {
        grid-template-columns: 1fr;
    }

    .copy-tools-content {
        align-items: stretch;
        flex-direction: column;
    }

    .copy-button-row {
        align-items: stretch;
        flex-direction: column;
    }
}

@media (max-width: 470px) {
    .site-header {
        display: block;
    }

    .header-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
        margin-top: 1rem;
    }

    .header-actions .button {
        width: 100%;
    }

    .headline-stats {
        gap: 1.15rem 0.65rem;
    }

    .topic-extremes div {
        display: block;
    }

    .topic-extremes dt {
        margin-bottom: 0.15rem;
    }

    .mastery-row {
        grid-template-columns: minmax(110px, 1fr) minmax(80px, 1.5fr) 2.8rem;
        gap: 0.45rem;
    }
}

@media (prefers-reduced-motion: no-preference) {
    .button,
    .toast {
        transition: background-color 140ms ease, border-color 140ms ease, color 140ms ease, opacity 140ms ease, transform 140ms ease;
    }
}

@media (forced-colors: active) {
    .status::before,
    .mastery-fill {
        border: 1px solid CanvasText;
    }
}
