/* Shared surfaces: every application route uses the Sheikah tokens. */

img { display: block; max-width: 100%; }
input, select, textarea { font: inherit; color: inherit; caret-color: var(--cyan); }
button, a, input, select, textarea { -webkit-tap-highlight-color: transparent; }
button:disabled { cursor: not-allowed; }
[hidden] { display: none !important; }
h1, h2, h3 { overflow-wrap: anywhere; text-wrap: balance; }
.icon { display: block; width: 20px; height: 20px; flex: none; }
.btn .icon, .ghost .icon { width: 18px; height: 18px; }
.btn, .ghost, .tabs button, .rune-choice, .rune-act { min-height: 44px; }
.btn, .ghost { text-decoration: none; text-align: center; }
.btn-primary:hover:not(:disabled) { background: var(--cyan); color: var(--cyan-ink); }
.btn-ghost { background: transparent; }
.ghost[aria-current="page"] { color: var(--cyan); background: var(--cyan-soft); border-radius: var(--r-sm); }
.field { min-width: 0; }
.field > span { color: var(--ink-2); font-size: 12px; letter-spacing: 0.04em; }
.field input, .field select, .field textarea, .admin-reset input { width: 100%; min-width: 0; min-height: 44px; padding: 10px 12px; border: 1px solid var(--line-2); border-radius: var(--r-md); color: var(--ink); background: var(--surface-3); }
.field textarea { resize: vertical; }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 1; }
.field input:hover, .field select:hover, .field textarea:hover { border-color: var(--line-3); }
[aria-invalid="true"] { border-color: var(--hp) !important; }
.field-hint { color: var(--muted); font-size: 12px; margin-top: -8px; }
.section-heading { font-size: 24px; }
.lede { max-width: 65ch; color: var(--ink-2); font-size: 16px; line-height: 1.7; }
.page { width: 100%; max-width: 1360px; margin: 0 auto; padding: var(--s6) max(var(--s5), env(safe-area-inset-right)) max(80px, env(safe-area-inset-bottom)) max(var(--s5), env(safe-area-inset-left)); min-width: 0; }
.page-narrow { max-width: 1180px; display: flex; flex-direction: column; gap: var(--s5); }
.page-heading { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: var(--s4); }
.page-heading h1 { font-size: 36px; margin-bottom: var(--s2); }
.alert, .gate-error { padding: var(--s3) var(--s4); color: var(--ink); background: var(--hp-soft); border: 1px solid var(--hp); border-radius: var(--r-md); font-size: 14px; }

/* The same navigation stays in place across the teacher and pupil paths. */
.topbar { height: auto; min-height: var(--topbar-h); gap: var(--s4); padding-block: max(8px, env(safe-area-inset-top)) 8px; }
.topbar > .class-picker { flex: none; max-width: 320px; }
.topbar-welcome .top-end { width: auto; margin-left: auto; }
.topbar-welcome .ghost span { display: inline; }
.top-end { gap: var(--s2); }
.board, .single, .sheet > *, .atelier > *, .rune-card-head h3 { min-width: 0; }
.board-sub, .panel-note, .target-names { line-height: 1.6; }
.console-head { align-items: center; gap: var(--s3); }
.console-head h2 { font-size: 15px; letter-spacing: 0.05em; }
.console-head .btn { flex: none; }
.console details.panel > summary { min-height: 44px; letter-spacing: 0.05em; }
.console details.panel > summary::after { content: ""; margin-left: auto; width: 7px; height: 7px; flex: none; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: rotate(45deg); }
.console details.panel[open] > summary::after { transform: rotate(225deg); }
.console .panel > .btn { margin-top: var(--s3); }
.add-form { display: flex; flex-direction: column; gap: var(--s3); }
.field-row > .field { flex: 1 1 120px; }
.hero-sheet-art { flex: none; }
.hero-sheet-facts { min-width: 0; }
.hero-sheet-top { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); }
.gear { grid-template-columns: minmax(0, 1fr); }
.gear div { align-items: baseline; }
.gear dd { text-align: right; overflow-wrap: anywhere; }
.account-line { flex-wrap: wrap; overflow-wrap: anywhere; }
.rune-card-head h3 { letter-spacing: 0.03em; }
.lvl-seal { flex: none; }
.rune-card.is-out { opacity: 1; }
.rune-card.is-out .hero-fig { filter: grayscale(1); }
.out-tag { color: var(--void); font-weight: 700; }
:root[data-theme="light"] .out-tag { color: white; }
.picker { padding: var(--s5) 0; }
.picker-card strong { overflow-wrap: anywhere; max-width: 100%; }
.picker-card .level { font-size: 13px; }
.picker .empty { padding-block: var(--s6); }
.hero-page-heading { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: var(--s3); max-width: 1360px; margin: 0 auto var(--s5); }
.hero-page-heading h1 { font-size: clamp(26px, 3vw, 40px); max-width: 28ch; }
.equipment-details { padding-block: var(--s3); border-top: 1px solid var(--line); }
.equipment-details summary { cursor: pointer; color: var(--ink-2); min-height: 44px; padding-block: var(--s3); }
.viewer-fallback { width: 100%; height: 90%; object-fit: contain; }
/* The recovery portrait has a different crop from the live camera. Showing it
   during loading creates a false zoom jump; reserve it for actual failures. */
[data-viewer-host].is-loading .viewer-fallback { visibility: hidden; }
.viewer-recovery { position: absolute; z-index: 2; bottom: var(--s4); left: var(--s4); right: var(--s4); display: flex; align-items: center; flex-wrap: wrap; justify-content: center; gap: var(--s3); padding: var(--s3); background: var(--panel-solid); border: 1px solid var(--line); border-radius: var(--r-md); }
.viewer-recovery .viewer-error { position: static; color: var(--ink-2); }
.sheet-info > .row { order: -1; }

/* Welcome and teacher unlock use one form language. */
.gate-page { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 440px); gap: clamp(32px, 6vw, 96px); align-items: center; max-width: 1180px; min-height: calc(100dvh - var(--topbar-h)); padding-block: var(--s7) 80px; }
.gate-intro h1 { max-width: 13ch; font-size: clamp(32px, 4vw, 52px); line-height: 1.14; }
.gate-intro .lede { margin-top: var(--s5); max-width: 40ch; }
.gate-heroes { display: flex; align-items: end; justify-content: center; margin-top: var(--s5); padding-bottom: var(--s4); border-bottom: 1px solid var(--line-2); }
.gate-heroes img { width: 50%; height: clamp(180px, 24vw, 290px); object-fit: contain; }
.gate { min-width: 0; width: 100%; }
.gate-card { display: flex; flex-direction: column; gap: var(--s4); padding: var(--s6); background: var(--panel-solid); border: 1px solid var(--line-2); border-radius: var(--r-lg); }
.gate-card h1, .gate-card h2 { font-size: 30px; }
.gate-lede, .gate-help { color: var(--ink-2); font-size: 14px; line-height: 1.65; }
.gate-tabs { margin-block: var(--s2); }
.gate-tabs button { font-family: var(--font-display); font-size: 14px; font-weight: 600; }
.gate-tabs button:hover:not(:disabled) { background: var(--cyan-soft); }
.gate-tabs button:disabled { opacity: 0.6; }
.gate-form { display: flex; flex-direction: column; gap: var(--s4); }
.gate-form .btn { width: 100%; min-height: 48px; font-size: 15px; margin-top: var(--s2); }
.gate-form input { min-height: 48px; }
.gate-actions { display: flex; flex-wrap: wrap; gap: var(--s2); }
.gate-actions .btn { flex: 1 1 160px; }
.gate-badge { color: var(--cyan); }
.gate-badge .icon { width: 32px; height: 32px; }
.lock-page { max-width: 540px; padding-top: clamp(24px, 8vh, 80px); }

/* Reading surface: the game's own words, with projection-friendly measure. */
.rules { display: flex; flex-direction: column; gap: var(--s6); max-width: 880px; width: 100%; margin-inline: auto; padding: var(--s6); background: var(--panel-solid); border: 1px solid var(--line); border-radius: var(--r-lg); }
.rules-head h1 { font-size: 36px; margin-bottom: var(--s4); }
.rules-section h2 { font-size: 24px; margin-bottom: var(--s4); }
.rules-section + .rules-section { padding-top: var(--s5); border-top: 1px solid var(--line); }
.rules-list { margin: 0; padding-left: 24px; display: flex; flex-direction: column; gap: var(--s3); font-size: 16px; line-height: 1.7; color: var(--ink-2); }
.rules-list li::marker { color: var(--cyan); }

/* A shop remains in the current role and always names its hero. */
.shop-hero-summary { display: flex; align-items: center; flex-wrap: wrap; gap: var(--s3); padding-block: var(--s3); border-block: 1px solid var(--line); }
.shop-hero-summary img { object-fit: contain; }
.shop-hero-summary > strong { font-family: var(--font-display); font-size: 24px; overflow-wrap: anywhere; }
.shop-head { flex-wrap: wrap; align-items: start; gap: var(--s4); }
.shop-tabs { flex: 1 1 100%; }
.shop-tabs button { min-height: 44px; border-radius: var(--r-md); padding: 8px 12px; font-size: 13px; }
.shop-tabs button:hover { border-color: var(--cyan); background: var(--cyan-soft); }
.shop-balance { flex-wrap: wrap; font-size: 14px; }
.shop-items { grid-template-columns: repeat(auto-fill, minmax(min(100%, 176px), 1fr)); gap: var(--s4); }
.shop-item { min-width: 0; gap: var(--s3); background: var(--panel-solid); padding: var(--s3); }
.shop-item.is-equipped { border-color: var(--cyan); }
.shop-item > .btn { margin-top: auto; }
.shop-item-text strong { font-size: 14px; }
.shop-item-text small, .shop-item-description { font-size: 12px; }
.shop-thumb { position: relative; width: 100%; min-height: 132px; padding: var(--s3); color: var(--ink); background: var(--surface-3); border: 1px solid var(--line); cursor: pointer; }
.shop-thumb:hover { border-color: var(--cyan); }
.shop-thumb .item-art { width: 112px; height: 112px; object-fit: contain; }
.shop-thumb .item-tier { position: absolute; top: 8px; right: 8px; }
.title-chip, .hero-title-tag { color: var(--amber); font-family: var(--font-display); font-weight: 600; overflow-wrap: anywhere; }
.title-chip { font-size: 16px; }

/* Earned titles are a prestige ladder. Tier 1 is quiet; each tier adds colour,
 * ornament, glow and (for tier 4-5) a plaque, ending in a radiant gold legend. */
.hero-title-tag {
  --title-color: #5c6b5e;
  --title-glow: transparent;
  display: block;
  color: var(--title-color);
  font-size: 20px;
  line-height: 1.2;
  text-align: center;
}
.hero-title-label { display: block; margin-bottom: 8px; font: 600 11px/1.3 var(--font-ui); text-transform: uppercase; letter-spacing: .14em; color: var(--muted); }
.hero-title-ribbon { display: flex; align-items: center; justify-content: center; gap: 5px; min-width: 0; position: relative; }
.hero-title-name { min-width: 0; overflow-wrap: anywhere; }
.title-ornament { width: 28px; height: 24px; flex: 0 0 auto; }
.title-ornament:last-child { transform: scaleX(-1); }
.title-ornament .orn-gem { fill: currentColor; }
.title-ornament .orn-dot { fill: currentColor; stroke: none; }

.hero-title-tag[data-title-tier="1"] { --title-color: #5c6b5e; }
.hero-title-tag[data-title-tier="2"] { --title-color: #2f6fa8; --title-glow: rgba(47,111,168,.28); }
.hero-title-tag[data-title-tier="3"] { --title-color: #2b7d63; --title-glow: rgba(43,125,99,.34); }
.hero-title-tag[data-title-tier="4"] { --title-color: #a23b3b; --title-glow: rgba(162,59,59,.40); }
.hero-title-tag[data-title-tier="5"] { --title-color: #a07a1e; --title-glow: rgba(197,150,42,.55); }

/* Four prestige titles carry their own identity instead of inheriting the tier
 * colour: Explorer teal, Champion amber, King royal violet, Legend rose. Names
 * are unchanged; only the visual treatment differs. */
.hero-title-tag[data-title-id="pathfinder"] { --title-color: #1f7f88; --title-glow: rgba(31,127,136,.32); }
.hero-title-tag[data-title-id="realm-champion"] { --title-color: #9c5f12; --title-glow: rgba(156,95,18,.36); }
.hero-title-tag[data-title-id="paragon-sovereign"] { --title-color: #5c3f9c; --title-glow: rgba(92,63,156,.36); }
.hero-title-tag[data-title-id="class-legend"] { --title-color: #a83a72; --title-glow: rgba(168,58,114,.40); }

.hero-title-tag[data-title-tier="3"] .title-ornament,
.hero-title-tag[data-title-tier="4"] .title-ornament,
.hero-title-tag[data-title-tier="5"] .title-ornament { width: 38px; height: 28px; }
.hero-title-tag[data-title-tier="4"] .hero-title-name,
.hero-title-tag[data-title-tier="5"] .hero-title-name { border-block: 1px solid color-mix(in srgb, var(--title-color) 55%, transparent); padding-block: 4px; }
.hero-title-tag[data-title-tier="5"] .hero-title-name {
  text-shadow: 0 0 10px var(--title-glow), 0 0 22px var(--title-glow);
  letter-spacing: .02em;
}
.hero-title-tag[data-title-tier="4"] .hero-title-name { text-shadow: 0 0 8px var(--title-glow); }

/* Tier 5 gets a radiant plaque; tier 4 a restrained rimmed one. */
.hero-title-tag[data-title-tier="5"][data-title-labelled],
.hero-title-tag[data-title-tier="5"] .hero-title-ribbon { position: relative; }
.hero-title-tag[data-title-tier="5"] .hero-title-ribbon::before {
  content: "";
  position: absolute;
  inset: -14px -22px;
  border-radius: 999px;
  background: radial-gradient(closest-side, var(--title-glow), transparent 78%);
  pointer-events: none;
}
.hero-title-tag[data-title-labelled] { padding: 16px 10px; font-size: clamp(26px,2.6vw,36px); background: var(--slate); border-block: 1px solid var(--line-2); position: relative; }
.hero-title-tag[data-title-labelled] .title-ornament { width: 44px; height: 32px; }
.hero-title-tag[data-title-tier="4"][data-title-labelled],
.hero-title-tag[data-title-tier="5"][data-title-labelled] { background: linear-gradient(180deg, color-mix(in srgb, var(--title-color) 12%, var(--slate)), var(--slate)); border-block-color: color-mix(in srgb, var(--title-color) 45%, transparent); }
.hero-title-tag[data-title-tier="5"][data-title-labelled] { box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--title-color) 40%, transparent); }

.rune-card-title { padding: 0 10px 10px; position: relative; z-index: 2; }
.workshop-identity { display: grid; grid-template-columns: minmax(0,1fr) auto; align-items: center; gap: 14px; }
.picker-info .hero-title-tag { font-size: 21px; }

/* Rules: unchanged copy, presented as a readable classroom quest sheet. */
.rules { max-width: 1040px; gap: 30px; padding: clamp(22px,4vw,48px); position: relative; }
.rules::before { content: ""; position: absolute; inset: 10px; border: 1px solid var(--line); border-radius: var(--r-md); pointer-events: none; }
.rules-head { display: grid; grid-template-columns: 64px minmax(0,1fr); align-items: start; gap: 24px; padding-bottom: 28px; border-bottom: 1px solid var(--line-2); }
.rules-head h1 { font-size: clamp(30px,3.4vw,44px); margin-bottom: 12px; }
.rules-emblem { display: grid; place-items: center; width: 64px; height: 76px; color: var(--amber); background: var(--amber-soft); border: 1px solid var(--inlay); border-radius: 3px 3px 30px 30px; }
.rules-emblem .icon { width: 34px; height: 34px; }
.rules-journey .rules-list { display: grid; grid-template-columns: 1fr 1fr; gap: 0 32px; padding: 0; list-style: none; }
.rules-journey li { padding: 14px 0 14px 22px; position: relative; border-bottom: 1px solid var(--line); }
.rules-journey li::before { content: ""; width: 6px; height: 6px; border: 1px solid var(--inlay); background: var(--cyan-soft); transform: rotate(45deg); position: absolute; top: 25px; left: 2px; }
.rules-journey li:last-child { grid-column: 1 / -1; }
.rules-rewards { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.rules-rewards .rules-section { padding: 24px; margin: 0; border: 1px solid var(--line-2); border-radius: var(--r-md); background: var(--slate); }
.rules-rewards h2 { display: flex; align-items: center; gap: 10px; font-size: 23px; }
.rule-symbol { display: inline-flex; color: var(--cyan); }
.rule-symbol .icon { width: 25px; height: 25px; }
.rules-money .rule-symbol { color: var(--amber); }
.rules-rewards .rules-money { border-top: 3px solid var(--inlay); }
.rules-rewards .rules-xp { border-top: 3px solid var(--cyan-2); }
.rules-back { text-align: center; padding-top: 2px; }
@media (max-width: 640px) {
  .rules-head { grid-template-columns: 42px minmax(0,1fr); gap: 14px; }
  .rules-emblem { width: 42px; height: 54px; }
  .rules-emblem .icon { width: 26px; height: 26px; }
  .rules-journey .rules-list, .rules-rewards { grid-template-columns: 1fr; }
  .rules-rewards .rules-section { padding: 18px; }
  .picker-info .hero-title-tag { font-size: 17px; }
  .picker-info .title-ornament { width: 18px; }
}
.item-meta { display: flex; flex-wrap: wrap; gap: var(--s2); justify-content: center; }
.rarity-label { color: var(--amber); font-weight: 600; }
.custom-orders ul { list-style: none; margin: 0; padding: 0; }
.custom-orders li { display: flex; flex-direction: column; gap: var(--s1); padding-block: var(--s3); border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.custom-orders time { color: var(--muted); font-size: 12px; }
.console .shop-items { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s2); }
.console .shop-thumb { min-height: 100px; }
.console .shop-thumb .item-art { height: 88px; }

/* Account administration shares the form and table tokens. */
.admin-page { max-width: 1440px; }
.admin-card { min-width: 0; padding: var(--s5); background: var(--panel-solid); border: 1px solid var(--line); border-radius: var(--r-lg); }
.admin-heading { display: flex; justify-content: space-between; align-items: center; gap: var(--s4); margin-bottom: var(--s5); }
.admin-heading h1 { font-size: 32px; }
.admin-heading p { margin-top: var(--s2); }
.admin-table-wrap { overflow-x: auto; }
.admin-table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.admin-table th, .admin-table td { text-align: left; vertical-align: middle; padding: var(--s3); border-bottom: 1px solid var(--line); }
.admin-table th { color: var(--muted); font-weight: 500; }
.admin-table td { overflow-wrap: anywhere; }
.admin-reset { display: flex; gap: var(--s2); align-items: center; min-width: 260px; }
.admin-reset input { width: 150px; }
.admin-reset .btn { flex: none; }
.admin-empty { padding-block: var(--s5); color: var(--ink-2); }

@media (min-width: 1021px) and (max-width: 1480px) {
  .brand-sub { display: none; }
}
@media (min-width: 1021px) and (max-width: 1250px) {
  .topbar .top-end > .ghost span { display: none; }
  .topbar .top-end > .ghost { min-width: 44px; justify-content: center; }
}
@media (max-width: 1020px) {
  .topbar .top-end > .tabs { flex: 1; }
  .topbar [data-action="show-rules"] span, .topbar [data-action="show-admin"] span { display: inline; }
}
@media (min-width: 800px) and (max-width: 1180px) {
  .sheet, .atelier { grid-template-columns: minmax(0, 1fr) minmax(0, 360px); grid-template-rows: auto 1fr; grid-template-areas: "stage heading" "stage info"; }
}
@media (max-width: 800px) {
  .gate-page { grid-template-columns: minmax(0, 1fr); gap: var(--s5); max-width: 540px; min-height: 0; padding-top: var(--s5); }
  .gate-intro h1 { max-width: 20ch; font-size: 32px; }
  .gate-intro .lede { margin-top: var(--s3); font-size: 14px; }
  .gate-heroes { display: none; }
  .admin-table, .admin-table tbody { display: block; }
  .admin-table thead { position: absolute; width: 1px; height: 1px; clip-path: inset(50%); overflow: hidden; }
  .admin-table tr { display: block; padding-block: var(--s4); border-bottom: 1px solid var(--line-2); }
  .admin-table td { display: grid; grid-template-columns: minmax(100px, 0.8fr) minmax(0, 1fr); gap: var(--s3); padding: var(--s2) 0; border: 0; }
  .admin-table td::before { content: attr(data-label); color: var(--muted); }
  .admin-table td:last-child { grid-template-columns: minmax(0, 1fr); }
  .admin-reset { min-width: 0; flex-wrap: wrap; }
  .admin-reset input { flex: 1 1 140px; }
}
@media (max-width: 720px) {
  .page { padding-inline: max(var(--s4), env(safe-area-inset-left)) max(var(--s4), env(safe-area-inset-right)); }
  .gate-card, .rules, .admin-card { padding: var(--s5); }
  .page-heading h1, .rules-head h1 { font-size: 30px; }
  .shop-items { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s3); }
  .sheet-stats { gap: var(--s4); }
  .sheet-stats .stat b { font-size: 18px; }
  .base-character-controls button { min-height: 44px; }
  .dais-lg { height: 260px; }
  .hero-page-heading h1 { font-size: 26px; }
  .sheet-stage .angle-bar, .atelier-stage .angle-bar { gap: var(--s1); }
  .angle-bar button { padding: 6px 9px; font-size: 10px; }
  input, select, textarea, .search input { font-size: 16px; }
}
@media (max-width: 520px) {
  .topbar .top-end { flex-wrap: wrap; justify-content: flex-end; }
  .topbar .top-end > .tabs { flex: 1 0 100%; }
  .topbar-welcome .top-end { flex: 0; }
  .gate-card, .rules, .admin-card { padding: var(--s4); }
  .gate-card h1, .gate-card h2 { font-size: 26px; }
  .shop-hero-summary > strong { font-size: 20px; }
  .shop-item { padding: var(--s2); }
  .shop-thumb { padding: var(--s2); }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}

#language-switcher {
  position: fixed;
  right: max(12px, env(safe-area-inset-right));
  bottom: max(12px, env(safe-area-inset-bottom));
  z-index: 90;
}

body:has(.layout) #language-switcher {
  bottom: max(76px, calc(64px + env(safe-area-inset-bottom)));
}

#lang-toggle {
  display: grid;
  place-items: center;
  min-width: 44px;
  min-height: 44px;
  padding: 0 10px;
  font: 700 12px/1 var(--font-display, system-ui);
  letter-spacing: 0.08em;
  color: var(--ink);
  background: var(--surface-1, var(--panel-solid));
  border: 1px solid var(--line-strong, var(--line-2));
  border-radius: var(--r-md, 8px);
  box-shadow: 0 8px 24px rgba(3, 9, 20, 0.22);
  cursor: pointer;
}

.hearts { display: flex; gap: 3px; }
.hp-heart { display: block; width: 22px; height: 21px; flex: none; }
.xp { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.xp-track { display: block; height: 10px; background: var(--surface-3, var(--slate)); border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.xp-fill { display: block; height: 100%; background: linear-gradient(90deg, var(--xp, var(--cyan)), color-mix(in srgb, var(--xp, var(--cyan)) 65%, white)); border-radius: inherit; }
.xp-label { color: var(--ink-muted, var(--muted)); font-size: 13px; }
.xp-label strong { color: var(--ink); }
.money { display: inline-flex; align-items: center; gap: 4px; width: fit-content; color: var(--money, var(--amber)); font-weight: 700; }
.money .coin { display: block; width: 20px; height: 20px; flex: none; }
.level { display: inline-flex; align-items: baseline; gap: 4px; width: fit-content; padding: 2px 8px; color: var(--rank, var(--cyan)); background: var(--rank-dim, var(--cyan-soft)); border: 1px solid var(--line-2); border-radius: var(--r-sm, 4px); }
.level-word { font-size: 11px; font-weight: 700; letter-spacing: 0.06em; }
.out-badge { position: absolute; inset: auto 12px 12px; padding: 4px 8px; text-align: center; color: #fff; background: var(--hp); border-radius: var(--r-sm, 4px); }

.dialog {
  position: relative;
  max-width: min(880px, calc(100vw - 24px));
  max-height: min(90vh, 90dvh);
  padding: 24px;
  color: var(--ink);
  background: var(--surface-1, var(--panel-solid));
  border: 1px solid var(--line-strong, var(--line-2));
  border-radius: var(--r-lg, 12px);
  box-shadow: 0 18px 44px rgba(3, 9, 20, 0.6);
  overflow: auto;
}

dialog.dialog:not([open]) { display: none; }
.dialog::backdrop { background: rgba(4, 10, 20, 0.78); }
.dialog-add-pupil { width: min(460px, calc(100vw - 32px)); padding: 30px; }
.dialog-add-pupil h2 { padding-right: 32px; }
.dialog-add-pupil form { display: flex; flex-direction: column; gap: 20px; margin-top: 20px; }
.dialog-add-pupil .field-row { align-items: stretch; }
.dialog-add-pupil .field-row .field { flex: 1; min-width: 0; }
.console-head { flex-wrap: wrap; gap: 8px; }
.console-history { display: flex; justify-content: flex-end; margin: 8px 0; }
/* Dressing and Shop share one back control, placed top-left in their header. */
.btn-back { align-self: flex-start; margin: 0 0 var(--s4); padding: 10px 16px; gap: 10px; font-weight: 600; color: var(--cyan); border: 1px solid var(--cyan-2); background: var(--panel); }
.btn-back:hover { background: var(--cyan-soft); border-color: var(--cyan); }
.hero-class-return .btn { color: var(--ink-2); }
.target-actions { justify-content: flex-start; }
.target-actions .btn { background: var(--panel); border: 1px solid var(--line-2); min-height: 40px; padding: 8px 12px; text-decoration: none; }
.target-actions .btn:hover:not(:disabled) { border-color: var(--cyan-2); background: var(--cyan-soft); }
.target-actions .btn.is-active { background: var(--selected); color: var(--on-selected); border-color: var(--selected); }
.rune-card-foot .rune-act { background: transparent; color: var(--cyan-2); }
.rune-card-foot .rune-act:hover { background: var(--cyan-soft); color: var(--ink); }
.rune-card-foot .rune-act:active { background: var(--selected); color: var(--on-selected); }
.picker h1[tabindex="-1"]:focus { outline: none; }
.teacher-console-tab {
  position: fixed; z-index: 31; right: 0; top: max(calc(var(--topbar-h) + 12px), calc(50dvh - 96px));
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; width: 44px; padding: 14px 8px; min-height: 160px;
  border: 1px solid var(--line-2); border-right: 0; border-radius: 10px 0 0 10px;
  background: var(--panel-solid); color: var(--cyan); cursor: pointer;
  box-shadow: -3px 3px 12px rgb(0 0 0 / 10%);
}
.teacher-console-tab span { writing-mode: vertical-rl; font: 600 13px/1.2 var(--font-ui); letter-spacing: .03em; }
.teacher-console-tab:hover { background: var(--cyan-soft); border-color: var(--cyan); }
.teacher-console-tab:focus-visible { outline-offset: -4px; }
.teacher-console-dialog {
  position: fixed; inset: 0 0 0 auto; margin: 0;
  width: min(480px,calc(100vw - 44px)); max-width: none;
  height: 100dvh; max-height: 100dvh; padding: 24px;
  border-radius: 12px 0 0 12px; overflow: hidden; z-index: 45;
}
.teacher-session-status { min-height: 18px; padding-top: 10px; color: var(--muted); font-size: 12px; }
.hero-class-return { margin-top: 12px; padding-top: 16px; border-top: 1px solid var(--line); }
body[data-teacher-panel="open"] .teacher-console-tab { z-index: 46; right: min(480px,calc(100vw - 44px)); }
@media (min-width: 1101px) {
  body[data-teacher-panel="open"] #app { margin-right: 480px; }
  body[data-teacher-panel="open"] #language-switcher { right: 496px; }
}
/* On narrow screens, keep part of the class visible and interactive. */
@media (max-width: 720px) {
  body[data-teacher-panel="open"] #app { padding-bottom: 52dvh; }
  .teacher-console-dialog { inset: auto 0 0 auto; width: 100%; height: 52dvh; max-height: 52dvh; border-radius: 12px 12px 0 0; padding: 16px; }
  body[data-teacher-panel="open"] .teacher-console-tab { right: 0; top: calc(48dvh - 44px); width: auto; min-height: 44px; height: 44px; flex-direction: row; padding: 8px 14px; border-radius: 8px 0 0 0; }
  body[data-teacher-panel="open"] .teacher-console-tab span { writing-mode: horizontal-tb; }
  body[data-teacher-panel="open"] #language-switcher { bottom: calc(52dvh + 56px); }
}
.teacher-console-dialog .console-head { display: grid; grid-template-columns: minmax(0,1fr) auto; align-items: center; padding-right: 40px; }
.teacher-console-dialog .console-head h2 { min-width: 0; font-size: clamp(18px,2vw,22px); }
.teacher-console-content { height: 100%; max-height: none; overflow: auto; padding-right: 6px; }
.teacher-console-dialog details.panel { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 12px; }
.teacher-console-dialog details.panel > summary { padding-block: 10px; }
.teacher-console-dialog details.panel > summary { display: flex; align-items: center; gap: 8px; list-style: none; cursor: pointer; color: var(--ink-2); }
.teacher-console-dialog details.panel > summary::-webkit-details-marker { display: none; }
.teacher-console-dialog details.panel > summary .icon { width: 16px; height: 16px; color: var(--cyan-2); }
.teacher-unlock-dialog { width: min(490px,calc(100vw - 24px)); padding: 20px; }
.teacher-unlock-dialog .gate { margin: 0; padding: 0; }
.teacher-unlock-dialog .gate-card { border: 0; padding: 24px 14px; }
.teacher-target { margin-block: 12px; }

/* One navigation row on every screen; the logo returns to the class roster. */
.topbar:not(.topbar-welcome) { flex-wrap: nowrap; }
.brand-home { display: flex; align-items: center; min-height: 44px; border: 0; background: none; padding: 0; cursor: pointer; }
.topbar:not(.topbar-welcome) .top-end { width: auto; flex: 0 0 auto; flex-wrap: nowrap; margin-left: auto; }
@media (max-width: 720px) {
  .topbar:not(.topbar-welcome) { gap: 4px; padding: 8px; min-height: 64px; }
  .topbar:not(.topbar-welcome) .brand-logo { width: clamp(70px,23vw,100px); height: auto; }
  .topbar:not(.topbar-welcome) > .class-picker { margin-left: auto; }
  .topbar:not(.topbar-welcome) .class-picker-summary { min-height: 40px; padding: 6px 12px; }
  .topbar:not(.topbar-welcome) .top-end { gap: 0; margin-left: 0; }
  .topbar:not(.topbar-welcome) .top-end > .ghost { width: 40px; padding: 8px; }
  .topbar:not(.topbar-welcome) .top-end > .ghost > span { display: none; }
  .topbar:not(.topbar-welcome) .top-end > .ghost[data-action="show-rules"] { width: auto; gap: 4px; }
  .topbar:not(.topbar-welcome) .top-end > .ghost[data-action="show-rules"] > span { display: inline; }
  .topbar:not(.topbar-welcome) .tablet-tools > summary { width: 40px; padding: 8px; }
}
@media (max-width: 359px) {
  .topbar:not(.topbar-welcome) .top-end > .ghost[data-action="show-rules"] { width: 40px; }
  .topbar:not(.topbar-welcome) .top-end > .ghost[data-action="show-rules"] > span { display: none; }
}

.dialog-close {
  position: absolute;
  z-index: 5;
  top: 12px;
  right: 12px;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  color: var(--ink-muted, var(--muted));
  background: var(--surface-2, var(--slate-3));
  border: 1px solid var(--line);
  border-radius: var(--r-sm, 4px);
  cursor: pointer;
}

.dialog-close:hover { color: var(--ink); }
.dialog-hero { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 360px); gap: 24px; align-items: center; padding-top: 8px; }
.dialog-hero-art { position: relative; display: grid; place-items: end center; min-width: 0; min-height: 320px; background: var(--surface-3, var(--slate)); border: 1px solid var(--line); border-radius: var(--r-md, 8px); overflow: hidden; }
.dialog-hero-facts { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.dialog-hero-facts h2 { padding-right: 44px; font-size: 28px; }
.dialog-item { display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; }
.dialog-item h2 { padding-inline: 44px; font-family: var(--font-display); font-size: 22px; }
.dialog-item-art { position: relative; display: grid; place-items: center; width: min(100%, 320px); min-height: 200px; padding: 16px; background: var(--surface-3, var(--slate)); border: 1px solid var(--line); border-radius: var(--r-md, 8px); overflow: hidden; }
.dialog-item-art.is-hero-preview { height: min(52vh, 380px); padding: 8px 16px 0; }
.dialog-item-art.is-hero-preview .avatar { width: 100%; height: 100%; }
.dialog-item-art .item-art { width: min(100%, 180px); height: auto; max-height: 180px; }
.dialog-status, .dialog-item-description { color: var(--ink-2); }
.dialog-item-description { max-width: 48ch; }
.bespoke-order-form { display: flex; flex-direction: column; gap: 12px; width: min(100%, 440px); text-align: left; }
.preview-title { position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%); max-width: calc(100% - 16px); padding: 8px 12px; color: var(--money, var(--amber)); background: var(--surface-1, var(--panel-solid)); border: 1px solid currentColor; border-radius: var(--r-sm, 4px); }

@media (max-width: 720px) {
  .dialog { width: calc(100vw - 16px); padding: 16px; }
  .dialog-hero { grid-template-columns: minmax(0, 1fr); }
  .dialog-hero-art { min-height: 240px; }
}

#toasts { width: max-content; max-width: calc(100vw - 32px); bottom: max(20px, env(safe-area-inset-bottom)); pointer-events: none; }
.toast { overflow-wrap: anywhere; }
.toast-error, .toast-warn { border-color: var(--hp); }
.toast-success { border-color: var(--ok); }
.toast-coin, .toast-levelup { border-color: var(--amber); }
@media (max-width: 1180px) {
  body:has(.layout) #toasts { bottom: calc(76px + env(safe-area-inset-bottom)); }
  .console { overflow: hidden; }
}
