:root {
  color-scheme: dark;
  --bg: #0b0f17;
  --surface: #131a27;
  --surface-elevated: #1a2334;
  --surface-hover: #212c42;
  --border: #243047;
  --border-strong: #344566;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-soft: rgba(99, 102, 241, 0.16);
  --success: #10b981;
  --success-soft: rgba(16, 185, 129, 0.16);
  --danger: #f43f5e;
  --danger-hover: #e11d48;
  --danger-soft: rgba(244, 63, 94, 0.16);
  --warning: #f59e0b;
  --warning-soft: rgba(245, 158, 11, 0.16);
  --radius: 14px;
  --radius-sm: 10px;
  --font-sans: "Noto Sans JP", "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

body {
  padding-bottom: env(safe-area-inset-bottom);
}

.hidden {
  display: none !important;
}

.app-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.boot-loader {
  margin: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  color: var(--text-muted);
}

.spinner {
  width: 34px;
  height: 34px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Top Navigation */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(11, 15, 23, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1040px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.01em;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--accent-soft);
  border: 1px solid rgba(99, 102, 241, 0.35);
  color: #a5b4fc;
  font-size: 0.95rem;
  font-weight: 700;
}

.user-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.user-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.85rem;
  color: var(--text);
}

.nav-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 2px;
}

.nav-tabs::-webkit-scrollbar {
  display: none;
}

.nav-tab {
  flex: 0 0 auto;
  min-height: 40px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.nav-tab:hover {
  background: var(--surface);
  color: var(--text);
}

.nav-tab.active {
  background: var(--accent-soft);
  border-color: rgba(99, 102, 241, 0.4);
  color: #c7d2fe;
}

/* Main Container */
.main-content {
  width: 100%;
  max-width: 1040px;
  margin: 0 auto;
  padding: 20px 16px 40px;
  flex: 1;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.page-title {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.page-subtitle {
  margin: 4px 0 0;
  color: var(--text-muted);
  font-size: 0.92rem;
}

/* Cards & Surfaces */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

.card-subtle {
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
}

.login-wrapper {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 16px;
}

.login-card {
  width: 100%;
  max-width: 420px;
}

.login-header {
  text-align: center;
  margin-bottom: 22px;
}

.login-header .brand-mark {
  width: 48px;
  height: 48px;
  font-size: 1.2rem;
  margin-bottom: 10px;
}

.login-header h1 {
  margin: 0;
  font-size: 1.5rem;
}

.login-header p {
  margin: 6px 0 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

/* Forms & Inputs (16px minimum prevents mobile iOS zoom) */
.form-stack {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-muted);
}

input[type="text"],
input[type="password"],
select,
textarea {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 1rem;
  line-height: 1.4;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

textarea {
  min-height: 74px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus,
button:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.32);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease, transform 0.08s ease;
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-sm {
  min-height: 36px;
  padding: 6px 12px;
  font-size: 0.85rem;
}

.btn-primary {
  background: var(--accent);
  color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--surface-elevated);
  border-color: var(--border-strong);
  color: var(--text);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--surface-hover);
}

.btn-danger {
  background: var(--danger-soft);
  border-color: rgba(244, 63, 94, 0.4);
  color: #fda4af;
}

.btn-danger:hover:not(:disabled) {
  background: var(--danger);
  color: #ffffff;
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-muted);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface);
  color: var(--text);
}

/* Badges & Alerts */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  border: 1px solid transparent;
  white-space: nowrap;
}

.badge-ja-en {
  background: rgba(56, 189, 248, 0.15);
  border-color: rgba(56, 189, 248, 0.35);
  color: #7dd3fc;
}

.badge-en-ja {
  background: rgba(168, 85, 247, 0.15);
  border-color: rgba(168, 85, 247, 0.35);
  color: #d8b4fe;
}

.badge-admin {
  background: var(--accent-soft);
  border-color: rgba(99, 102, 241, 0.4);
  color: #c7d2fe;
}

.badge-user {
  background: rgba(148, 163, 184, 0.14);
  border-color: rgba(148, 163, 184, 0.3);
  color: #cbd5e1;
}

.badge-success {
  background: var(--success-soft);
  border-color: rgba(16, 185, 129, 0.4);
  color: #6ee7b7;
}

.badge-danger {
  background: var(--danger-soft);
  border-color: rgba(244, 63, 94, 0.4);
  color: #fda4af;
}

.alert {
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
  border: 1px solid transparent;
  margin-bottom: 14px;
}

.alert-error {
  background: var(--danger-soft);
  border-color: rgba(244, 63, 94, 0.4);
  color: #fecdd3;
}

.alert-success {
  background: var(--success-soft);
  border-color: rgba(16, 185, 129, 0.4);
  color: #a7f3d0;
}

.alert-warning {
  background: var(--warning-soft);
  border-color: rgba(245, 158, 11, 0.4);
  color: #fde68a;
}

/* Filter Bar */
.filter-bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.filter-pill {
  min-height: 40px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

.filter-pill.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

/* Quiz Grid */
.quiz-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.quiz-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: left;
  cursor: pointer;
  color: inherit;
  font-family: inherit;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.1s ease;
}

.quiz-card:hover {
  border-color: var(--accent);
  background: var(--surface-elevated);
}

.quiz-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.quiz-card-title {
  margin: 0;
  font-size: 1.08rem;
  font-weight: 700;
  color: var(--text);
}

.quiz-card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.86rem;
  color: var(--text-muted);
}

/* Quiz Runner */
.runner-card {
  max-width: 680px;
  margin: 0 auto;
}

.runner-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.step-dots {
  display: flex;
  gap: 8px;
  margin-bottom: 18px;
}

.step-dot {
  flex: 1;
  height: 8px;
  border-radius: 999px;
  border: none;
  padding: 0;
  background: var(--border);
  cursor: pointer;
  transition: background 0.15s ease;
}

.step-dot.answered {
  background: rgba(99, 102, 241, 0.55);
}

.step-dot.current {
  background: var(--accent);
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.3);
}

.prompt-box {
  padding: 20px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 18px;
  text-align: center;
}

.prompt-text {
  margin: 0;
  font-size: 1.55rem;
  font-weight: 700;
  line-height: 1.4;
  word-break: break-word;
}

.prompt-reading {
  margin: 8px 0 0;
  color: var(--text-muted);
  font-size: 1rem;
}

.choice-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 20px;
}

.choice-btn {
  width: 100%;
  min-height: 56px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  background: var(--surface-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 1.04rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.choice-btn:hover {
  background: var(--surface-hover);
}

.choice-btn.selected {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: #ffffff;
}

.choice-key {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-muted);
}

.choice-btn.selected .choice-key {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.runner-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

/* Review Summary */
.score-banner {
  text-align: center;
  padding: 20px;
  border-radius: var(--radius-sm);
  background: var(--surface-elevated);
  border: 1px solid var(--border-strong);
  margin-bottom: 18px;
}

.score-value {
  font-size: 2.2rem;
  font-weight: 800;
  margin: 0;
}

.review-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 20px;
}

.review-item {
  padding: 14px;
  border-radius: var(--radius-sm);
  background: var(--bg);
  border: 1px solid var(--border);
}

.review-item.correct {
  border-color: rgba(16, 185, 129, 0.45);
}

.review-item.incorrect {
  border-color: rgba(244, 63, 94, 0.45);
}

.review-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.review-answers {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.94rem;
  margin-top: 8px;
}

.review-explanation {
  margin: 10px 0 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--surface);
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* Capacity Bar */
.capacity-card {
  margin-bottom: 16px;
}

.capacity-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  font-weight: 600;
}

.progress-track {
  width: 100%;
  height: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  transition: width 0.25s ease;
}

.progress-fill.full {
  background: var(--danger);
}

/* Lists & Tables */
.item-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.item-row {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.item-row-main {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.item-row-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* Admin Quiz Editor */
.question-editor {
  padding: 16px;
  border-radius: var(--radius-sm);
  background: var(--surface-elevated);
  border: 1px solid var(--border-strong);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.question-editor-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  color: #c7d2fe;
}

.choice-edit-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.choice-edit-row input[type="radio"] {
  width: 22px;
  height: 22px;
  accent-color: var(--accent);
  flex: 0 0 auto;
  cursor: pointer;
}

.split-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

/* Modal Dialog */
.modal-dialog {
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  width: min(440px, calc(100vw - 32px));
  box-shadow: var(--shadow);
}

.modal-dialog::backdrop {
  background: rgba(2, 6, 14, 0.78);
  backdrop-filter: blur(4px);
}

.modal-card {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-title {
  margin: 0;
  font-size: 1.15rem;
}

.modal-body {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 6px;
}

.muted {
  color: var(--text-muted);
}

.empty-state {
  text-align: center;
  padding: 32px 16px;
  color: var(--text-muted);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
}

@media (min-width: 720px) {
  .topbar-inner {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }

  .quiz-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .item-row {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }

  .split-grid {
    grid-template-columns: 1.35fr 1fr;
    align-items: start;
  }
}

@media (min-width: 980px) {
  .quiz-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
