.app { max-width: 1240px; margin: 0 auto; padding: 14px 24px 40px; }
.top { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; flex-wrap: wrap; }
.spacer { flex: 1; }

.layout { display: grid; grid-template-columns: 360px minmax(0, 1fr); gap: 24px; align-items: start; }
.side { display: flex; flex-direction: column; gap: 12px; position: sticky; top: 12px; }
@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .side { position: static; }
}
@media (max-width: 520px) {
  .app { padding: 16px 16px 40px; }
  .hide-sm { display: none; }
}

/* Connect card */
.qr-wrap { display: flex; justify-content: center; margin: 16px 0 12px; }
.qr { width: 220px; height: 220px; padding: 10px; background: #fff; border-radius: 16px; border: 1px solid var(--border); }
.qr svg { display: block; width: 100%; height: 100%; }
.steps { margin: 0 0 14px; padding-left: 20px; font-size: 14px; }
.steps li { margin: 3px 0; }
.tip-line { margin: -4px 0 14px; padding: 10px 12px; background: var(--accent-soft); border-radius: 10px; color: var(--text); }
.url-row { display: flex; align-items: center; gap: 4px; background: var(--surface-2); border-radius: 10px; padding: 4px 4px 4px 12px; }
.url { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12.5px; color: var(--muted); }
.field { display: flex; flex-direction: column; gap: 4px; margin-top: 12px; }
.field select { padding: 8px 10px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); }

/* Settings card */
.settings { display: flex; flex-direction: column; gap: 14px; }
.save-to { display: flex; gap: 12px; align-items: flex-start; }
.save-to .icon { color: var(--accent); margin-top: 2px; }
.path { font-size: 13px; word-break: break-all; }
.toggle { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; cursor: pointer; }
.toggle input { margin-top: 3px; width: 16px; height: 16px; accent-color: var(--accent); flex: none; }
.help summary { cursor: pointer; font-weight: 600; font-size: 14px; }
.help ul { padding-left: 18px; margin: 10px 0 12px; font-size: 13.5px; color: var(--muted); }
.help li { margin: 5px 0; }
.small-btn { font-size: 13px; padding: 7px 10px; white-space: normal; text-align: left; }

/* Feed */
.feed-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 12px; }
.feed-head h1 { margin: 0; font-size: 22px; letter-spacing: -.02em; }
.day { margin: 22px 0 10px; font-size: 13px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.day:first-child { margin-top: 4px; }
.group { margin-bottom: 14px; padding: 16px; }
.group-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; font-size: 14px; }
.group-head .icon { color: var(--accent); }
.group-head b { font-weight: 650; }
.group.fresh { animation: arrive .5s ease-out; }
@keyframes arrive { from { transform: translateY(-6px); box-shadow: 0 0 0 3px var(--accent-soft); } to { transform: none; } }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 10px; }
.tile {
  position: relative; display: block; padding: 0; border: 0; border-radius: var(--radius-sm); overflow: hidden;
  background: var(--surface-2); aspect-ratio: 1; cursor: zoom-in; text-align: left;
}
.tile img, .tile video { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile .file-icon { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; color: var(--muted); padding: 10px; }
.tile .file-icon .ext { font-size: 12px; font-weight: 700; letter-spacing: .05em; }
.tile .file-icon .fname { font-size: 12px; text-align: center; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; word-break: break-all; }
.tile .badge { position: absolute; left: 8px; bottom: 8px; background: rgba(0, 0, 0, .6); color: #fff; font-size: 11px; font-weight: 650; padding: 2px 7px; border-radius: 6px; }
.tile.missing { opacity: .45; cursor: default; }
.tile:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.tile .reveal {
  position: absolute; top: 6px; right: 6px; opacity: 0; transition: opacity .15s;
  background: rgba(0, 0, 0, .55); color: #fff; border: 0; border-radius: 8px; padding: 5px; cursor: pointer; display: flex;
}
.tile:hover .reveal, .tile:focus-within .reveal { opacity: 1; }

/* Notes */
.note { margin-bottom: 14px; padding: 16px; }
.note-text {
  white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; font-size: 15px; line-height: 1.55;
  background: var(--surface-2); border-radius: var(--radius-sm); padding: 12px 14px; max-height: 280px; overflow: auto;
}
.note-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.note-actions .btn { font-size: 13px; padding: 6px 11px; }
.note-actions .spacer { flex: 1; }

/* Incoming */
.incoming { margin-bottom: 14px; padding: 16px; border-color: var(--accent); }
.incoming-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; align-items: center; margin-top: 10px; font-size: 14px; }
.incoming-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.incoming-row .progress { grid-column: 1 / -1; }

/* Empty */
.empty { text-align: center; padding: 48px 24px; }
.empty-art { width: 64px; height: 64px; margin: 0 auto 14px; border-radius: 18px; display: flex; align-items: center; justify-content: center; background: var(--accent-soft); color: var(--accent); }
.empty p { max-width: 380px; margin: 6px auto 0; }

/* Lightbox */
.lightbox { position: fixed; inset: 0; z-index: 50; background: rgba(8, 9, 12, .94); display: flex; align-items: center; justify-content: center; color: #fff; }
.lightbox[hidden] { display: none; }
.lb-top { position: absolute; top: 0; left: 0; right: 0; display: flex; gap: 8px; align-items: center; padding: 14px 16px; background: linear-gradient(rgba(0, 0, 0, .6), transparent); }
.lb-top .btn { background: rgba(255, 255, 255, .1); border-color: transparent; color: #fff; }
.lb-top .btn:hover { background: rgba(255, 255, 255, .2); }
.lb-title { flex: 1; min-width: 0; }
.lb-title > div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#lb-meta { opacity: .7; }
.lb-stage { max-width: calc(100vw - 140px); max-height: calc(100vh - 120px); display: flex; align-items: center; justify-content: center; }
.lb-stage img, .lb-stage video { max-width: calc(100vw - 140px); max-height: calc(100vh - 120px); object-fit: contain; border-radius: 6px; }
.lb-stage .file-big { text-align: center; opacity: .85; }
.lb-stage .file-big .icon { width: 64px; height: 64px; stroke-width: 1.5; }
.lb-nav { position: absolute; top: 50%; transform: translateY(-50%); background: rgba(255, 255, 255, .08); border: 0; color: #fff; border-radius: 50%; width: 48px; height: 48px; display: flex; align-items: center; justify-content: center; cursor: pointer; }
.lb-nav:hover { background: rgba(255, 255, 255, .18); }
.lb-nav.prev { left: 16px; }
.lb-nav.next { right: 16px; }
.lb-nav[disabled] { opacity: .2; cursor: default; }
@media (max-width: 640px) {
  .lb-stage, .lb-stage img, .lb-stage video { max-width: 100vw; }
  .lb-nav { display: none; }
  .lb-top .btn span { display: none; }
}

/* ---- Web (GitHub Pages) version additions ---- */
.banner {
  display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; margin-bottom: 16px;
  border-radius: var(--radius-sm); background: var(--accent-soft); color: var(--text); font-size: 14px;
}
.banner .icon { color: var(--accent); margin-top: 1px; }
.private-note { display: flex; gap: 8px; align-items: flex-start; margin: 12px 0 0; }
.private-note .icon { margin-top: 2px; color: var(--ok); }
.save-body { min-width: 0; flex: 1; }
.save-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.save-actions .btn { font-size: 13px; padding: 6px 10px; }
.save-actions .hint { font-size: 12.5px; color: var(--muted); }
.warn-row { color: var(--warn); font-size: 13px; }
.footer { margin-top: 24px; text-align: center; }
.saved-badge { position: absolute; left: 8px; top: 8px; background: rgba(0, 0, 0, .55); color: #fff; font-size: 11px; font-weight: 650; padding: 2px 7px; border-radius: 6px; }
.overlay { position: fixed; inset: 0; z-index: 60; background: rgba(8, 9, 12, .55); display: flex; align-items: center; justify-content: center; padding: 16px; }
.overlay[hidden] { display: none; }
.overlay-card { max-width: 420px; text-align: center; padding: 32px 24px; }
.overlay-card h2 { font-size: 19px; margin-bottom: 6px; }
.overlay-card .btn { margin-top: 14px; }
#save-where { word-break: normal; overflow-wrap: anywhere; }
.blocked { border-color: var(--danger); background: var(--danger-soft); }
.blocked h2 { color: var(--danger); }
.blocked p { margin: 6px 0 8px; }
.blocked ul { margin: 0; padding-left: 18px; }
.blocked li { margin: 4px 0; }
.shared-note { margin: 10px 0 0; padding: 10px 12px; border-radius: 10px; background: var(--surface-2); }
.shared-note kbd { font: 12px ui-monospace, Consolas, monospace; padding: 1px 5px; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 5px; background: var(--surface); }

/* New QR code button + refresh animation */
.new-qr { width: 100%; margin-top: 10px; }
.new-qr .icon { transition: transform .5s; }
.new-qr:hover .icon { transform: rotate(-90deg); }
.qr.refreshing { animation: qr-refresh .45s ease-out; }
@keyframes qr-refresh { 0% { opacity: .15; transform: scale(.94); } 100% { opacity: 1; transform: none; } }

/* Delete all + confirmation dialog */
.feed-head .btn.danger { border-color: transparent; background: transparent; }
.feed-head .btn.danger:hover { background: var(--danger-soft); }
.dialog { max-width: 420px; width: calc(100vw - 32px); padding: 28px 24px 22px; text-align: center; color: var(--text); }
.dialog::backdrop { background: rgba(8, 9, 12, .55); }
.dialog h2 { font-size: 19px; margin: 0 0 6px; }
.dialog p { margin: 0 0 12px; }
.dialog .toggle { text-align: left; justify-content: flex-start; margin: 14px 0 6px; padding: 10px 12px; border-radius: 10px; background: var(--surface-2); }
.danger-art { background: var(--danger-soft); color: var(--danger); }
.dialog-actions { display: flex; gap: 10px; justify-content: center; margin-top: 18px; }
.dialog-actions .btn { min-width: 110px; }
.btn.primary.danger-btn { background: var(--danger); border-color: var(--danger); color: #fff; }

/* ---- Compact sidebar: everything fits on one laptop screen without scrolling ---- */
.connect, .settings { padding: 16px; }
.card-head { display: flex; align-items: center; gap: 4px; }
.card-head h2 { flex: 1; margin: 0; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-head .icon-only { padding: 6px; }
.new-qr { width: auto; margin-top: 0; padding: 6px 10px; font-size: 13px; flex: none; }
.qr-wrap { margin: 12px 0 10px; }
.qr { width: 200px; height: 200px; padding: 8px; }
.connect .steps { margin: 0 0 6px; padding-left: 18px; font-size: 13.5px; }
.connect .steps li { margin: 2px 0; }
.connect .private-note { margin: 6px 0 0; }
.settings { gap: 10px; }
.options summary { font-size: 14px; }
.options-body { display: flex; flex-direction: column; gap: 9px; margin-top: 10px; }
.options-body ul { margin: 0; }
.help-title { margin: 6px 0 0; font-weight: 650; font-size: 13.5px; }
.empty .shared-note { max-width: 420px; margin: 16px auto 0; text-align: left; }
@media (max-height: 660px) and (min-width: 901px) {
  .qr { width: 176px; height: 176px; }
  .app { padding-top: 10px; }
  .top { margin-bottom: 10px; }
}

/* ---- Classroom ---- */
.classroom-btn { padding: 7px 12px; font-size: 13.5px; }
.classroom-btn.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.end-class { padding: 6px 10px; font-size: 13px; color: var(--danger); flex: none; }
.class-code-box { text-align: center; margin: 10px 0 2px; padding: 8px; border-radius: 12px; background: var(--accent-soft); }
.class-code { font: 700 30px/1.15 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: .08em; color: var(--text); }
.class-mode .qr { width: 150px; height: 150px; }
.class-mode .qr-wrap { margin: 8px 0 8px; }

.class-dialog { text-align: left; max-width: 440px; position: relative; }
.class-dialog h2 { text-align: center; }
.class-dialog > .empty-art { margin: 0 auto 10px; }
.dialog-close { position: absolute; top: 10px; right: 10px; }
.seg { display: flex; gap: 4px; padding: 4px; border-radius: 12px; background: var(--surface-2); margin: 12px 0 14px; }
.seg-btn { flex: 1; border: 0; background: transparent; padding: 8px 10px; border-radius: 9px; font-weight: 600; font-size: 14px; color: var(--muted); cursor: pointer; }
.seg-btn.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, .08); }
.class-form { display: flex; flex-direction: column; gap: 8px; }
.class-form p { margin: 2px 0 0; }
.field-label { font-size: 13px; font-weight: 600; margin-top: 4px; }
.text-input { width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); font-size: 15px; outline: none; }
.text-input:focus { border-color: var(--accent); background: var(--surface); }
.code-input { font: 600 20px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: .12em; text-transform: uppercase; text-align: center; }
.form-error { color: var(--danger); font-size: 13px; margin: 0; }
.btn.wide { width: 100%; padding: 11px; margin-top: 6px; }
.class-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; max-height: 240px; overflow: auto; }
.class-list li { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 12px; background: var(--surface-2); }
.class-list .class-info { flex: 1; min-width: 0; }
.class-list .class-name { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.class-list .class-meta { font: 13px ui-monospace, Consolas, monospace; color: var(--muted); letter-spacing: .05em; }
.class-list .btn { padding: 6px 12px; font-size: 13px; }
.recent-classes { display: flex; flex-direction: column; gap: 8px; }
.recent-classes .class-list { max-height: 190px; }
.recent-classes .btn.wide { margin-top: 2px; }
.class-list .empty-note { justify-content: center; color: var(--muted); font-size: 13.5px; background: transparent; border: 1px dashed var(--border); }
.new-class { display: flex; gap: 8px; margin-top: 6px; }
.new-class .text-input { flex: 1; }
.class-code-box { margin: 8px 0 0; padding: 6px 8px; }
.class-code { font-size: 26px; }
@media (max-height: 660px) and (min-width: 901px) {
  .class-mode .qr { width: 140px; height: 140px; }
}

/* ---- Computer code + Send to a computer ---- */
.send-btn { padding: 7px 12px; font-size: 13.5px; }
.top .classroom-btn { margin-left: 0; }
.class-code.refreshing { animation: qr-refresh .45s ease-out; }
.dialog-sub { text-align: center; margin: 4px 0 14px; }
@media (max-width: 520px) { .send-btn { padding: 7px 9px; } }

/* ---- Photo viewer on phones: always-visible close, Save label, room for the notch ---- */
.lb-top { padding-top: max(14px, env(safe-area-inset-top)); }
.lb-close-hint { display: none; }
@media (max-width: 640px) {
  .lb-top { gap: 6px; padding-left: 12px; padding-right: 12px; }
  .lb-top .btn { padding: 10px; }
  #lb-close { background: rgba(255, 255, 255, .22); }
  .is-phone #lb-download span { display: inline; }
  .is-phone #lb-download { padding: 10px 12px; }
}
@media (max-height: 660px) and (min-width: 901px) {
  .qr { width: 164px; height: 164px; }
  .class-mode .qr { width: 140px; height: 140px; }
}

/* ---- Header: buttons grouped at the top right; on phones the status pill gets its own line ---- */
.top-actions { display: flex; align-items: center; gap: 8px; }
@media (max-width: 520px) {
  .top { display: grid; grid-template-columns: minmax(0, 1fr) auto; row-gap: 10px; column-gap: 8px; }
  .top .spacer { display: none; }
  .top .logo { grid-column: 1; grid-row: 1; min-width: 0; }
  .top .top-actions { grid-column: 2; grid-row: 1; gap: 6px; }
  .top #status { grid-column: 1 / -1; grid-row: 2; justify-self: start; max-width: 100%; }
  .top-actions .btn { padding: 8px 9px; }
}
@media (max-height: 660px) and (min-width: 901px) {
  .qr { width: 152px; height: 152px; }
}

/* ---- Teacher: send a message or link to the whole class ---- */
.broadcast { margin-bottom: 16px; padding: 14px 16px; border-color: color-mix(in srgb, var(--accent) 35%, var(--border)); }
.broadcast-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.broadcast-head .icon { color: var(--accent); }
.broadcast-head .muted { margin-left: auto; }
.broadcast-form { display: flex; gap: 8px; align-items: flex-end; }
.broadcast-form textarea {
  flex: 1; min-height: 42px; max-height: 140px; resize: none; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface-2); font-size: 15px; line-height: 1.4; outline: none;
}
.broadcast-form textarea:focus { border-color: var(--accent); background: var(--surface); }
.broadcast-form .btn { padding: 10px 16px; }
.broadcast-sent { margin-top: 12px; }
.broadcast-sent-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.broadcast-sent-head .btn { padding: 4px 10px; font-size: 13px; }
.broadcast-list { list-style: none; margin: 6px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 180px; overflow: auto; }
.broadcast-list li { display: flex; align-items: flex-start; gap: 10px; padding: 8px 10px; border-radius: 10px; background: var(--surface-2); font-size: 14px; }
.broadcast-list .msg-text { flex: 1; min-width: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.broadcast-list .msg-meta { flex: none; color: var(--muted); font-size: 12px; white-space: nowrap; }

/* ---- Teacher: hide the QR code for a bigger class code, and a full-screen view for the projector ---- */
.code-head { display: flex; align-items: center; justify-content: center; gap: 6px; }
.class-mode .code-head { justify-content: space-between; padding-left: 4px; }
.code-tools { display: flex; gap: 2px; flex: none; }
.code-tools .btn { padding: 2px 7px; font-size: 12px; gap: 4px; color: var(--accent); border-radius: 7px; }
.code-tools .btn:hover { background: var(--surface); color: var(--accent); }
.class-mode.qr-hidden .qr-wrap { display: none; }
.class-mode.qr-hidden .class-code-box { padding: 8px 8px 16px; margin-bottom: 10px; }
.class-mode.qr-hidden .class-code { font-size: min(46px, 12vw); line-height: 1.25; margin-top: 6px; }
.class-mode.qr-hidden #steps-class { list-style: none; padding-left: 0; text-align: center; }
.class-mode.qr-hidden #steps-class li:last-child { display: none; } /* "Or scan the QR code" */

.present {
  position: fixed; inset: 0; z-index: 70; display: flex; flex-direction: column;
  background: var(--bg); color: var(--text); padding: 18px clamp(16px, 3vw, 48px) 28px;
}
.presenting .toast { display: none; } /* nothing about students' files on the big screen */
.present-top { display: flex; align-items: center; gap: 12px; min-width: 0; }
.present-class { font-size: clamp(18px, 2.2vw, 32px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.present-count { color: var(--muted); font-size: clamp(14px, 1.4vw, 20px); white-space: nowrap; }
.present-top .spacer { flex: 1; }
.present-top .btn { flex: none; }
.present-body { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; gap: clamp(24px, 5vw, 96px); }
.present-main { text-align: center; min-width: 0; }
.present-step { font-size: clamp(18px, 2.6vw, 44px); margin: 0 0 .8em; }
.present-label { color: var(--muted); font-size: clamp(14px, 1.6vw, 26px); font-weight: 650; text-transform: uppercase; letter-spacing: .14em; }
.present-code {
  font: 800 min(10vw, 24vh)/1.1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: .06em; white-space: nowrap; color: var(--text);
}
.present.no-qr .present-code { font-size: min(14.5vw, 30vh); }
.present-qr-box { flex: none; text-align: center; color: var(--muted); font-size: clamp(14px, 1.6vw, 24px); }
.present-qr-box p { margin: .6em 0 0; }
.present-qr { width: min(40vh, 28vw); height: min(40vh, 28vw); padding: 12px; background: #fff; border-radius: 18px; }
.present-qr svg { display: block; width: 100%; height: 100%; }
.present.no-qr .present-qr-box { display: none; }
@media (max-width: 520px) {
  .present-top { gap: 8px; }
  .present-count { display: none; }
  .present-top .btn { padding: 6px 10px; font-size: 13px; }
}
@media (orientation: portrait) {
  .present-body { flex-direction: column; gap: 32px; }
  .present-code, .present.no-qr .present-code { font-size: min(13vw, 14vh); }
  .present-qr { width: min(60vw, 34vh); height: min(60vw, 34vh); }
}
