:root {
  --bg: #f7f4ef;
  --surface: #ffffff;
  --soft: #faf8f3;
  --ink: #2b2b2b;
  --muted: #6b6b6b;
  --accent: #6b8e4e;
  --accent-dark: color-mix(in srgb, var(--accent) 75%, black);
  --accent-soft: color-mix(in srgb, var(--accent) 10%, white);
  --accent-line: color-mix(in srgb, var(--accent) 35%, white);
  --good: #2f7d3a;
  --bad: #b03434;
  --warn: #9a6a00;
  --line: #e6e1d6;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
}
a { color: var(--accent-dark); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
em.alt, .italic { font-style: italic; }

/* ---- top bar ---- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  max-width: 992px; margin: 0 auto; padding: 14px 16px 0;
}
.brand { font-weight: 700; font-size: 18px; color: var(--ink); text-decoration: none; display: inline-flex; gap: 8px; align-items: center; }
.brand i { color: var(--accent); }
.crumbs { display: flex; gap: 6px; align-items: center; font-size: 14px; color: var(--muted); min-width: 0; }
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--accent-dark); }

main { display: flex; flex-direction: column; align-items: center; padding: 14px 16px 48px; gap: 16px; }
.container {
  width: 100%; max-width: 720px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.05);
  padding: 28px 28px 32px;
}
.container.wide { max-width: 960px; }
h1 { margin: 0 0 6px; font-size: 28px; letter-spacing: -0.01em; }
h2 { margin: 0 0 12px; font-size: 20px; }
.subtitle { color: var(--muted); margin: 0 0 22px; font-size: 15px; }
.field { margin-bottom: 18px; }
.section-label {
  display: block; font-weight: 600; margin-bottom: 8px;
  font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted);
}

/* ---- buttons ---- */
button { font: inherit; }
.primary, .secondary {
  cursor: pointer; border-radius: 10px; padding: 12px 20px; border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s; text-decoration: none; display: inline-block;
}
.primary { background: var(--accent); color: white; font-weight: 600; }
.primary:hover { background: var(--accent-dark); }
.primary:disabled { opacity: 0.45; cursor: not-allowed; }
.secondary { background: white; border-color: var(--line); color: var(--ink); }
.secondary:hover { border-color: var(--accent); color: var(--accent-dark); }
.small { padding: 7px 12px; font-size: 14px; }
.chip-btn {
  cursor: pointer; background: white; border: 1px solid var(--line);
  border-radius: 999px; padding: 5px 12px; font-size: 13px; color: var(--ink);
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.chip-btn:hover { border-color: var(--accent); color: var(--accent-dark); }
.chip-btn.on { background: var(--accent); border-color: var(--accent); color: white; }
/* Icon-only buttons: no box until hovered, focused or pressed. */
.icon {
  cursor: pointer; background: transparent; border: 1px solid transparent; border-radius: 8px;
  width: 36px; height: 36px; display: inline-flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 16px; text-decoration: none; flex: 0 0 auto;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}
.icon:hover, .icon:focus-visible, .icon:active { border-color: var(--line); background: var(--soft); color: var(--ink); outline: none; }
.icon.danger, .icon.danger:hover { color: var(--bad); }
.icon:disabled { opacity: 0.35; cursor: not-allowed; }
.icon.big { width: 48px; height: 48px; font-size: 20px; }
.actions { margin-top: 22px; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* ---- forms ---- */
input[type="text"], input[type="password"], input[type="number"], input[type="search"], textarea, select {
  font: inherit; font-size: 16px; padding: 10px 12px; width: 100%;
  border: 1px solid var(--line); border-radius: 10px; background: white; color: var(--ink);
}
textarea { resize: vertical; min-height: 64px; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); }
input:disabled { background: var(--soft); }

.options { display: grid; gap: 8px; }
.options.two { grid-template-columns: 1fr 1fr; }
@media (max-width: 520px) { .options.two { grid-template-columns: 1fr; } }
.option {
  display: flex; align-items: flex-start; gap: 10px;
  border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.option:hover { border-color: var(--accent); }
.option input { margin-top: 3px; accent-color: var(--accent); }
.option:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.opt-title { font-weight: 600; }
.opt-desc { color: var(--muted); font-size: 13px; margin-top: 2px; }
.toggle-row { display: flex; gap: 10px; flex-wrap: wrap; }
.toggle-row label {
  display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 14px; cursor: pointer; font-size: 14px;
}
.toggle-row label:hover { border-color: var(--accent); }
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); }

/* ---- home ---- */
.class-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.class-card {
  display: flex; flex-direction: column; text-decoration: none; color: var(--ink);
  border: 1px solid var(--line); border-radius: 14px; overflow: hidden; background: white;
  transition: border-color 0.15s, transform 0.15s;
}
.class-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.class-card .cover { aspect-ratio: 16 / 10; background: var(--soft) center / cover no-repeat; display: flex; align-items: center; justify-content: center; font-size: 40px; }
.class-card .body { padding: 12px 14px 14px; }
.class-card .name { font-weight: 700; font-size: 17px; }
.class-card .meta { color: var(--muted); font-size: 13px; margin-top: 4px; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }

/* ---- tabs ---- */
.tabs { display: flex; gap: 4px; background: var(--soft); border: 1px solid var(--line); border-radius: 12px; padding: 4px; margin-bottom: 22px; }
.tabs a {
  flex: 1; text-align: center; padding: 9px 10px; border-radius: 9px; text-decoration: none;
  color: var(--muted); font-weight: 600; display: inline-flex; gap: 8px; justify-content: center; align-items: center;
}
.tabs a.on { background: white; color: var(--accent-dark); box-shadow: 0 1px 3px rgba(0,0,0,0.08); }

/* ---- item picker ---- */
.picker { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.picker-header { padding: 10px 14px; background: var(--soft); border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.picker-header .row { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.picker-header .summary { font-size: 13px; color: var(--muted); }
.picker-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.picker-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 2px 12px; max-height: 300px; overflow-y: auto; padding: 10px 14px; }
@media (max-width: 520px) { .picker-grid { grid-template-columns: 1fr; } }
.picker-grid label { display: flex; align-items: center; gap: 8px; padding: 4px 0; font-size: 14px; cursor: pointer; user-select: none; min-width: 0; }
.picker-grid label:hover { color: var(--accent-dark); }
.picker-grid label.unavailable { opacity: 0.4; }
.picker-grid .label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picker-grid .label .sub { color: var(--muted); font-size: 12px; margin-left: 6px; }
.picker-grid .count { color: var(--muted); font-size: 12px; }
.qcount { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.qcount input { width: 100px; }
.qcount .hint { color: var(--muted); font-size: 13px; }

/* ---- session ---- */
.meta-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; color: var(--muted); font-size: 14px; gap: 10px; }
.progress-bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin-bottom: 18px; }
.progress-bar > div { height: 100%; background: var(--accent); transition: width 0.3s; }

.card { perspective: 1200px; width: 100%; aspect-ratio: 4 / 3; margin-bottom: 12px; cursor: pointer; }
.card-inner { position: relative; width: 100%; height: 100%; transform-style: preserve-3d; transition: transform 0.55s cubic-bezier(.55,.05,.32,1.02); }
.card.flipped .card-inner { transform: rotateY(180deg); }
.card-face {
  position: absolute; inset: 0; backface-visibility: hidden; border-radius: 14px; overflow: hidden;
  display: flex; flex-direction: column; align-items: stretch; justify-content: center;
  background: var(--soft); border: 1px solid var(--line);
}
.card-face.back { transform: rotateY(180deg); }
.face-img { flex: 1; min-height: 0; display: flex; }
.face-img img { width: 100%; height: 100%; object-fit: contain; }
.face-text { padding: 20px 28px; text-align: center; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; }
.face-img + .face-text { padding: 10px 16px 14px; flex: 0 0 auto; max-height: 45%; border-top: 1px solid var(--line); background: white; }
.face-text .v-main { font-size: clamp(26px, 5.5vw, 42px); font-weight: 700; letter-spacing: -0.01em; }
.face-text .v-other { font-size: clamp(16px, 3vw, 22px); color: var(--muted); }
.face-text .v-main.long, .face-text .v-other.long { font-size: clamp(15px, 2.6vw, 19px); font-weight: 500; color: var(--ink); text-align: left; line-height: 1.45; }
.face-img + .face-text .v-main { font-size: clamp(20px, 4vw, 28px); }
.face-text .v-label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.face-text .notes { font-size: 14px; color: var(--muted); line-height: 1.4; }
.hint-line { text-align: center; color: var(--muted); font-size: 13px; margin-bottom: 12px; user-select: none; }
.nav-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.nav-row .center { display: flex; gap: 6px; justify-content: center; flex: 1; }

.prompt-box { width: 100%; aspect-ratio: 4 / 3; background: var(--soft); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; display: flex; align-items: center; justify-content: center; margin-bottom: 18px; }
.prompt-box img { width: 100%; height: 100%; object-fit: contain; }
.prompt-box.text { aspect-ratio: auto; min-height: 160px; padding: 26px; flex-direction: column; gap: 6px; text-align: center; }
.prompt-box.text .v-main { font-size: clamp(22px, 5vw, 34px); font-weight: 700; }
.prompt-box.text .v-main.long { font-size: 18px; font-weight: 500; text-align: left; line-height: 1.45; }
.prompt { font-size: 15px; color: var(--muted); margin-bottom: 10px; }
.prompt strong { color: var(--ink); }
.answer-grid { display: grid; gap: 12px; }
.answer-grid label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.05em; }
.answer-grid input.ok { border-color: var(--good); background: #f3faf0; }
.answer-grid input.no { border-color: var(--bad); background: #fdf3f2; }

.choices { display: grid; gap: 8px; }
.choice {
  display: flex; gap: 12px; align-items: center; text-align: left; width: 100%;
  cursor: pointer; background: white; border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; color: var(--ink);
}
.choice:hover:not(:disabled) { border-color: var(--accent); }
.choice .key { flex: 0 0 26px; height: 26px; border-radius: 6px; background: var(--soft); border: 1px solid var(--line); display: inline-flex; align-items: center; justify-content: center; font-size: 13px; color: var(--muted); }
.choice:disabled { cursor: default; }
.choice.right { border-color: var(--good); background: #ecf5e7; }
.choice.wrong { border-color: var(--bad); background: #fbecea; }

.feedback { margin-top: 16px; padding: 14px 16px; border-radius: 10px; font-size: 15px; line-height: 1.45; }
.feedback.good { background: #ecf5e7; border: 1px solid #bcd9a8; color: var(--good); }
.feedback.bad { background: #fbecea; border: 1px solid #efc5bf; color: var(--bad); }
.feedback.check { background: var(--soft); border: 1px solid var(--line); color: var(--ink); }
.feedback .line { color: var(--ink); margin-top: 6px; font-size: 14px; }
.feedback .close { color: var(--warn); font-size: 14px; margin-top: 6px; }

.results-summary { text-align: center; margin-bottom: 22px; padding: 22px; background: var(--accent-soft); border: 1px solid var(--accent-line); border-radius: 12px; }
.score { font-size: 44px; font-weight: 700; color: var(--accent-dark); margin-bottom: 4px; }
.review-list { border-top: 1px solid var(--line); }
.review-item { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.review-item .thumb { width: 56px; height: 56px; border-radius: 8px; background: var(--soft); object-fit: cover; flex: 0 0 56px; }
.review-item .verdict { font-weight: 700; flex: 0 0 22px; text-align: center; }
.review-item .verdict.ok { color: var(--good); }
.review-item .verdict.no { color: var(--bad); }
.review-item .text { flex: 1; min-width: 0; }
.review-item .you { color: var(--muted); font-size: 13px; }

/* ---- editor ---- */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; justify-content: space-between; margin-bottom: 18px; }
.class-rows { border-top: 1px solid var(--line); }
.class-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.class-row .thumb { width: 48px; height: 48px; border-radius: 8px; object-fit: cover; background: var(--soft); flex: 0 0 48px; display: flex; align-items: center; justify-content: center; color: var(--muted); }
.class-row .text { flex: 1; min-width: 0; }
.class-row .name { font-weight: 600; }
.class-row .meta { font-size: 13px; color: var(--muted); }
.class-row .btns { display: flex; gap: 2px; }
.notice { padding: 12px 14px; border-radius: 10px; font-size: 14px; margin-bottom: 16px; line-height: 1.45; }
.notice.bad { background: #fbecea; border: 1px solid #efc5bf; color: var(--bad); }
.notice.good { background: #ecf5e7; border: 1px solid #bcd9a8; color: var(--good); }
.notice ul { margin: 6px 0 0; padding-left: 20px; max-height: 240px; overflow-y: auto; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 600px) { .grid-2 { grid-template-columns: 1fr; } }
.form-label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.form-hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.color-input { display: flex; gap: 8px; align-items: center; }
.color-input input[type="color"] { width: 44px; height: 42px; border: 1px solid var(--line); border-radius: 10px; padding: 3px; background: white; }

.field-rows { display: grid; gap: 8px; }
.field-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.field-row input[type="text"] { flex: 1; min-width: 160px; }
.field-row .key { font-family: ui-monospace, monospace; font-size: 12px; color: var(--muted); }
.field-row label { display: inline-flex; gap: 6px; align-items: center; font-size: 14px; }

.item-list { display: grid; gap: 10px; }
.item-card { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; background: white; }
.item-card .head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.item-card .head .num { color: var(--muted); font-size: 13px; flex: 1; }
.item-card .vals { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 10px; }
.item-card .alts { margin-top: 4px; font-size: 14px; padding: 6px 10px; }
.item-card .extra { display: grid; grid-template-columns: 1fr 2fr; gap: 10px; margin-top: 10px; }
@media (max-width: 600px) { .item-card .extra { grid-template-columns: 1fr; } }
.pics { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; align-items: center; }
.pic { position: relative; width: 72px; height: 72px; }
.pic img { width: 100%; height: 100%; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.pic .icon { position: absolute; top: -8px; right: -8px; width: 26px; height: 26px; font-size: 12px; background: white; border-color: var(--line); }
.add-pic { width: 72px; height: 72px; border: 1px dashed var(--line); border-radius: 8px; display: flex; align-items: center; justify-content: center; color: var(--muted); cursor: pointer; }
.add-pic:hover { border-color: var(--accent); color: var(--accent-dark); }
.save-bar {
  position: sticky; bottom: 0; z-index: 5; width: 100%; max-width: 960px;
  background: white; border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px;
  display: flex; gap: 10px; align-items: center; justify-content: flex-end; box-shadow: 0 -4px 14px rgba(0,0,0,0.06);
}
.save-bar .status { flex: 1; font-size: 14px; color: var(--muted); }

@media (max-width: 520px) {
  .container { padding: 20px 16px 24px; }
  h1 { font-size: 22px; }
  .score { font-size: 36px; }
}

/* ---- user menu, banners, dialogs ---- */
.menu { position: relative; }
.menu-btn {
  cursor: pointer; background: transparent; border: 1px solid transparent; border-radius: 8px; padding: 6px 10px;
  color: var(--muted); display: inline-flex; gap: 6px; align-items: center; font-size: 14px; max-width: 220px;
}
.menu-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-btn:hover, .menu-btn:focus-visible, .menu-btn[aria-expanded="true"] { border-color: var(--line); background: white; color: var(--ink); outline: none; }
.menu-list {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 20; min-width: 170px;
  background: white; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,0.1); padding: 6px;
}
.menu-list a, .menu-list button {
  display: block; width: 100%; text-align: left; padding: 8px 10px; border-radius: 6px; border: 0; background: none;
  color: var(--ink); text-decoration: none; font-size: 14px; cursor: pointer;
}
.menu-list a:hover, .menu-list button:hover { background: var(--soft); }
.menu-list hr { border: 0; border-top: 1px solid var(--line); margin: 6px 0; }
.banner { background: #2b2b2b; color: white; font-size: 14px; padding: 8px 16px; display: flex; gap: 12px; justify-content: center; align-items: center; flex-wrap: wrap; }
.banner button { background: white; color: #2b2b2b; border: 0; border-radius: 6px; padding: 4px 10px; cursor: pointer; font-weight: 600; }
.banner.warn { background: #fff4d6; color: #6b4e00; }
.banner.warn a { color: #6b4e00; font-weight: 600; }

dialog.modal { border: 1px solid var(--line); border-radius: 14px; padding: 22px; width: min(520px, calc(100vw - 32px)); box-shadow: 0 12px 40px rgba(0,0,0,0.18); }
dialog.modal::backdrop { background: rgba(0,0,0,0.3); }
dialog.modal h2 { margin-top: 0; }
.share-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.share-row .who { flex: 1; min-width: 0; }
.share-row .who .muted { font-size: 13px; }
.share-row select { width: auto; padding: 6px 8px; font-size: 14px; }
.share-add { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.share-add select:first-child { flex: 1; min-width: 160px; }
.share-add select { width: auto; }

.section-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 0 0 12px; flex-wrap: wrap; }
.card-actions { display: flex; gap: 0; padding: 0 8px 8px; margin-top: -6px; }
.class-tile { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; background: white; transition: border-color 0.15s, transform 0.15s; }
.class-tile:hover { border-color: var(--accent); }
.class-tile .class-card { border: 0; border-radius: 0; }
.class-tile .class-card:hover { transform: none; }
.badge { display: inline-block; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; padding: 2px 7px; border-radius: 999px; background: var(--soft); border: 1px solid var(--line); color: var(--muted); vertical-align: middle; }
.badge.admin { background: #fde9c8; border-color: #f2cf8f; color: #7a4d00; }
.badge.off { background: #fbecea; border-color: #efc5bf; color: var(--bad); }
.link-box { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.link-box input { font-family: ui-monospace, monospace; font-size: 13px; }
.code-big { font-family: ui-monospace, monospace; font-size: 34px; font-weight: 700; letter-spacing: 0.08em; text-align: center; padding: 14px; background: var(--soft); border: 1px solid var(--line); border-radius: 12px; margin: 10px 0; }
table.users { width: 100%; border-collapse: collapse; font-size: 14px; }
table.users th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); padding: 6px 8px; border-bottom: 1px solid var(--line); }
table.users td { padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.users tr.row { cursor: pointer; }
table.users tr.row:hover td { background: var(--soft); }
@media (max-width: 640px) { table.users .wide { display: none; } }
.check-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.check-row label { display: inline-flex; gap: 6px; align-items: center; border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; font-size: 14px; cursor: pointer; }
.list-plain { list-style: none; padding: 0; margin: 0; }
.list-plain li { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.list-plain li .grow { flex: 1; min-width: 0; }

.qr { margin: 14px 0 4px; text-align: center; }
.qr svg { width: 200px; height: 200px; background: white; border: 1px solid var(--line); border-radius: 10px; }
.qr figcaption { font-size: 13px; color: var(--muted); margin-top: 6px; }
