:root {
  --bg: #f6f4ef;
  --card: #ffffff;
  --cream: #faf8f4;
  --navy: #1b2540;
  --navy-2: #263356;
  --brand: #c8323c;
  --brand-dark: #a82630;
  --ink: #1b2540;
  --text: #2a3350;
  --muted: #6b7288;
  --border: #e3e6ee;
  --primary: #2f5fd0;
  --primary-dark: #2449ac;
  --primary-soft: #eaf0ff;
  --ok: #059669;
  --ok-soft: #d1fae5;
  --warn: #d97706;
  --warn-soft: #fef3c7;
  --danger: #c8323c;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(27, 37, 64, 0.04), 0 8px 24px rgba(27, 37, 64, 0.07);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: "Inter", "Noto Sans JP", system-ui, -apple-system, "Segoe UI", sans-serif;
  background:
    radial-gradient(900px 400px at 90% -10%, #e6e9f7 0%, transparent 60%),
    radial-gradient(700px 360px at -10% 0%, #fbe4e6 0%, transparent 55%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.hidden { display: none !important; }
.small { font-size: 0.85rem; }
.muted { color: var(--muted); }

h1, h2, h3 { color: var(--ink); line-height: 1.25; margin: 0; }
h2 { font-size: 1.35rem; margin-bottom: 8px; }
h3 { font-size: 1rem; margin-bottom: 12px; }

/* ===== Header ===== */
.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--navy);
  color: #fff;
  box-shadow: 0 2px 10px rgba(27, 37, 64, 0.25);
}
.header-inner {
  max-width: 1500px;
  margin: 0 auto;
  padding: 10px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.brand { display: flex; align-items: center; gap: 18px; min-width: 0; }
.logo-pill {
  background: var(--cream);
  border-radius: 12px;
  padding: 6px 14px;
  display: flex;
  align-items: center;
  flex: none;
}
.logo-svg { height: 46px; width: auto; display: block; }

.cand { display: flex; flex-direction: column; line-height: 1.25; padding-left: 18px; border-left: 1px solid rgba(255, 255, 255, 0.2); min-width: 0; }
.cand-label { font-size: 0.72rem; color: #b6bdd4; }
.cand-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 260px; }

.exam-status { display: flex; gap: 10px; align-items: center; flex: none; }
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.9rem;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.2);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.pill-timer { font-size: 0.95rem; }
.pill-timer .timer-label { font-weight: 500; color: #cdd3e6; }
.pill-timer.warn { background: var(--warn); border-color: var(--warn); }
.pill-timer.low { background: var(--brand); border-color: var(--brand); animation: pulse 1s infinite; }
.pill.has-flags { background: var(--warn-soft); border-color: #fcd34d; color: #92400e; }
.pill.many-flags { background: #fee2e2; border-color: #fca5a5; color: #991b1b; }
@keyframes pulse { 50% { opacity: 0.75; } }

/* ===== Exam toolbar (section dropdown, question tabs) ===== */
.toolbar { background: #fff; color: var(--ink); border-bottom: 1px solid var(--border); }
.toolbar-inner {
  max-width: 1500px;
  margin: 0 auto;
  padding: 10px 24px 6px;
  display: grid;
  grid-template-columns: minmax(280px, 430px) 1fr auto auto;
  align-items: center;
  gap: 14px;
}
.select-wrap { position: relative; }
.select-wrap select {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  font: inherit;
  font-weight: 600;
  color: var(--ink);
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%231b2540' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 14px center;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 11px 38px 11px 14px;
  cursor: pointer;
}
.select-wrap select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px rgba(47, 95, 208, 0.12); }

.tabs-wrap { display: flex; align-items: center; justify-content: center; gap: 6px; min-width: 0; }
.chev {
  width: 32px;
  height: 40px;
  border: 0;
  background: transparent;
  font-size: 1.6rem;
  line-height: 1;
  color: var(--ink);
  cursor: pointer;
  border-radius: 8px;
}
.chev:hover:not(:disabled) { background: #f1f3f8; }
.chev:disabled { color: #c3c8d6; cursor: not-allowed; }
.tabs { position: relative; display: flex; gap: 2px; overflow-x: auto; max-width: 560px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: none;
  min-width: 54px;
  height: 46px;
  border: 0;
  background: #f4f5f9;
  font: inherit;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  position: relative;
  border-bottom: 3px solid transparent;
}
.tab:hover { background: #eceff7; }
.tab.answered { color: var(--primary); background: var(--primary-soft); }
.tab.marked { color: #b45309; background: var(--warn-soft); }
.tab.marked::after { content: ""; position: absolute; top: 6px; right: 7px; width: 7px; height: 7px; border-radius: 50%; background: var(--warn); }
.tab.current { border-bottom-color: var(--brand); color: var(--ink); background: #fff; box-shadow: inset 0 0 0 1px var(--border); }

.icon-btn {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 1.5px solid var(--border);
  background: #fff;
  border-radius: 10px;
  color: var(--ink);
  cursor: pointer;
}
.icon-btn:hover { background: #f4f5f9; }

.attempt-row { display: flex; justify-content: center; padding-bottom: 6px; }
.attempt-pill { font-size: 0.78rem; font-weight: 600; color: var(--muted); background: #f4f5f9; border: 1px solid var(--border); padding: 2px 14px; border-radius: 999px; }

/* ===== Page container ===== */
.container { width: 100%; max-width: 1100px; margin: 0 auto; padding: 28px 20px 40px; flex: 1; }
body.in-exam .container { max-width: 1500px; padding: 0 24px 24px; }
.app-footer { text-align: center; font-size: 0.8rem; color: var(--muted); padding: 14px; }

/* ===== Cards ===== */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 18px; }
.card-narrow { max-width: 640px; margin: 0 auto; }

/* ===== Hero ===== */
.hero {
  background: linear-gradient(135deg, #141c33 0%, #1b2540 55%, #2d3a63 100%);
  color: #fff;
  border-radius: 22px;
  padding: 40px 32px;
  margin-bottom: 18px;
  position: relative;
  overflow: hidden;
  box-shadow: 0 18px 40px rgba(27, 37, 64, 0.25);
}
.hero::after {
  content: "";
  position: absolute;
  right: -60px;
  top: -60px;
  width: 260px;
  height: 260px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(200, 50, 60, 0.95), rgba(200, 50, 60, 0) 68%);
  opacity: 0.6;
}
.hero h1 { color: #fff; font-size: clamp(1.6rem, 4vw, 2.4rem); font-weight: 800; letter-spacing: -0.02em; margin: 10px 0 8px; position: relative; z-index: 1; }
.hero-tag {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: rgba(255, 255, 255, 0.14);
  padding: 5px 12px;
  border-radius: 999px;
  position: relative;
  z-index: 1;
}
.hero-sub { color: #cbd2e6; margin: 0 0 24px; max-width: 520px; position: relative; z-index: 1; }
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; position: relative; z-index: 1; }
.tile { background: rgba(255, 255, 255, 0.1); border: 1px solid rgba(255, 255, 255, 0.14); border-radius: 14px; padding: 14px; }
.tile-num { font-size: 1.7rem; font-weight: 800; }
.tile-label { font-size: 0.78rem; color: #cbd2e6; }

.rules { margin: 12px 0 18px; padding-left: 20px; }
.rules li { margin-bottom: 8px; }

.check { display: flex; gap: 12px; align-items: flex-start; padding: 14px; background: var(--primary-soft); border-radius: 12px; margin-bottom: 18px; cursor: pointer; }
.check input { width: 18px; height: 18px; margin-top: 3px; accent-color: var(--primary); flex: none; }

.notice { display: flex; justify-content: space-between; align-items: center; gap: 14px; padding: 14px 18px; border-radius: 12px; margin-bottom: 18px; }
.notice-warn { background: var(--warn-soft); border: 1px solid #fcd34d; color: #78350f; }

/* ===== Buttons ===== */
.btn {
  font: inherit;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 11px 20px;
  cursor: pointer;
  transition: transform 0.08s, background 0.15s, box-shadow 0.15s, opacity 0.15s;
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-lg { padding: 14px 26px; font-size: 1rem; }
.btn-sm { padding: 9px 18px; font-size: 0.9rem; }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 6px 14px rgba(47, 95, 208, 0.25); }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-secondary { background: var(--primary-soft); color: var(--primary-dark); border-color: #c4d4fb; }
.btn-ghost { background: #fff; color: var(--ink); border-color: var(--border); }
.btn-ghost:hover:not(:disabled) { background: #f6f7fb; }
.btn-danger { background: var(--brand); color: #fff; }
.btn-danger:hover { background: var(--brand-dark); }
.btn-finish { background: var(--brand); color: #fff; padding: 9px 20px; box-shadow: 0 4px 12px rgba(200, 50, 60, 0.35); }
.btn-finish:hover { background: var(--brand-dark); }

.row-actions { display: flex; gap: 12px; justify-content: space-between; align-items: center; margin-top: 18px; flex-wrap: wrap; }
.row-actions.center { justify-content: center; }

/* ===== Form ===== */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.field { display: block; margin: 14px 0 0; font-weight: 600; font-size: 0.9rem; color: var(--ink); }
.field input, .field select {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 12px 14px;
  font: inherit;
  font-weight: 400;
  background: #fff;
  border: 1.5px solid var(--border);
  border-radius: 10px;
}
.field input:focus, .field select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px rgba(47, 95, 208, 0.12); }
.error { color: var(--danger); min-height: 1.4em; margin: 12px 0 8px; font-size: 0.9rem; font-weight: 500; }

/* ===== System check ===== */
.check-grid { display: grid; grid-template-columns: 1.1fr 1fr; gap: 24px; margin-top: 16px; align-items: start; }
.cam-video {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  background: #0b1020;
  border-radius: 12px;
  transform: scaleX(-1);
}
.cam-note { font-size: 0.82rem; color: var(--muted); margin-top: 8px; }
.checklist { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.ci { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid var(--border); border-radius: 12px; background: #fff; flex-wrap: wrap; }
.ci .dot { width: 12px; height: 12px; border-radius: 50%; background: #cbd2e0; flex: none; }
.ci.ok { background: #f0fdf4; border-color: #bbf7d0; }
.ci.ok .dot { background: var(--ok); }
.ci.fail { background: #fef2f2; border-color: #fecaca; }
.ci.fail .dot { background: var(--danger); }
.ci.pending .dot { background: var(--warn); animation: pulse 1s infinite; }
.ci-text { flex: 1; font-weight: 500; font-size: 0.93rem; }

/* ===== Exam: two panes ===== */
.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: #fff;
  border: 1px solid var(--border);
  border-top: 0;
  border-radius: 0 0 14px 14px;
  box-shadow: var(--shadow);
  min-height: calc(100vh - 230px);
  user-select: none;
  -webkit-user-select: none;
}
.pane { padding: 32px 44px; min-width: 0; }
.pane-left { border-right: 1px solid var(--border); }
.pane-right { padding-right: 84px; }
.pane-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 22px; min-height: 36px; }
.pane-head h2, .pane-head h3 { margin: 0; font-size: 1.2rem; }

.link-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 0;
  background: transparent;
  font: inherit;
  font-weight: 500;
  color: #b45309;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 8px;
}
.link-btn:hover { background: #fff7ed; }
.link-btn.on { background: var(--warn-soft); font-weight: 600; }
.link-muted { color: var(--muted); }
.link-muted:hover { background: #f4f5f9; }

.q-text {
  font-family: "Noto Sans JP", "Inter", sans-serif;
  font-size: 1.3rem;
  font-weight: 500;
  line-height: 1.8;
  margin: 0;
  white-space: pre-line;
  color: var(--ink);
}
.passage {
  font-family: "Noto Sans JP", "Inter", sans-serif;
  font-size: 1.1rem;
  line-height: 2;
  white-space: pre-line;
  background: #f8f9fc;
  border: 1px solid var(--border);
  border-left: 4px solid var(--brand);
  border-radius: 12px;
  padding: 16px 20px;
  margin-bottom: 22px;
}

.audio-box { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 14px 16px; background: #f8f9ff; border: 1.5px dashed #c4d4fb; border-radius: 12px; margin-bottom: 20px; }

.options { display: grid; gap: 14px; }
.option {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  text-align: left;
  font: inherit;
  font-family: "Noto Sans JP", "Inter", sans-serif;
  font-size: 1.05rem;
  padding: 20px 22px;
  background: #fff;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.option:hover { border-color: #9db6ee; background: #fafcff; }
.radio {
  flex: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid #c3c9d8;
  background: #fff;
  display: grid;
  place-items: center;
}
.option.selected { border-color: var(--primary); background: var(--primary-soft); }
.option.selected .radio { border-color: var(--primary); }
.option.selected .radio::after { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--primary); }

.float-next {
  position: fixed;
  right: 20px;
  top: 52%;
  width: 46px;
  height: 46px;
  border: 0;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  font-size: 1.4rem;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(47, 95, 208, 0.35);
  z-index: 20;
}
.float-next:hover { background: var(--primary-dark); }

/* Floating camera */
.cam-float {
  position: fixed;
  right: 20px;
  bottom: 20px;
  width: 180px;
  z-index: 40;
  border-radius: 12px;
  overflow: hidden;
  background: #000;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
  border: 2px solid #fff;
}
.cam-float .cam-video { border-radius: 0; }
.cam-badge {
  position: absolute;
  left: 6px;
  bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(15, 23, 42, 0.8);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
}
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: #22c55e; }
.live-dot.warn { background: #f59e0b; }
.live-dot.bad { background: #ef4444; }

/* Summary */
.summary-body { margin: 12px 0 4px; overflow-x: auto; }
.sum-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; text-align: left; }
.sum-table th, .sum-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); }
.sum-table th { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.sum-table td:not(:first-child), .sum-table th:not(:first-child) { text-align: center; }
.sum-table tr.total td { font-weight: 700; border-bottom: 0; }

/* ===== Result ===== */
.result { text-align: center; }
.result-icon { width: 64px; height: 64px; border-radius: 50%; background: var(--ok-soft); color: var(--ok); display: grid; place-items: center; font-size: 2rem; font-weight: 700; margin: 0 auto 14px; }
.score-box { margin: 20px 0; }
.score-ring {
  width: 150px;
  height: 150px;
  margin: 0 auto 10px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: conic-gradient(var(--primary) var(--pct, 0%), #e8ecf5 0);
  position: relative;
}
.score-ring::before { content: ""; position: absolute; inset: 12px; background: #fff; border-radius: 50%; }
.score-num { position: relative; font-size: 2.4rem; font-weight: 800; color: var(--ink); }
.score-num small { font-size: 1rem; color: var(--muted); font-weight: 600; }
#resultReason { justify-content: center; text-align: center; }

/* ===== Overlays / toasts ===== */
.overlay { position: fixed; inset: 0; z-index: 100; background: rgba(15, 23, 42, 0.78); backdrop-filter: blur(4px); display: grid; place-items: center; padding: 20px; }
.modal { background: #fff; border-radius: 20px; padding: 32px; max-width: 440px; width: 100%; text-align: center; box-shadow: 0 30px 60px rgba(0, 0, 0, 0.3); }
.modal-wide { max-width: 620px; text-align: left; }
.modal-wide h3 { text-align: center; }
.modal p { color: var(--muted); margin: 8px 0 20px; }
.modal-icon { width: 54px; height: 54px; border-radius: 50%; display: grid; place-items: center; margin: 0 auto 14px; font-weight: 800; font-size: 1.6rem; }
.modal-icon.warn { background: var(--warn-soft); color: var(--warn); }

.toasts { position: fixed; top: 140px; left: 50%; transform: translateX(-50%); z-index: 120; display: grid; gap: 10px; width: min(480px, calc(100% - 24px)); pointer-events: none; }
.toast { background: var(--navy); color: #fff; padding: 12px 16px; border-radius: 12px; font-size: 0.92rem; font-weight: 500; box-shadow: 0 12px 28px rgba(0, 0, 0, 0.25); animation: slidein 0.25s ease-out; }
.toast.flag { background: #b91c1c; }
.toast.info { background: var(--warn); }
@keyframes slidein { from { opacity: 0; transform: translateY(-8px); } }

/* ===== Responsive ===== */
@media (max-width: 1000px) {
  .cand { display: none; }
  .toolbar-inner { grid-template-columns: 1fr auto auto; }
  .tabs-wrap { grid-column: 1 / -1; order: 5; }
  .pane { padding: 26px 24px; }
  .pane-right { padding-right: 70px; }
}
@media (max-width: 800px) {
  .split { grid-template-columns: 1fr; min-height: 0; }
  .pane-left { border-right: 0; border-bottom: 1px solid var(--border); }
  .pane-right { padding-right: 24px; }
  .check-grid { grid-template-columns: 1fr; }
  .cam-float { width: 110px; right: 10px; bottom: 10px; }
  .float-next { top: auto; bottom: 140px; right: 12px; }
  .pill-timer .timer-label { display: none; }
}
@media (max-width: 600px) {
  .container { padding: 18px 12px 32px; }
  body.in-exam .container { padding: 0 8px 24px; }
  .card { padding: 22px 16px; }
  .hero { padding: 28px 20px; }
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .grid2 { grid-template-columns: 1fr; }
  .header-inner { padding: 8px 12px; flex-wrap: wrap; row-gap: 8px; }
  .exam-status { width: 100%; justify-content: space-between; }
  .link-btn { white-space: nowrap; padding: 6px 4px; }
  .pane { padding: 22px 16px; }
  .logo-svg { height: 32px; }
  .logo-pill { padding: 5px 10px; }
  .toolbar-inner { padding: 8px 12px 4px; }
  .pill { padding: 6px 10px; font-size: 0.8rem; }
  .btn-finish { padding: 8px 12px; font-size: 0.85rem; }
  .q-text { font-size: 1.15rem; }
  .notice { flex-direction: column; align-items: stretch; }
}
