/* Addison Academy — weekly planner */

:root {
    --bg: #F6F4EF;
    --surface: #FFFFFF;
    --surface-2: #FBFAF7;
    --border: #E5E1D8;
    --border-strong: #D3CEC2;
    --text: #1E2321;
    --text-mute: #6D716C;
    --text-dim: #A3A59F;

    --accent: #2F5BEA;
    --accent-soft: rgba(47, 91, 234, 0.10);

    --done: #22B567;
    --done-bg: #DDF6E7;
    --done-text: #17643B;
    --done-glow: rgba(34, 181, 103, 0.45);

    --today: rgba(47, 91, 234, 0.06);
    --danger: #D64545;

    --radius: 14px;
    --shadow: 0 1px 2px rgba(20, 24, 22, 0.05), 0 4px 16px rgba(20, 24, 22, 0.05);

    /* Easings borrowed from Habit Gladiators' completion animations:
       --ease-sweep = the ring-fill sweep, --ease-spring = the star-pop overshoot. */
    --ease-sweep: cubic-bezier(0.65, 0, 0.35, 1);
    --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);

    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #121416;
        --surface: #1A1D20;
        --surface-2: #16191B;
        --border: #2A2E32;
        --border-strong: #3A3F44;
        --text: #EDEDE9;
        --text-mute: #969A94;
        --text-dim: #5E625D;
        --accent: #7C9BFF;
        --accent-soft: rgba(124, 155, 255, 0.14);
        --done: #3DDC84;
        --done-bg: #173A27;
        --done-text: #9BEBBE;
        --done-glow: rgba(61, 220, 132, 0.40);
        --today: rgba(124, 155, 255, 0.07);
        --shadow: none;
        color-scheme: dark;
    }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; }
body {
    background: var(--bg);
    color: var(--text);
    font-family: 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;
    font-size: 15px;
    line-height: 1.4;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
    min-height: 100dvh;
}
button, input, textarea { font: inherit; color: inherit; }

/* ---------- Buttons ---------- */
.btn {
    border: 1px solid var(--border-strong);
    background: var(--surface);
    border-radius: 10px;
    padding: 10px 16px;
    font-weight: 700;
    cursor: pointer;
    transition: background 150ms, border-color 150ms, transform 120ms;
}
.btn:active { transform: scale(0.97); }
.btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn--primary:disabled { opacity: 0.6; cursor: default; }
.btn--ghost { background: transparent; border-color: transparent; color: var(--text-mute); }
.btn--ghost:hover { background: var(--accent-soft); color: var(--text); }
.btn--sm { padding: 6px 10px; font-size: 13px; }
.btn--block { width: 100%; }
.link-btn {
    background: none; border: 0; padding: 4px; cursor: pointer;
    color: var(--accent); font-weight: 700; font-size: 14px;
}
.link-btn--sm { font-size: 12px; padding: 0; }
.icon-btn {
    width: 36px; height: 36px; border-radius: 50%;
    border: 1px solid var(--border); background: var(--surface);
    font-size: 22px; line-height: 1; cursor: pointer; color: var(--text-mute);
    display: grid; place-items: center; padding: 0 0 3px;
}
.icon-btn:hover { color: var(--text); border-color: var(--border-strong); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Demo banner ---------- */
.demo-banner {
    background: #FFF3C9; color: #6B5300;
    font-size: 13px; font-weight: 600; text-align: center;
    padding: 7px 16px;
}
@media (prefers-color-scheme: dark) {
    .demo-banner { background: #3A3215; color: #F1DC8F; }
}

/* ---------- Brand ---------- */
.brand { display: flex; align-items: center; gap: 10px; }
.brand img { display: block; }
.brand-name { font-weight: 800; letter-spacing: -0.01em; }
.brand--big .brand-name { font-size: 22px; }
.brand-sub { color: var(--text-mute); font-size: 13px; font-weight: 600; }

/* ---------- Auth ---------- */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card {
    width: 100%; max-width: 380px;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 20px; padding: 28px 24px; box-shadow: var(--shadow);
}
.auth-tabs {
    display: grid; grid-template-columns: 1fr 1fr; gap: 4px;
    background: var(--surface-2); border: 1px solid var(--border);
    border-radius: 12px; padding: 4px; margin: 24px 0 18px;
}
.auth-tabs button {
    border: 0; background: transparent; border-radius: 9px; padding: 8px;
    font-weight: 700; color: var(--text-mute); cursor: pointer;
}
.auth-tabs button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 13px; font-weight: 700; color: var(--text-mute); margin-bottom: 5px; }
.field input {
    width: 100%; padding: 11px 12px; border-radius: 10px;
    border: 1px solid var(--border-strong); background: var(--surface-2);
}
.field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.auth-error { color: var(--danger); font-size: 14px; font-weight: 600; margin: -4px 0 12px; }
#auth-forgot { display: block; margin: 12px auto 0; }

/* ---------- App shell ---------- */
.app { max-width: 1180px; margin: 0 auto; padding: 0 16px 48px; }
.topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 0; gap: 12px;
}
.topbar-right { display: flex; align-items: center; gap: 8px; min-width: 0; }
.who { color: var(--text-mute); font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.toolbar {
    display: flex; align-items: center; flex-wrap: wrap; gap: 8px 16px;
    margin: 6px 0 14px;
}
.page-title { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; margin: 0; flex: 1 1 auto; }
.week-nav { display: flex; align-items: center; gap: 10px; }
.week-label-wrap { text-align: center; min-width: 128px; }
.week-label { font-weight: 800; font-size: 16px; }

/* ---------- 1 week / 2 weeks ---------- */
.span-toggle {
    display: inline-grid; grid-template-columns: 1fr 1fr; gap: 3px;
    background: var(--surface-2); border: 1px solid var(--border);
    border-radius: 10px; padding: 3px;
}
.span-toggle button {
    border: 0; background: transparent; border-radius: 7px;
    padding: 6px 12px; font-weight: 700; font-size: 13px;
    color: var(--text-mute); cursor: pointer; white-space: nowrap;
}
.span-toggle button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.grids { display: grid; gap: 10px; }
.week-heading {
    display: flex; align-items: baseline; gap: 10px;
    margin: 10px 0 0; font-size: 15px; font-weight: 800;
}
.week-heading:first-child { margin-top: 0; }
.week-heading-rel { color: var(--accent); }
.week-heading-range { color: var(--text-mute); font-weight: 700; }

/* ---------- Progress ---------- */
.progress { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.progress-bar { flex: 1; height: 8px; border-radius: 99px; background: var(--border); overflow: hidden; }
.progress-fill {
    height: 100%; width: 0; border-radius: inherit; background: var(--done);
    transition: width 600ms var(--ease-sweep);
}
.progress-text { font-weight: 700; color: var(--text-mute); font-size: 14px; white-space: nowrap; }

/* ---------- Grid ---------- */
.grid-scroll {
    overflow-x: auto;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface);
    box-shadow: var(--shadow);
    -webkit-overflow-scrolling: touch;
}
.grid {
    --subject-w: 128px;
    display: grid;
    grid-template-columns: var(--subject-w) repeat(6, minmax(118px, 1fr));
    min-width: calc(var(--subject-w) + 6 * 118px);
}
.gh, .gs, .cell { border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.grid > :nth-child(7n) { border-right: 0; }
.grid > :nth-last-child(-n+7) { border-bottom: 0; }

.gh {
    padding: 10px 8px; text-align: center; background: var(--surface-2);
    position: sticky; top: 0;
}
.gh-day { font-weight: 800; font-size: 14px; }
.gh-date { font-size: 12px; color: var(--text-mute); font-weight: 600; }
.gh.is-today { background: var(--accent-soft); }
.gh.is-today .gh-day { color: var(--accent); }
.gh-corner { text-align: left; font-size: 12px; color: var(--text-mute); font-weight: 700; display: flex; align-items: end; }

/* Subject column stays pinned while the days scroll sideways on phones. */
.gh-corner, .gs {
    position: sticky; left: 0; z-index: 2;
    background: var(--surface-2);
}
.gh-corner { z-index: 3; }
.gs {
    display: flex; align-items: center; gap: 4px;
    padding: 8px 6px 8px 12px; min-height: 96px;
}
.gs-name {
    flex: 1; min-width: 0; font-weight: 800; font-size: 15px;
    border: 1px solid transparent; border-radius: 8px; padding: 4px 6px; margin-left: -6px;
    background: transparent; cursor: text;
    /* Same whole-words rule as cell text — fitWords() in app.js shrinks to fit. */
    overflow-wrap: normal; word-break: normal; hyphens: manual;
}
.gs-name.is-squeezed { overflow-wrap: anywhere; }
.gs-name:hover { border-color: var(--border); }
.gs-name:focus { outline: none; border-color: var(--accent); background: var(--surface); }
/* Tucked into the corner so it doesn't take width from the subject name. */
.gs-delete {
    position: absolute; right: 2px; bottom: 2px;
    border: 0; background: none; color: var(--text-dim); cursor: pointer;
    font-size: 16px; line-height: 1; padding: 4px 6px; border-radius: 6px;
    opacity: 0; transition: opacity 150ms;
}
.gs:hover .gs-delete, .gs-delete:focus-visible { opacity: 1; }
.gs-delete:hover { color: var(--danger); background: rgba(214, 69, 69, 0.08); }
@media (hover: none) { .gs-delete { opacity: 0.6; } }
.is-readonly .gs-name { cursor: default; }
.is-readonly .gs-name:hover { border-color: transparent; }

/* ---------- Cell ---------- */
.cell {
    position: relative; isolation: isolate;
    min-height: 96px; padding: 10px 12px;
    display: flex; align-items: center; justify-content: center; text-align: center;
    cursor: pointer; user-select: none; -webkit-user-select: none;
    overflow: hidden;
    transition: background 150ms;
}
.cell.is-today { background: var(--today); }
.cell:hover { background: var(--accent-soft); }
.cell.is-done:hover { background: transparent; }
.is-readonly .cell { cursor: default; }
.is-readonly .cell:hover { background: transparent; }
.is-readonly .cell.is-today:hover { background: var(--today); }

.cell-text {
    position: relative; z-index: 1;
    font-weight: 600; font-size: 14px; line-height: 1.3;
    /* Words stay whole: fitText() in app.js shrinks the font until the longest word
       fits. max-width + min-width:0 make an overflowing word measurable
       (scrollWidth > clientWidth). Only .is-squeezed (a word too long even at
       the minimum size) may break mid-word. */
    max-width: 100%; min-width: 0;
    overflow-wrap: normal; word-break: normal; hyphens: manual;
    transition: color 300ms, opacity 300ms;
}
.cell-text.is-squeezed { overflow-wrap: anywhere; }
.cell-empty-hint {
    color: var(--text-dim); font-size: 22px; font-weight: 600;
    opacity: 0; transition: opacity 150ms;
}
.cell:hover .cell-empty-hint, .cell:focus-visible .cell-empty-hint { opacity: 1; }
.is-readonly .cell-empty-hint { display: none; }

/* The green fill — sweeps left → right like HG's ring sweeps around. */
.cell-fill {
    position: absolute; inset: 0; z-index: 0;
    background: var(--done-bg);
    transform: scaleX(0); transform-origin: left center;
    transition: transform 260ms ease-in;
}
.cell.is-done .cell-fill { transform: scaleX(1); transition-timing-function: ease-out; }
.cell.is-done .cell-text { color: var(--done-text); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--done-text) 45%, transparent); }

/* Check mark — drawn with stroke-dashoffset. */
.cell-check {
    position: absolute; z-index: 1; top: 7px; right: 7px;
    width: 22px; height: 22px; border-radius: 50%;
    background: var(--done); color: #fff;
    display: grid; place-items: center;
    transform: scale(0); opacity: 0;
    transition: transform 200ms, opacity 200ms;
}
.cell-check svg { width: 14px; height: 14px; display: block; }
.cell-check path {
    fill: none; stroke: currentColor; stroke-width: 3.2;
    stroke-linecap: round; stroke-linejoin: round;
    stroke-dasharray: 24; stroke-dashoffset: 24;
}
.cell.is-done .cell-check { transform: scale(1); opacity: 1; }
.cell.is-done .cell-check path { stroke-dashoffset: 0; }

.cell-edit {
    position: absolute; z-index: 2; bottom: 4px; right: 4px;
    border: 0; background: none; cursor: pointer;
    color: var(--text-dim); font-size: 14px; padding: 4px 6px; border-radius: 6px;
    opacity: 0; transition: opacity 150ms;
}
.cell:hover .cell-edit, .cell-edit:focus-visible { opacity: 1; }
.cell-edit:hover { color: var(--text); background: rgba(127, 127, 127, 0.12); }
@media (hover: none) { .cell.has-text .cell-edit { opacity: 0.55; } }

.cell-input {
    position: relative; z-index: 2;
    width: 100%; min-height: 70px; resize: none;
    border: 0; background: transparent; outline: none;
    text-align: center; font-weight: 600; font-size: 14px; line-height: 1.3;
    padding: 0;
}
.cell.is-editing { background: var(--surface); box-shadow: inset 0 0 0 2px var(--accent); cursor: text; }

/* ---------- The celebration ----------
   1. fill sweeps across (HG ring-fill easing)
   2. a soft green glow pulses out from the cell
   3. the check badge springs in (HG star-pop overshoot) and draws its tick
   4. sparks burst from the badge (spawned in JS) */
.cell.celebrate .cell-fill { animation: aaFillSweep 640ms var(--ease-sweep) both; }
.cell.celebrate { animation: aaGlow 900ms ease-out 380ms both; }
.cell.celebrate .cell-check { animation: aaBadgePop 520ms var(--ease-spring) 420ms both; }
.cell.celebrate .cell-check path { animation: aaTickDraw 300ms ease-out 560ms both; }
.cell.celebrate .cell-text { animation: aaTextBump 520ms var(--ease-spring) 380ms both; }

@keyframes aaFillSweep {
    0%   { transform: scaleX(0); }
    100% { transform: scaleX(1); }
}
@keyframes aaGlow {
    0%   { box-shadow: inset 0 0 0 0 var(--done-glow); }
    35%  { box-shadow: inset 0 0 0 3px var(--done-glow); }
    100% { box-shadow: inset 0 0 0 0 transparent; }
}
@keyframes aaBadgePop {
    0%   { transform: scale(0) rotate(-30deg); opacity: 0; }
    45%  { transform: scale(1.45) rotate(8deg); opacity: 1; }
    70%  { transform: scale(0.92) rotate(-4deg); }
    100% { transform: scale(1) rotate(0); opacity: 1; }
}
@keyframes aaTickDraw {
    from { stroke-dashoffset: 24; }
    to   { stroke-dashoffset: 0; }
}
@keyframes aaTextBump {
    0%   { transform: scale(1); }
    40%  { transform: scale(1.06); }
    100% { transform: scale(1); }
}

.spark {
    position: absolute; z-index: 3; pointer-events: none;
    width: 6px; height: 6px; border-radius: 50%;
    background: var(--done);
    animation: aaSpark 620ms cubic-bezier(0.2, 0.7, 0.3, 1) forwards;
}
.spark:nth-child(3n) { background: #F4C141; width: 5px; height: 5px; }
.spark:nth-child(3n+1) { background: var(--accent); width: 4px; height: 4px; }
@keyframes aaSpark {
    0%   { transform: translate(-50%, -50%) rotate(var(--a)) translateX(0) scale(1); opacity: 1; }
    100% { transform: translate(-50%, -50%) rotate(var(--a)) translateX(var(--d)) scale(0.2); opacity: 0; }
}

/* No transitions on the first paint of a grid (prevents every done cell sweeping in). */
.grid.no-anim *, .grid.no-anim *::before { transition: none !important; }

@media (prefers-reduced-motion: reduce) {
    .cell.celebrate, .cell.celebrate *, .spark { animation: none !important; }
    .cell-fill, .cell-check, .progress-fill { transition: none !important; }
}

/* ---------- Add subject ---------- */
.add-subject {
    display: flex; align-items: center; gap: 8px;
    margin-top: 10px; width: 100%;
    border: 1.5px dashed var(--border-strong); border-radius: var(--radius);
    background: transparent; padding: 14px 16px; cursor: pointer;
    color: var(--text-mute); font-weight: 700;
    transition: border-color 150ms, color 150ms, background 150ms;
}
.add-subject:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.add-subject-plus { font-size: 22px; line-height: 1; }
.readonly-note { color: var(--text-mute); font-size: 13px; text-align: center; margin-top: 12px; }

/* ---------- Students (admin) ---------- */
.students-list { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.student-card {
    text-align: left; cursor: pointer;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 16px; box-shadow: var(--shadow);
    display: grid; gap: 10px;
    transition: border-color 150ms, transform 120ms;
}
.student-card:hover { border-color: var(--accent); }
.student-card:active { transform: scale(0.99); }
.student-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.student-name { font-weight: 800; font-size: 17px; }
.student-email { color: var(--text-mute); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.student-count { font-weight: 800; color: var(--done-text); white-space: nowrap; }
.student-count.is-zero { color: var(--text-mute); }
.empty-state { color: var(--text-mute); text-align: center; padding: 48px 16px; grid-column: 1 / -1; }

/* ---------- Toast ---------- */
.toast {
    position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
    transform: translate(-50%, 20px) scale(0.96); opacity: 0;
    background: var(--text); color: var(--bg);
    padding: 12px 20px; border-radius: 99px; font-weight: 800;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    pointer-events: none; z-index: 50; white-space: nowrap; max-width: calc(100vw - 32px);
    overflow: hidden; text-overflow: ellipsis;
    transition: transform 380ms var(--ease-spring), opacity 200ms;
}
.toast.show { transform: translate(-50%, 0) scale(1); opacity: 1; }
.toast.is-big { background: var(--done); color: #fff; font-size: 17px; padding: 14px 24px; }

/* ---------- Phone ---------- */
@media (max-width: 600px) {
    .app { padding: 0 12px 40px; }
    .page-title { font-size: 22px; width: 100%; }
    .toolbar { justify-content: space-between; }
    .week-nav { width: 100%; justify-content: space-between; }
    .grid { --subject-w: 96px; grid-template-columns: var(--subject-w) repeat(6, 112px);
        /* The grid box must be as wide as its columns, or the sticky subject
           column runs out of containing block and scrolls away. */
        min-width: 0; width: max-content; }
    .gs { padding-left: 10px; min-height: 88px; }
    .gs-name { font-size: 14px; }
    .cell { min-height: 88px; padding: 8px 10px; }
    .brand .brand-name { font-size: 15px; }
}
