:root {
  color-scheme: light;
  --orange: #ea580c;
  --orange-dark: #9a3412;
  --cream: #fff7ed;
  --ink: #1f2937;
  --muted: #64748b;
  --line: #e2e8f0;
  --surface: #fff;
  --danger: #b91c1c;
  --success: #047857;
  font-family: "Hiragino Maru Gothic ProN", "Hiragino Sans", "Yu Gothic", Meiryo, sans-serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--cream); }
body { margin: 0; min-height: 100%; color: var(--ink); background: linear-gradient(145deg, #fff7ed, #fffbeb 45%, #eff6ff); }
#app { width: 100%; min-height: 100dvh; }
button, input, textarea { font: inherit; }
button, .button { min-height: 44px; touch-action: manipulation; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--orange-dark); outline-offset: 3px; }
rt { color: #5f6368; font-weight: 500; }
button rt, a rt, [class*="bg-"] rt, [class*="text-white"] rt { color: inherit; }
.skip-link { position: fixed; top: -80px; left: 16px; z-index: 100; padding: 12px; background: #fff; color: #000; }
.skip-link:focus { top: 12px; }

.center-screen { width: 100%; min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; padding: 24px; text-align: center; }
.login-card { width: min(100%, 500px); margin-inline: auto; padding: clamp(24px, 6vw, 48px); border-radius: 30px; background: rgba(255,255,255,.96); box-shadow: 0 24px 70px rgba(15,23,42,.12); }
.app-logo { width: 88px; height: 88px; display: block; margin: 0 auto 20px; border-radius: 24px; object-fit: cover; box-shadow: 0 12px 30px rgba(234,88,12,.28); }
h1, h2, h3 { line-height: 1.35; }
h1 { margin: 0 0 12px; font-size: clamp(23px, 5vw, 34px); }
h2 { font-size: clamp(21px, 4vw, 28px); }
h3 { font-size: 18px; }
p { line-height: 1.75; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.loader { width: 48px; height: 48px; margin: auto; border: 5px solid #fed7aa; border-top-color: var(--orange); border-radius: 50%; animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.primary, .secondary, .quiet, .danger { border: 0; border-radius: 14px; padding: 11px 18px; font-weight: 800; }
.primary { background: linear-gradient(90deg, #ea580c, #f59e0b); color: #fff; box-shadow: 0 8px 20px rgba(234,88,12,.22); }
.secondary { background: #fff; color: var(--orange-dark); border: 2px solid #fdba74; }
.quiet { background: #f1f5f9; color: #334155; }
.danger { background: #fee2e2; color: var(--danger); }
.wide { width: 100%; }
.button-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.button-row > button { flex: 1 1 150px; }

.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px max(16px, env(safe-area-inset-left)); background: rgba(255,255,255,.94); border-bottom: 1px solid var(--line); backdrop-filter: blur(12px); }
.brand { display: flex; gap: 10px; align-items: center; font-weight: 900; }
.brand-icon { width: 34px; height: 34px; flex: 0 0 auto; border-radius: 10px; object-fit: cover; }
.account { min-height: 0; padding: 4px 8px; border: 0; border-radius: 10px; background: transparent; text-align: right; font-size: 12px; color: var(--muted); }
.account:hover { background: #f8fafc; }
.account strong { display: block; color: var(--ink); font-size: 14px; }
.account small { display: block; margin-top: 2px; color: var(--orange-dark); font-size: 9px; font-weight: 800; }
.page { width: min(1440px, calc(100% - 32px)); margin: 0 auto; padding: 24px 0 calc(60px + env(safe-area-inset-bottom)); }
.page-heading { display: flex; align-items: end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.page-heading h1 { margin: 0; }
.role-home { width: min(100%, 900px); min-height: calc(100dvh - 130px); display: grid; align-content: center; gap: 22px; margin-inline: auto; padding-block: clamp(24px, 7vh, 72px); }
.role-home-intro { max-width: 680px; margin-inline: auto; text-align: center; }
.role-home-intro p { margin: 0; color: var(--muted); }
.role-choice-grid { width: 100%; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.role-choice-grid .item-card { min-height: 210px; display: grid; place-content: center; text-align: center; }
.role-choice-grid .item-card h2 { margin: 0 0 8px; }
.role-choice-grid .item-card p { margin: 0; }

.panel, .item-card, .journal-card { background: rgba(255,255,255,.96); border: 1px solid rgba(226,232,240,.9); border-radius: 22px; box-shadow: 0 10px 32px rgba(15,23,42,.07); }
.panel { padding: clamp(20px, 4vw, 32px); margin-bottom: 20px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 270px), 1fr)); gap: 16px; }
.item-card { padding: 20px; text-align: left; }
button.item-card { width: 100%; color: inherit; }
.item-card:hover { border-color: #fb923c; transform: translateY(-1px); }
.badge { display: inline-block; padding: 4px 9px; border-radius: 999px; background: #ffedd5; color: var(--orange-dark); font-size: 12px; font-weight: 900; letter-spacing: .04em; }
.empty { padding: 34px 20px; text-align: center; border: 2px dashed #cbd5e1; border-radius: 18px; color: var(--muted); }

label { display: block; margin: 0 0 16px; font-weight: 800; }
label span { display: block; margin-bottom: 7px; }
input, textarea { width: 100%; padding: 13px 14px; border: 2px solid #cbd5e1; border-radius: 12px; background: #fff; color: var(--ink); }
select { width: 100%; min-height: 44px; padding: 10px 12px; border: 2px solid #cbd5e1; border-radius: 12px; background: #fff; color: var(--ink); }
textarea { min-height: 170px; resize: vertical; line-height: 1.75; }
input:focus, textarea:focus { border-color: #f97316; outline: 3px solid #ffedd5; }
.field-note { margin: -9px 0 16px; color: var(--muted); font-size: 12px; }
.emotion-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 0 0 18px; }
.emotion-row label { margin: 0; }
.emotion-row input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.emotion-row span { display: grid; place-items: center; min-width: 52px; min-height: 48px; margin: 0; border: 2px solid #e2e8f0; border-radius: 14px; background: #fff; font-size: 25px; }
.emotion-row input:checked + span { border-color: #f97316; background: #fff7ed; }

.invite-layout { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 24px; align-items: start; }
.class-code { margin: 8px 0 14px; font-size: clamp(28px, 7vw, 48px); font-weight: 950; letter-spacing: .13em; color: var(--orange-dark); overflow-wrap: anywhere; }
.url-box { padding: 12px; border-radius: 12px; background: #f8fafc; border: 1px solid var(--line); font: 12px/1.6 ui-monospace, SFMono-Regular, Consolas, monospace; overflow-wrap: anywhere; }
.qr-box { width: 220px; max-width: 100%; padding: 14px; background: #fff; border: 1px solid var(--line); border-radius: 18px; }
.qr-box svg { display: block; width: 100%; height: auto; }
.qr-actions { display: grid; justify-items: center; gap: 10px; }
.class-switcher { display: grid; grid-template-columns: minmax(180px, 260px) auto auto; align-items: end; gap: 8px; }
.class-switcher label { grid-column: 1; margin: 0; color: var(--muted); font-size: 11px; }
.class-switcher select { grid-column: 1; }
.class-switcher #refresh-class { grid-column: 2; grid-row: 2; }
.class-switcher #classes { grid-column: 3; grid-row: 2; }
.sync-status { display: block; color: var(--muted); font-size: 11px; }
.permission-page { min-height: calc(100dvh - 130px); display: grid; place-items: center; }
.permission-card { width: min(100%, 620px); margin: 0 auto; text-align: center; }
.permission-icon { width: 74px; height: 74px; display: grid; place-items: center; margin: 0 auto 14px; border-radius: 24px; background: #eff6ff; font-size: 34px; }
.permission-points { display: grid; gap: 10px; margin: 22px 0; text-align: left; }
.permission-points p { margin: 0; padding: 12px 14px; border-radius: 13px; background: #f8fafc; }
.permission-points span { color: var(--muted); font-size: 13px; }
.permission-card .quiet { margin-top: 9px; }

.journal-list { display: grid; gap: 14px; }
.journal-card { padding: 20px; }
.journal-meta { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; color: var(--muted); font-size: 12px; }
.journal-body { white-space: pre-wrap; line-height: 1.9; overflow-wrap: anywhere; }
.journal-image { display: block; max-width: 100%; max-height: 520px; margin-top: 14px; border-radius: 14px; object-fit: contain; background: #f1f5f9; }
.notice, .error { padding: 14px 16px; margin-bottom: 16px; border-radius: 13px; line-height: 1.7; }
.notice { background: #ecfdf5; color: #065f46; }
.error { background: #fef2f2; color: #991b1b; white-space: pre-wrap; }

.tabs { display: flex; gap: 8px; margin: 0 0 22px; overflow-x: auto; padding-bottom: 3px; }
.teacher-tabs { position: sticky; top: 59px; z-index: 15; padding: 8px; border: 1px solid var(--line); border-radius: 17px; background: rgba(255,255,255,.94); box-shadow: 0 8px 22px rgba(15,23,42,.06); backdrop-filter: blur(12px); }
.tab { flex: 1 0 auto; border: 1px solid var(--line); border-radius: 14px; padding: 11px 16px; background: #fff; color: #475569; font-weight: 900; }
.tab.active { background: #1e293b; color: #fff; border-color: #1e293b; }
.metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 20px; }
.teacher-overview { display: grid; grid-template-columns: minmax(190px, 1.2fr) repeat(3, minmax(130px, 1fr)); gap: 12px; margin-bottom: 16px; }
.metric { display: grid; gap: 4px; padding: 20px; border: 1px solid var(--line); border-radius: 18px; background: #fff; text-align: center; }
.metric strong { color: var(--orange-dark); font-size: clamp(24px, 5vw, 38px); }
.metric span { color: var(--muted); font-size: 13px; font-weight: 800; }
.teacher-overview .metric { min-height: 118px; align-content: center; padding: 14px; }
.teacher-overview .attention-metric strong { color: #b45309; }
.submission-donut-card { grid-template-columns: auto 1fr; align-items: center; gap: 12px; text-align: left; }
.submission-donut { width: 86px; aspect-ratio: 1; display: grid; place-items: center; margin: auto; border-radius: 50%; background: conic-gradient(var(--orange) var(--rate), #ffedd5 0); }
.submission-donut::before { content: ''; grid-area: 1 / 1; width: 60px; aspect-ratio: 1; border-radius: 50%; background: #fff; }
.submission-donut > span { z-index: 1; grid-area: 1 / 1; display: grid; }
.submission-donut strong { font-size: 24px; }
.submission-donut small { color: var(--muted); font-size: 10px; }
.filter-row { display: flex; gap: 8px; margin: -5px 0 15px; overflow-x: auto; }
.filter-chip { min-height: 38px; padding: 7px 15px; border: 1px solid var(--line); border-radius: 999px; background: #fff; color: #475569; font-weight: 800; }
.filter-chip.active { border-color: #fb923c; background: #ffedd5; color: var(--orange-dark); }
.teacher-dashboard-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(290px, 340px); gap: 18px; align-items: start; }
.teacher-submissions { min-width: 0; }
.teacher-list-heading, .compact-section-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.teacher-list-heading { margin: 4px 0 12px; }
.teacher-list-heading h2, .compact-section-heading h2 { margin: 0; }
.teacher-list-controls { display: grid; grid-template-columns: minmax(220px, 360px) minmax(0, 1fr); align-items: center; gap: 12px; margin-bottom: 12px; }
.teacher-list-controls .filter-row { margin: 0; }
.teacher-sidebar { position: sticky; top: 130px; max-height: calc(100dvh - 145px); overflow-y: auto; scrollbar-gutter: stable; }
.teacher-sidebar .panel { padding: 20px; border-radius: 18px; }
.teacher-theme-panel label { margin-bottom: 11px; }
.teacher-theme-panel details { margin-block: 10px; }
.today-status-panel h3 { margin: 18px 0 8px; font-size: 14px; }
.student-status-list { display: flex; flex-wrap: wrap; gap: 7px; }
.student-status-list span { padding: 6px 9px; border-radius: 999px; font-size: 12px; font-weight: 800; }
.student-status-list.missing span { background: #fff7ed; color: #9a3412; border: 1px solid #fdba74; }
.student-status-list.submitted span { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.teacher-journal-list { grid-template-columns: repeat(auto-fit, minmax(min(100%, 330px), 1fr)); align-items: stretch; }
.teacher-journal-card { padding: 0; overflow: hidden; }
.teacher-journal-card.needs-reply { border-color: #fdba74; }
.teacher-journal-card.is-returned { box-shadow: 0 6px 18px rgba(15,23,42,.04); }
.journal-main { width: 100%; padding: 20px; border: 0; background: transparent; color: inherit; text-align: left; }
.journal-main:hover { background: #fffaf5; }
.quick-feedback { display: flex; align-items: center; gap: 7px; min-height: 52px; padding: 8px 14px; border-top: 1px solid var(--line); background: #f8fafc; }
.quick-feedback .quiet { min-height: 34px; padding: 6px 11px; margin-left: auto; font-size: 12px; }
.quick-stamp { width: 38px; min-height: 36px; padding: 2px; border: 1px solid var(--line); border-radius: 10px; background: #fff; font-size: 19px; }
.quick-stamp:hover { border-color: #fb923c; background: #fff7ed; }
.batch-bar { margin: 0 0 15px; padding: 11px 14px; border: 1px solid #fed7aa; border-radius: 15px; background: #fffaf5; }
.batch-bar summary { color: var(--orange-dark); }
.batch-bar p { margin: 7px 0 10px; }
.selectable-journal { min-height: 240px; padding: 16px; border: 2px dashed #fdba74; border-radius: 12px; background: #fffef8; user-select: text; }
.highlight-add { margin-top: 12px; }
.highlight-editor { margin: 18px 0; }
.highlight-row { margin-bottom: 12px; padding: 12px; border: 1px solid #fde68a; border-radius: 13px; background: #fffbeb; }
.highlight-row textarea { min-height: 82px; }
.highlight-quote { margin-bottom: 10px; color: #92400e; font-weight: 900; line-height: 1.6; }
.highlight-actions { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.teacher-highlight { position: relative; padding: 1px 2px; border-radius: 4px; background: #fef08a; color: inherit; }
.teacher-highlight span { display: inline-block; margin-left: 2px; font-size: .8em; }
.highlight-notes { margin-top: 18px; padding: 15px; border-radius: 14px; background: #f0fdf4; }
.highlight-notes h3 { margin-top: 0; }
.highlight-notes > div { padding: 9px 0; border-top: 1px solid #bbf7d0; }
.highlight-notes p { margin: 4px 0 0; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 230px), 1fr)); gap: 12px; }
details { margin: 14px 0; padding: 12px; border: 1px solid var(--line); border-radius: 13px; }
summary { cursor: pointer; font-weight: 900; }
.compact-input { width: min(100%, 360px); }
.journal-card[type="button"] { width: 100%; color: inherit; text-align: left; }
.clamp { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.success-badge { background: #d1fae5; color: #065f46; }
.detail-grid { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(300px, .7fr); gap: 18px; align-items: start; }
.feedback-box { margin-top: 15px; padding: 14px; border-left: 5px solid #fb923c; border-radius: 10px; background: #fff7ed; }
.feedback-box p { margin: 6px 0 0; color: #7c2d12; }
.theme-banner { margin: 0 0 18px; padding: 16px; border-radius: 16px; background: linear-gradient(135deg, #ffedd5, #fef3c7); color: #7c2d12; font-size: 20px; font-weight: 900; }
.support-row { display: flex; gap: 7px; flex-wrap: wrap; margin: -4px 0 14px; }
.support-row button { flex: 0 1 auto; }
.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; }
.eyebrow { display: block; margin-bottom: 5px; color: var(--orange); font-size: 11px; font-weight: 950; letter-spacing: .14em; }
.section-heading, .notebook-top, .calendar-heading, .journal-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.section-heading { margin: 36px 0 14px; }
.section-heading h2, .notebook-top h2 { margin: 0; }
.student-workspace { display: grid; grid-template-areas: "calendar notebook tools"; grid-template-columns: 220px minmax(0, 1fr) 260px; gap: 16px; align-items: start; }
.student-workspace > .panel { min-width: 0; margin: 0; padding: 20px; }
.student-calendar { grid-area: calendar; }
.notebook { grid-area: notebook; position: relative; overflow: hidden; border-top: 7px solid #f97316; }
.writing-tools { grid-area: tools; }
.notebook form { position: relative; }
.notebook-controls { display: grid; justify-items: end; gap: 7px; }
.notebook-date { color: var(--muted); font-size: 12px; font-weight: 800; }
.focus-button { min-height: 36px; padding: 6px 10px; border: 1px solid #fdba74; border-radius: 999px; background: #fff7ed; color: var(--orange-dark); font-size: 12px; font-weight: 900; }
.focus-button[aria-pressed="true"] { border-color: #1e293b; background: #1e293b; color: #fff; }
.notebook .theme-banner { display: grid; gap: 6px; margin-top: 18px; font-size: 13px; }
.notebook .theme-banner strong { font-size: 18px; }
.lined-paper, .lined-reading { background-color: #fffef8; background-image: repeating-linear-gradient(to bottom, transparent 0, transparent 34px, #dbeafe 35px, transparent 36px); background-attachment: local; line-height: 36px; }
.lined-paper { min-height: clamp(360px, 52dvh, 680px); padding: 5px 15px; border-color: #fed7aa; border-radius: 8px; font-size: 17px; }
.lined-reading { min-height: 180px; padding: 4px 12px; }
.notebook-options { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(210px, .7fr); gap: 14px; align-items: start; }
.emotion-fieldset { min-width: 0; margin: 0; padding: 0; border: 0; }
.emotion-fieldset legend { margin-bottom: 8px; }
.labeled-emotions { display: grid; grid-template-columns: repeat(4, 1fr); }
.labeled-emotions span { min-width: 0; padding: 6px 3px; }
.labeled-emotions b, .labeled-emotions small { display: block; }
.labeled-emotions small { margin-top: 2px; font-size: 10px; color: var(--muted); }
.attachment { background: #f8fafc; }
.notebook-submit { display: flex; align-items: center; justify-content: flex-end; gap: 16px; margin-top: 8px; }
.writing-count { flex: 0 0 auto; color: var(--muted); font-size: 12px; font-weight: 800; }
.submit-journal { min-width: min(100%, 320px); min-height: 56px; font-size: 17px; }
.auxiliary-details { margin: 0; padding: 0; border: 0; }
.auxiliary-summary { list-style-position: outside; color: var(--ink); font-size: 16px; font-weight: 950; }
.auxiliary-content { margin-top: 14px; }
.writing-tools .auxiliary-content > p { margin-top: 0; }
.writing-tools details { padding: 10px 0; border-width: 0 0 1px; border-radius: 0; }
.writing-tools > .auxiliary-details { padding: 0; border: 0; }
.template-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin-top: 10px; }
.template-button, .hint-button { border: 1px solid #fed7aa; border-radius: 10px; background: #fffaf4; color: #7c2d12; font-size: 12px; font-weight: 800; }
.template-button { padding: 8px 5px; }
.hint-list { display: grid; gap: 7px; margin-top: 10px; }
.hint-button { min-height: 0; padding: 9px; text-align: left; line-height: 1.5; }
.icon-button { width: 38px; min-height: 38px; padding: 0; border: 1px solid var(--line); border-radius: 50%; background: #fff; font-size: 26px; line-height: 1; }
.calendar-week, .calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.calendar-week { margin-top: 15px; color: var(--muted); text-align: center; font-size: 10px; }
.calendar-cell { min-width: 0; min-height: 34px; display: grid; place-content: center; gap: 0; padding: 2px; border: 0; border-radius: 8px; background: transparent; color: var(--ink); font-size: 11px; text-align: center; }
button.calendar-cell { cursor: pointer; }
.calendar-cell small { color: var(--orange); font-size: 8px; }
.calendar-cell.has-journal { background: #ffedd5; font-weight: 900; }
.calendar-cell.has-feedback { background: #d1fae5; }
.calendar-key { display: flex; justify-content: center; gap: 10px; color: var(--muted); font-size: 9px; }
.feedback-alert { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; padding: 15px 18px; border: 2px solid #fbbf24; border-radius: 16px; background: linear-gradient(90deg, #fffbeb, #fff7ed); color: #92400e; text-align: left; box-shadow: 0 8px 24px rgba(245,158,11,.12); }
.student-journal-card { width: 100%; color: inherit; text-align: left; }
.student-history .journal-list { grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); }
.student-journal-card.unread { border: 2px solid #f59e0b; box-shadow: 0 10px 30px rgba(245,158,11,.16); }
.journal-footer { margin-top: 14px; color: var(--muted); font-size: 12px; }
.journal-dialog { width: min(720px, calc(100% - 24px)); max-height: calc(100dvh - 30px); padding: 0; border: 0; border-radius: 24px; color: var(--ink); box-shadow: 0 30px 90px rgba(15,23,42,.3); }
.journal-dialog::backdrop { background: rgba(15,23,42,.62); backdrop-filter: blur(3px); }
.journal-dialog article { padding: clamp(22px, 5vw, 38px); }
.dialog-close { float: right; width: 42px; min-height: 42px; border: 0; border-radius: 50%; background: #f1f5f9; color: #475569; font-size: 25px; }
.dialog-note { margin-top: 18px; text-align: center; }
.feedback-box.large { padding: 18px; font-size: 16px; }
.confetti-layer { position: fixed; inset: 0; z-index: 200; overflow: hidden; pointer-events: none; }
.confetti-layer i { position: absolute; top: -20px; left: var(--x); width: 10px; height: 18px; border-radius: 2px; background: var(--color); animation: confetti-fall 1.45s var(--delay) cubic-bezier(.22,.7,.4,1) forwards; }
@keyframes confetti-fall { to { transform: translate3d(calc((var(--x) - 50%) * -.45), 105dvh, 0) rotate(var(--spin)); opacity: .1; } }
.check-label { display: flex; align-items: center; gap: 10px; }
.check-label input { width: 22px; height: 22px; }
.check-label span { margin: 0; }
.inline-form { display: grid; grid-template-columns: 1fr 1.4fr auto; gap: 8px; margin-top: 16px; }
.member-table { display: grid; gap: 8px; }
.member-row { display: grid; grid-template-columns: minmax(180px, 1fr) auto minmax(150px, auto); align-items: center; gap: 12px; padding: 12px; border: 1px solid var(--line); border-radius: 13px; }
.member-row div:first-child { display: grid; }
.member-row div:first-child span { color: var(--muted); font-size: 12px; }
.button-row.compact { flex-wrap: nowrap; }
.button-row.compact button { flex: 0 1 auto; min-height: 38px; padding: 7px 10px; font-size: 12px; }
.heatmap { overflow-x: auto; }
.heatmap-row { display: grid; grid-template-columns: 130px repeat(14, minmax(38px, 1fr)); min-width: 720px; gap: 4px; align-items: center; padding: 4px 0; }
.heatmap-row > span { display: grid; place-items: center; min-height: 34px; border-radius: 8px; background: #f8fafc; font-size: 18px; }
.heatmap-head span { font-size: 11px; font-weight: 800; background: transparent; }
.vitals-grid { display: grid; grid-template-columns: minmax(260px, .42fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.vitals-grid > .panel { margin: 0; }
.vitals-alerts { position: sticky; top: 130px; }
.teacher-settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; align-items: start; }
.teacher-settings-grid > .panel { margin: 0; }
.teacher-settings-grid .wide-setting { grid-column: 1 / -1; }
blockquote { margin: 0 0 16px; padding: 14px 18px; border-left: 5px solid #f59e0b; background: #fffbeb; white-space: pre-wrap; }

#toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); z-index: 100; transform: translate(-50%, 30px); max-width: calc(100% - 32px); padding: 12px 18px; border-radius: 12px; background: #1e293b; color: #fff; opacity: 0; pointer-events: none; transition: .2s ease; font-weight: 800; }
#toast.visible { opacity: 1; transform: translate(-50%, 0); }
.pwa-controls { position: fixed; right: max(14px, env(safe-area-inset-right)); bottom: calc(14px + env(safe-area-inset-bottom)); z-index: 80; }
.pwa-action, .pwa-later { min-height: 42px; padding: 9px 14px; border-radius: 999px; font-weight: 900; }
.pwa-action { border: 2px solid #34d399; background: #fff; color: #065f46; box-shadow: 0 8px 24px rgba(15,23,42,.14); }
.pwa-update { display: flex; align-items: center; gap: 9px; max-width: calc(100vw - 28px); padding: 9px 10px 9px 15px; border-radius: 18px; background: #1e293b; color: #fff; box-shadow: 0 12px 34px rgba(15,23,42,.28); font-size: 12px; font-weight: 800; }
.pwa-update[hidden], .pwa-action[hidden] { display: none; }
.pwa-later { min-height: 38px; padding-inline: 8px; border: 0; background: transparent; color: #cbd5e1; font-size: 11px; }

html.writing-focus .topbar,
html.writing-focus .student-page-heading,
html.writing-focus .feedback-alert,
html.writing-focus .student-calendar,
html.writing-focus .writing-tools,
html.writing-focus .student-history,
html.writing-focus .past-self-panel,
html.writing-focus .pwa-controls { display: none; }
html.writing-focus .page { width: min(1180px, calc(100% - 24px)); padding-top: 12px; }
html.writing-focus .student-workspace { display: grid; grid-template-areas: "notebook"; grid-template-columns: minmax(0, 1fr); }
html.writing-focus .notebook { width: 100%; }
html.writing-focus .lined-paper { min-height: clamp(360px, calc(100dvh - 300px), 760px); }

@media (min-width: 681px) and (max-width: 1050px) and (min-height: 521px) {
  .student-workspace { grid-template-areas: "notebook tools" "notebook calendar"; grid-template-columns: minmax(0, 1fr) minmax(230px, .48fr); }
  .notebook-options { grid-template-columns: 1fr; }
}

@media (max-width: 1100px) {
  .teacher-dashboard-grid { grid-template-columns: minmax(0, 1fr); }
  .teacher-sidebar { position: static; max-height: none; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; overflow: visible; }
  .teacher-sidebar > .panel { margin: 0; }
  .vitals-grid { grid-template-columns: minmax(0, 1fr); }
  .vitals-alerts { position: static; }
}

@media (max-width: 860px) {
  .teacher-overview { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .teacher-list-controls { grid-template-columns: minmax(0, 1fr); }
  .teacher-list-controls .compact-input { width: 100%; }
}

@media (max-width: 680px), (max-height: 520px) and (orientation: landscape) {
  .topbar { padding-block: 8px; }
  .brand { gap: 8px; font-size: 14px; }
  .brand-icon { width: 30px; height: 30px; border-radius: 8px; }
  .page { width: calc(100% - 20px); padding-top: 14px; }
  .page-heading { margin-bottom: 12px; }
  .student-page-heading { align-items: center; flex-wrap: nowrap; }
  .student-page-heading h1 { max-width: 62vw; overflow: hidden; font-size: 22px; text-overflow: ellipsis; white-space: nowrap; }
  .student-page-heading .quiet { min-height: 40px; padding: 8px 10px; font-size: 12px; }
  .role-home { min-height: auto; padding-block: 28px; }
  .role-choice-grid { grid-template-columns: 1fr; }
  .role-choice-grid .item-card { min-height: 150px; }
  .invite-layout { grid-template-columns: 1fr; }
  .qr-box { width: min(260px, 100%); margin: auto; }
  .account span { display: none; }
  .account small { display: none; }
  .metrics { grid-template-columns: 1fr; }
  .teacher-tabs { top: 47px; gap: 5px; margin-bottom: 14px; padding: 6px; border-radius: 14px; }
  .teacher-tabs .tab { min-height: 40px; padding: 8px 10px; font-size: 12px; }
  .teacher-overview { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .teacher-overview .metric { min-height: 92px; padding: 10px; }
  .teacher-overview .submission-donut-card { grid-column: 1 / -1; min-height: 104px; }
  .teacher-sidebar { display: grid; grid-template-columns: minmax(0, 1fr); }
  .teacher-list-heading { margin-top: 2px; }
  .teacher-list-controls { gap: 8px; }
  .teacher-journal-list { grid-template-columns: minmax(0, 1fr); }
  .teacher-settings-grid { grid-template-columns: minmax(0, 1fr); }
  .teacher-settings-grid .wide-setting { grid-column: auto; }
  .detail-grid { grid-template-columns: 1fr; }
  .inline-form { grid-template-columns: 1fr; }
  .member-row { grid-template-columns: 1fr auto; }
  .member-row .button-row { grid-column: 1 / -1; }
  .student-workspace { display: grid; grid-template-areas: "notebook" "tools" "calendar"; grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .student-workspace > * { width: 100%; }
  .student-workspace > .panel { padding: 14px; border-radius: 17px; }
  .student-calendar, .writing-tools { padding-block: 13px !important; }
  .auxiliary-summary { padding: 2px 4px; font-size: 15px; }
  .auxiliary-content { margin-top: 12px; }
  .notebook-top { align-items: flex-start; }
  .notebook-top h2 { font-size: 21px; }
  .notebook-controls { min-width: 96px; }
  .focus-button { min-height: 34px; padding: 5px 8px; }
  .notebook .theme-banner { gap: 3px; margin: 12px 0; padding: 11px 13px; }
  .notebook .theme-banner strong { font-size: 16px; }
  .lined-paper { min-height: max(320px, 45dvh); padding-inline: 11px; font-size: 16px; }
  .notebook-options { grid-template-columns: 1fr; gap: 4px; }
  .attachment { margin-block: 8px; }
  .notebook-submit { position: sticky; bottom: calc(6px + env(safe-area-inset-bottom)); z-index: 5; display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 10px; margin: 8px -4px -4px; padding: 8px; border: 1px solid #fed7aa; border-radius: 14px; background: rgba(255,255,255,.96); box-shadow: 0 8px 24px rgba(15,23,42,.12); }
  .submit-journal { width: 100%; min-width: 0; min-height: 52px; }
  .section-heading { margin-top: 28px; }
  .feedback-alert { align-items: flex-start; }
  .feedback-alert span:last-child { display: none; }
  .teacher-class-heading { align-items: stretch; }
  .teacher-class-title { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 4px 8px; }
  .teacher-class-title h1 { margin: 0; overflow: hidden; font-size: 22px; text-overflow: ellipsis; white-space: nowrap; }
  .teacher-class-title .sync-status { grid-column: 1 / -1; }
  .class-switcher { width: 100%; grid-template-columns: 1fr auto; }
  .class-switcher #refresh-class { grid-column: 1 / -1; grid-row: 3; }
  .class-switcher #classes { grid-column: 2; grid-row: 2; }
  .pwa-controls { right: 10px; bottom: calc(10px + env(safe-area-inset-bottom)); }
  .pwa-update > span { display: none; }
}

@media (max-width: 420px) {
  .account { max-width: 74px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .account strong { overflow: hidden; text-overflow: ellipsis; }
  .notebook-date { font-size: 11px; }
  .labeled-emotions small { font-size: 9px; }
}

@media (max-height: 520px) and (orientation: landscape) {
  .page { padding-top: 10px; }
  .student-page-heading { margin-bottom: 8px; }
  .lined-paper { min-height: max(230px, 52dvh); }
  .student-history .journal-list { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
}

@media (min-width: 1500px) {
  .student-workspace { grid-template-columns: 230px minmax(0, 1fr) 280px; gap: 20px; }
  .student-workspace > .panel { padding: 24px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
@media (forced-colors: active) {
  button, input, textarea, .panel, .item-card, .journal-card { border: 2px solid ButtonText; }
}
