:root {
  color-scheme: dark;
  --bg: #061326;
  --bg-raised: #0b213d;
  --panel: #0e2949;
  --panel-soft: #123354;
  --text: #f7fbff;
  --muted: #b9cee1;
  --line: #315472;
  --cyan: #50ddff;
  --cyan-dark: #043e58;
  --green: #64e5a5;
  --orange: #ffc267;
  --red: #ff858c;
  --shadow: 0 18px 60px rgb(0 0 0 / 28%);
  --radius: 20px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--bg); }
body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  min-height: 100dvh;
  background:
    radial-gradient(circle at 92% -5%, rgb(37 138 203 / 28%), transparent 34rem),
    radial-gradient(circle at -20% 40%, rgb(61 212 255 / 12%), transparent 28rem),
    var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; }
button, select, input[type="file"] { touch-action: manipulation; }
button { color: inherit; }
a { color: var(--cyan); }
img { max-width: 100%; height: auto; }
[hidden] { display: none !important; }

.skip-link { position: fixed; left: 12px; top: -80px; z-index: 100; padding: 12px 16px; background: white; color: #001528; border-radius: 10px; }
.skip-link:focus { top: 12px; }
.app-shell { width: min(100%, 760px); margin: 0 auto; padding: max(20px, env(safe-area-inset-top)) 16px calc(104px + env(safe-area-inset-bottom)); }
.loading-screen { min-height: 70vh; display: grid; place-content: center; justify-items: center; color: var(--muted); }
.brand-mark { width: 76px; height: 76px; display: grid; place-content: center; border: 2px solid var(--cyan); border-radius: 24px; color: var(--cyan); font-size: 40px; font-weight: 900; box-shadow: 0 0 40px rgb(80 221 255 / 24%); }
.eyebrow { margin: 0 0 5px; color: var(--cyan); font-size: .76rem; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
h1, h2, h3 { margin: 0; line-height: 1.15; text-wrap: balance; }
h1 { font-size: clamp(1.7rem, 7vw, 2.6rem); }
h2 { font-size: clamp(1.35rem, 5vw, 1.9rem); }
h3 { font-size: 1.08rem; }
p { margin: .65rem 0; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.screen-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin: 4px 0 24px; }
.header-actions { flex: none; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.team-chip { flex: none; min-height: 44px; padding: 10px 13px; border: 1px solid color-mix(in srgb, var(--team-color, var(--cyan)) 70%, white); border-radius: 999px; background: color-mix(in srgb, var(--team-color, var(--cyan)) 18%, var(--panel)); font-size: .78rem; font-weight: 900; letter-spacing: .06em; }
.site-switch { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; padding: 9px 13px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel); color: var(--text); font-size: .78rem; font-weight: 850; text-decoration: none; white-space: nowrap; }

.panel, .mission-card, .notice {
  background: linear-gradient(145deg, rgb(15 44 76 / 96%), rgb(9 31 57 / 96%));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.panel { padding: 20px; margin: 0 0 16px; }
.notice { padding: 16px; margin-bottom: 16px; border-left: 4px solid var(--cyan); }
.notice.warning { border-left-color: var(--orange); }
.notice.danger { border-left-color: var(--red); }
.notice.success { border-left-color: var(--green); }
.progress-wrap { margin: 22px 0; }
.progress-meta { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 9px; font-weight: 800; }
.progress-bar { height: 14px; overflow: hidden; border: 1px solid #3b617e; border-radius: 999px; background: #041426; }
.progress-bar > span { display: block; height: 100%; min-width: 0; border-radius: inherit; background: linear-gradient(90deg, #23bce8, #73f0d1); transition: width .35s ease; }
.stats-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; }
.stat { min-width: 0; padding: 10px 5px; border-radius: 13px; background: rgb(5 21 40 / 55%); text-align: center; }
.stat strong { display: block; font-size: 1.15rem; }
.stat span { display: block; color: var(--muted); font-size: .7rem; }

.mission-list { display: grid; gap: 13px; }
.mission-card { position: relative; display: grid; grid-template-columns: 48px minmax(0, 1fr); gap: 14px; width: 100%; padding: 17px; text-align: left; cursor: pointer; }
.mission-card:disabled { cursor: default; opacity: .72; }
.mission-card:not(:disabled):active { transform: translateY(1px); }
.mission-number { width: 48px; height: 48px; display: grid; place-content: center; border-radius: 15px; background: var(--cyan-dark); color: var(--cyan); font-weight: 900; }
.mission-card h3 { margin-top: 2px; }
.mission-card p { margin: 5px 0 0; }
.teacher-team-card { color: var(--text); text-decoration: none; }
.status { display: inline-flex; align-items: center; gap: 6px; margin-top: 8px; color: var(--muted); font-size: .82rem; font-weight: 750; }
.status::before { content: ''; width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.status-available { color: var(--cyan); }.status-available::before { background: var(--cyan); box-shadow: 0 0 14px var(--cyan); }
.status-submitted { color: var(--orange); }.status-submitted::before { background: var(--orange); }
.status-validated { color: var(--green); }.status-validated::before { background: var(--green); }
.status-refused { color: var(--red); }.status-refused::before { background: var(--red); }

.primary-button, .secondary-button, .danger-button, .ghost-button, .file-button {
  width: 100%; min-height: 50px; display: inline-flex; align-items: center; justify-content: center; gap: 9px;
  border: 1px solid transparent; border-radius: 15px; padding: 12px 17px; font-weight: 850; text-decoration: none; cursor: pointer;
}
.primary-button { background: linear-gradient(135deg, #51ddff, #74eeca); color: #001a27; box-shadow: 0 12px 28px rgb(55 211 242 / 22%); }
.secondary-button { background: var(--panel-soft); border-color: #49708e; color: var(--text); }
.ghost-button { width: auto; min-height: 44px; background: transparent; border-color: var(--line); color: var(--muted); }
.danger-button { background: #512132; border-color: #9b475c; }
.primary-button:disabled, .secondary-button:disabled, .danger-button:disabled { cursor: wait; opacity: .58; }
.button-row { display: flex; gap: 10px; flex-wrap: wrap; }
.button-row > * { flex: 1 1 150px; }
.icon-button { width: 46px; height: 46px; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); font-size: 1.2rem; cursor: pointer; }

.form-grid { display: grid; gap: 16px; }
.field { display: grid; gap: 7px; }
.field > span, label > span { color: #e9f5ff; font-weight: 750; }
input, select, textarea {
  width: 100%; min-height: 50px; padding: 12px 14px; border: 1px solid #4a6e89; border-radius: 13px;
  background: #061a31; color: var(--text); outline: none;
}
textarea { min-height: 120px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible { outline: 3px solid rgb(80 221 255 / 45%); outline-offset: 2px; }
input::placeholder, textarea::placeholder { color: #8aa8c0; opacity: 1; }
.input-row { display: grid; grid-template-columns: minmax(0, 1fr) 104px; gap: 10px; }
.help { color: var(--muted); font-size: .82rem; }
.error-message { color: #ffd1d4; font-weight: 700; }
.success-message { color: #baffd8; font-weight: 700; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--muted); margin: 22px 0; font-size: .8rem; }
.divider::before, .divider::after { content: ''; height: 1px; background: var(--line); flex: 1; }
.file-button { position: relative; background: var(--panel-soft); border-color: #4d7898; overflow: hidden; }
.file-button input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.photo-preview { position: relative; min-height: 180px; overflow: hidden; border: 1px dashed #4d7898; border-radius: 16px; background: #05172b; display: grid; place-content: center; color: var(--muted); }
.photo-preview img { width: 100%; max-height: 390px; object-fit: contain; }
.mission-image { width: 100%; max-height: 430px; margin: 16px 0; border-radius: 17px; object-fit: cover; border: 1px solid var(--line); }
.mission-copy { white-space: pre-wrap; font-size: 1.08rem; }
details.hint { margin: 14px 0; border: 1px solid var(--line); border-radius: 14px; background: rgb(4 20 38 / 50%); }
details.hint summary { min-height: 48px; display: flex; align-items: center; padding: 11px 14px; cursor: pointer; font-weight: 800; }
details.hint p { padding: 0 14px 14px; }
.choice-list { display: grid; gap: 10px; }
.choice-item { display: grid; grid-template-columns: 24px 1fr; gap: 10px; align-items: center; min-height: 50px; padding: 12px; border: 1px solid var(--line); border-radius: 13px; }
.choice-item input { width: 21px; min-height: 21px; margin: 0; }
.recovery-code { padding: 17px; border: 1px dashed var(--cyan); border-radius: 16px; background: #041b30; color: var(--cyan); font: 900 clamp(1.45rem, 8vw, 2.3rem) ui-monospace, monospace; text-align: center; letter-spacing: .15em; }

.bottom-nav {
  position: fixed; z-index: 30; left: 50%; bottom: 0; transform: translateX(-50%); width: min(100%, 760px);
  display: grid; grid-template-columns: repeat(5, 1fr); padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  border: 1px solid #294c6a; border-bottom: 0; border-radius: 22px 22px 0 0; background: rgb(5 20 38 / 94%); backdrop-filter: blur(16px); box-shadow: 0 -12px 35px rgb(0 0 0 / 28%);
}
.bottom-nav button { min-height: 56px; display: grid; place-content: center; gap: 1px; border: 0; border-radius: 13px; background: transparent; color: var(--muted); font-size: .69rem; font-weight: 750; cursor: pointer; }
.bottom-nav button span:first-child { font-size: 1.2rem; }
.bottom-nav button.active { background: #103657; color: var(--cyan); }
.bottom-nav button[data-view="emergency"] { color: #ffb6ad; }
.bottom-nav button[data-view="emergency"].active { background: #55231f; color: #fff; }
.emergency-panel { display: grid; gap: 14px; text-align: center; }
.emergency-symbol { width: 76px; height: 76px; margin: 0 auto; display: grid; place-content: center; border-radius: 50%; background: #55231f; color: #fff; font-size: 2.2rem; }
.emergency-number { margin: 0; color: #fff; font-size: clamp(1.7rem, 9vw, 2.5rem); font-weight: 900; letter-spacing: .04em; }
.network-status { position: fixed; z-index: 90; top: max(8px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); width: calc(100% - 28px); max-width: 520px; padding: 12px 15px; border: 1px solid #c78938; border-radius: 13px; background: #392814; color: #fff1d1; text-align: center; box-shadow: var(--shadow); }
.final-success { text-align: center; overflow: hidden; }
.final-symbol { margin: 10px auto 18px; width: 98px; height: 98px; display: grid; place-content: center; border: 3px solid var(--green); border-radius: 50%; color: var(--green); font-size: 3rem; box-shadow: 0 0 0 15px rgb(100 229 165 / 8%), 0 0 48px rgb(100 229 165 / 24%); animation: success 700ms ease-out; }
@keyframes success { from { transform: scale(.45) rotate(-20deg); opacity: 0; } }

/* Administration */
.admin-body { background: #061326; }
.admin-shell { width: min(100%, 1180px); margin: 0 auto; padding: 24px 18px 70px; }
.admin-topbar { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 24px; }
.admin-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.game-status-panel { display: flex; align-items: center; justify-content: space-between; gap: 18px; border-color: #3b6688; }
.game-status-panel h2 { margin: 4px 0; }
.staff-summary { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin: 8px 0 0; color: var(--muted); font-size: .86rem; }
.access-badge { display: inline-flex; align-items: center; min-height: 28px; padding: 4px 9px; border: 1px solid #3f718e; border-radius: 999px; background: #0b2c49; color: var(--cyan); font-size: .72rem; font-weight: 850; }
.access-badge[data-access="viewer"] { border-color: #9a7437; background: #3b2c16; color: #ffe1a8; }
.readonly-notice { border-left-color: var(--orange); }
.readonly-value { margin-top: 12px; padding: 11px 12px; border: 1px solid var(--line); border-radius: 12px; background: #071a2e; overflow-wrap: anywhere; }
.admin-form :disabled { opacity: .78; cursor: not-allowed; }
.admin-nav { display: flex; gap: 7px; overflow-x: auto; padding: 4px 0 14px; scrollbar-width: thin; }
.admin-nav button { flex: none; min-height: 44px; padding: 9px 15px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel); cursor: pointer; }
.admin-nav button.active { color: #001823; background: var(--cyan); border-color: var(--cyan); }
.admin-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 245px), 1fr)); gap: 14px; }
.admin-card { min-width: 0; padding: 18px; border: 1px solid var(--line); border-radius: 17px; background: var(--panel); }
.admin-card .big { font-size: 2rem; font-weight: 900; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; margin: 16px 0; }
.toolbar > * { flex: 1 1 160px; }
.submission-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 310px), 1fr)); gap: 16px; }
.submission-card { padding: 16px; border: 1px solid var(--line); border-radius: 17px; background: var(--panel); }
.submission-card img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 13px; background: #041323; }
.answer-box { min-height: 48px; padding: 11px; border-radius: 11px; background: #05192e; white-space: pre-wrap; overflow-wrap: anywhere; }
.badge { display: inline-flex; padding: 4px 9px; border-radius: 999px; background: #173e5e; font-size: .75rem; font-weight: 800; }
.badge.draft { background: #49351c; color: #ffe4ae; }
.badge.active { background: #154632; color: #baffe0; }
.mission-admin-row { display: grid; grid-template-columns: 62px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 14px 0; border-bottom: 1px solid var(--line); }
.mission-admin-row:last-child { border: 0; }
.mission-admin-row .ghost-button { padding-inline: 13px; }
.admin-form { display: grid; gap: 15px; }
.admin-two-col { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.check-row { min-height: 44px; display: flex; align-items: center; gap: 10px; }
.check-row input { width: 22px; min-height: 22px; }
.variant-panel { border: 1px solid var(--line); border-radius: 14px; padding: 12px; }
.variant-panel summary { min-height: 44px; cursor: pointer; font-weight: 800; }
.login-card { width: min(100%, 440px); margin: 12vh auto 0; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 640px; }
th, td { padding: 11px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; }

@media (max-width: 520px) {
  .app-shell { padding-inline: 13px; }
  .panel { padding: 17px; }
  .screen-header { align-items: flex-start; }
  .header-actions { max-width: 48%; }
  .header-actions .team-chip { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .site-switch { width: 100%; padding-inline: 10px; }
  .input-row, .admin-two-col { grid-template-columns: 1fr; }
  .mission-admin-row { grid-template-columns: 48px minmax(0, 1fr); }
  .mission-admin-row > :last-child { grid-column: 1 / -1; width: 100%; }
  .admin-topbar { align-items: flex-start; flex-wrap: wrap; }
  .admin-actions { width: 100%; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .admin-actions .ghost-button { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

@media (prefers-contrast: more) {
  :root { --muted: #e2eff9; --line: #7194ad; }
}
