﻿:root {
  --font-ui: "Inter", "Noto Sans JP", -apple-system, BlinkMacSystemFont, sans-serif;
  --font-serif: "Noto Serif JP", "Hiragino Mincho ProN", "Yu Mincho", serif;
  --bg: #F7F9FC;
  --surface: #ffffff;
  --border: #E2E8F0;
  --text: #1E293B;
  --muted: #64748B;
  --primary: #5A90C6;
  --primary-hover: #4A7DB3;
  --secondary: #475569;
  --secondary-hover: #334155;
  --danger: #DC2626;
  --radius: 8px;
  --radius-lg: 10px;
  --radius-xl: 12px;
  --shadow-sm: 0 1px 4px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.10);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.15);
  --transition: all 0.2s ease;
  --pane-divider: #d5dde8;
  --answer-font-size: 17px;
  --answer-line-height: 1.65;
  --answer-line-step: calc(var(--answer-font-size) * var(--answer-line-height));
  --answer-single-max-width: calc(56px + 20px + 54ch);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-ui);
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* Material Symbols sizing */
.material-symbols-outlined {
  font-size: 20px;
  vertical-align: middle;
  font-variation-settings: 'FILL' 0, 'wght' 300, 'GRAD' 0, 'opsz' 24;
}

.btn-icon {
  font-size: 15px;
  margin-right: 3px;
  line-height: 1;
}

.app-shell {
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 4px;
  height: 100vh;
  overflow: hidden;
}

main {
  height: 100%;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 16px;
}

.global-error {
  color: var(--danger);
  font-size: 13px;
}

.viewport-warning {
  margin-bottom: 10px;
  padding: 10px 14px;
  border: 1px solid #f59e0b;
  border-radius: var(--radius);
  background: #fffbeb;
  color: #92400e;
  font-size: 13px;
}

.screen {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
}

#screen-select {
  height: 100%;
  overflow: auto;
  border: none;
  border-radius: 0;
  box-shadow: none;
}

#screen-select .select-content {
  max-width: 640px;
  margin: 0 auto;
  padding: 28px 16px 40px;
}

#screen-select h2 {
  margin-top: 0;
  padding-bottom: 12px;
  border-bottom: 3px solid var(--primary);
  margin-bottom: 24px;
  color: var(--text);
}

/* --- Selection Step Flow --- */

.selection-step {
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background: #fff;
  padding: 0;
  margin-bottom: 18px;
  transition: all 0.3s ease;
  overflow: hidden;
}

.step-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  background: #fafbfd;
}

.step-header-text {
  flex: 1;
}

.step-header-text h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
}

.step-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  background: #e2e8f0;
  color: #64748b;
  font-size: 14px;
  font-weight: 800;
  flex-shrink: 0;
  transition: all 0.3s ease;
}

.step-status {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.4;
}

.step-body {
  padding: 20px 22px;
}

/* Ready state */
.selection-step.is-ready {
  border-color: #93c5fd;
}

.selection-step.is-ready .step-header {
  background: #f0f7ff;
  border-bottom-color: #bfdbfe;
}

.selection-step.is-ready .step-badge {
  background: var(--primary);
  color: #fff;
}

.selection-step.is-ready .step-status {
  color: var(--primary);
  font-weight: 500;
}

/* Locked state */
.selection-step.is-locked {
  border-color: #e8ecf1;
  background: #f8f9fb;
}

.selection-step.is-locked .step-header {
  background: #f4f5f7;
  border-bottom-color: #e8ecf1;
}

.selection-step.is-locked .step-badge {
  background: #e2e8f0;
  color: #a0aec0;
}

.selection-step.is-locked .step-header-text h3 {
  color: #a0aec0;
}

.selection-step.is-locked .step-status {
  color: #b0b8c4;
}

.selection-step.is-locked .step-body {
  opacity: 0.4;
  pointer-events: none;
}

/* --- Select Card Buttons --- */

.select-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}

.select-card-button {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 16px 20px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #fff;
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: left;
}

.select-card-button:hover {
  border-color: var(--primary);
  background: #f8fbff;
  box-shadow: 0 2px 8px rgba(90, 144, 198, 0.12);
}

.select-card-button:active {
  transform: scale(0.99);
}

.select-card-icon {
  font-size: 22px !important;
  color: var(--primary);
}

.select-card-label {
  flex: 1;
}

/* --- Time Input --- */

.time-input-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.time-input {
  width: 120px;
  padding: 12px 16px;
  font-size: 18px;
  font-weight: 600;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  transition: var(--transition);
}

.time-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(90, 144, 198, 0.15);
}

.time-unit {
  font-size: 15px;
  font-weight: 600;
  color: var(--muted);
}

/* --- Start Button --- */

.start-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 18px 32px;
  border: none;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.25s ease;
  letter-spacing: 0.02em;
}

.start-button:hover:not(:disabled) {
  background: var(--primary-hover);
  box-shadow: 0 4px 16px rgba(90, 144, 198, 0.35);
  transform: translateY(-1px);
}

.start-button:active:not(:disabled) {
  transform: translateY(0);
  box-shadow: 0 2px 8px rgba(90, 144, 198, 0.25);
}

.start-button:disabled {
  background: #cbd5e1;
  color: #94a3b8;
  cursor: not-allowed;
  box-shadow: none;
}

.start-button-icon {
  font-size: 24px !important;
}

#screen-exercise {
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  --ui-scale: 1;
  padding: 0;
  border: none;
  box-shadow: none;
  background: var(--bg);
  border-radius: 0;
}

/* --- Buttons --- */

input,
select,
button {
  font: inherit;
}

input,
select {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: var(--transition);
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(90, 144, 198, 0.15);
}

button {
  border: 0;
  border-radius: 6px;
  padding: 5px 10px;
  cursor: pointer;
  font-weight: 500;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 3px;
  white-space: nowrap;
  font-size: 12.5px;
  line-height: 1.4;
}

button:hover {
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
}

button:disabled,
input:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.primary-button {
  background: var(--primary);
  color: #fff;
}

.primary-button:hover {
  background: var(--primary-hover);
}

.secondary-button {
  background: var(--secondary);
  color: #fff;
}

.secondary-button:hover {
  background: var(--secondary-hover);
}

/* Outline button (law prev/next) */
.outline-button {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 3px 6px;
  font-size: 11.5px;
}

.outline-button:hover {
  background: var(--bg);
  color: var(--primary);
  border-color: var(--primary);
}

.outline-button .btn-icon {
  font-size: 14px;
  margin-right: 1px;
}

.field {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 10px;
  align-items: start;
  margin-bottom: 16px;
}

.field label {
  font-weight: 600;
  color: var(--text);
  padding-top: 10px;
}

/* Selection screen doesn't use .field grid */

.summary-card,
.module-status {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 12px;
}

#screen-exercise .module-status {
  display: none;
}

/* --- Top Band --- */

.app-top-band {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 14px;
  background: #fff;
  margin-bottom: 0;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}

#screen-select .app-top-band {
  margin: -24px -24px 0;
}

.brand-wrap {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.brand-wrap strong {
  color: var(--text);
  font-size: 14px;
  letter-spacing: 0.01em;
}

.bexa-logo {
  height: 28px;
  width: auto;
  display: block;
}

.band-end-button {
  background: var(--secondary);
  color: #fff;
  border: none;
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 12.5px;
  font-weight: 500;
}

.band-end-button:hover {
  background: var(--secondary-hover);
}

/* --- Exercise Toolbar --- */

.exercise-toolbar {
  border: none;
  border-radius: 0;
  padding: 5px 8px;
  margin-bottom: 0;
  display: flex;
  align-items: center;
  gap: 5px;
  min-height: 38px;
  overflow: hidden;
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
}

.exercise-toolbar button {
  padding: 5px 10px;
  font-size: 12.5px;
  line-height: 1.3;
  border-radius: 5px;
}

.exercise-toolbar .secondary-button {
  background: #5a6577;
}

.exercise-toolbar .secondary-button:hover {
  background: #475569;
  box-shadow: 0 1px 4px rgba(0,0,0,0.10);
}

.toolbar-actions {
  justify-content: flex-end;
  flex-wrap: nowrap;
  overflow-x: auto;
  scrollbar-width: thin;
  margin-left: auto;
  gap: 5px;
  min-width: 0;
  flex: 0 1 auto;
}

.toolbar-separator {
  width: 1px;
  min-height: 22px;
  background: #d8dee6;
  display: inline-block;
  margin: 0 3px;
}

.secondary-button.is-on {
  background: var(--primary);
}

.secondary-button.is-off {
  background: var(--secondary);
}

/* Problem / Law / Answer toggles: keep OFF and hover clearly distinct */
.exercise-toolbar #toggle-problem.secondary-button.is-off,
.exercise-toolbar #toggle-law.secondary-button.is-off,
.exercise-toolbar #toggle-answer.secondary-button.is-off {
  background: #cbd5e1;
  color: #1f2937;
}

.exercise-toolbar #toggle-problem.secondary-button.is-off:hover,
.exercise-toolbar #toggle-law.secondary-button.is-off:hover,
.exercise-toolbar #toggle-answer.secondary-button.is-off:hover {
  background: #94a3b8;
  color: #111827;
}

.exercise-toolbar #toggle-problem.secondary-button.is-on,
.exercise-toolbar #toggle-law.secondary-button.is-on,
.exercise-toolbar #toggle-answer.secondary-button.is-on {
  background: var(--primary);
  color: #ffffff;
}

.exercise-toolbar #toggle-problem.secondary-button.is-on:hover,
.exercise-toolbar #toggle-law.secondary-button.is-on:hover,
.exercise-toolbar #toggle-answer.secondary-button.is-on:hover {
  background: var(--primary-hover);
  color: #ffffff;
}

.timer-text {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  white-space: nowrap;
  min-width: 160px;
  background: rgba(220, 38, 38, 0.05);
  border: 1px solid rgba(220, 38, 38, 0.10);
  border-radius: 6px;
  color: var(--danger);
  font-size: 12.5px;
  font-weight: 700;
  line-height: 1.2;
}

.timer-text #timer-display {
  display: inline-flex;
  align-items: center;
  font-size: 16px;
  line-height: 1;
  letter-spacing: 0.5px;
  margin-left: 2px;
  font-variant-numeric: tabular-nums;
}

.timer-text .btn-icon {
  color: var(--danger);
}

#toggle-timer {
  width: 96px;
  text-align: center;
  justify-content: center;
}

.current-problem {
  display: block;
  margin-bottom: 0;
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
  min-width: 0;
  max-width: 680px;
  flex: 1 1 340px;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
  padding: 0 4px;
}

#exercise-zoom-target {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* --- Exercise Layout Grid --- */

.exercise-layout {
  --left-col-width: 50%;
  --top-row-height: 50%;
  display: grid;
  grid-template-columns: var(--left-col-width) calc(100% - var(--left-col-width));
  grid-template-rows: var(--top-row-height) calc(100% - var(--top-row-height));
  grid-template-areas:
    "problem law"
    "problem answer";
  gap: 1px;
  height: 100%;
  min-height: 0;
  position: relative;
  background: var(--pane-divider);
}

.pane-resizer {
  position: absolute;
  z-index: 30;
  background: transparent;
  border-radius: 4px;
}

.pane-resizer:hover {
  background: rgba(90, 144, 198, 0.25);
}

.pane-resizer-col {
  top: 0;
  bottom: 0;
  left: var(--left-col-width);
  width: 6px;
  transform: translateX(-3px);
  cursor: col-resize;
}

.pane-resizer-row {
  right: 0;
  width: calc(100% - var(--left-col-width));
  top: var(--top-row-height);
  height: 6px;
  transform: translateY(-3px);
  cursor: row-resize;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.exercise-toolbar .toolbar-actions {
  flex-wrap: nowrap;
}

.selected-list {
  min-height: 48px;
  margin: 0;
  padding: 0;
  list-style: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg);
}

.selected-list:empty {
  display: none;
}

.selected-list li {
  padding: 10px 16px;
  color: var(--text);
  font-size: 13.5px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}

.selected-list li:last-child {
  border-bottom: none;
}

.selected-list li::before {
  content: "check_circle";
  font-family: "Material Symbols Outlined";
  font-size: 18px;
  color: var(--primary);
  font-variation-settings: 'FILL' 1, 'wght' 300, 'GRAD' 0, 'opsz' 24;
}

.selected-list li.empty-item::before {
  content: "radio_button_unchecked";
  color: var(--muted);
  font-variation-settings: 'FILL' 0, 'wght' 300, 'GRAD' 0, 'opsz' 24;
}

.field-error {
  margin: 4px 0 0;
  color: var(--danger);
  font-size: 12px;
}

.input-error {
  border-color: var(--danger);
}

/* --- Modal --- */

.modal {
  width: min(680px, calc(100vw - 24px));
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 0;
  box-shadow: var(--shadow-lg);
}

.modal::backdrop {
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(2px);
}

.modal-inner {
  margin: 0;
  padding: 20px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.modal-header h3 {
  margin: 0;
  color: var(--text);
}

.modal-options {
  max-height: 320px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
  margin-bottom: 12px;
}

.modal-option {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 8px;
  border-radius: 6px;
  cursor: pointer;
  transition: var(--transition);
}

.modal-option:hover {
  background: var(--bg);
}

/* --- Pane --- */

.pane {
  border: none;
  border-radius: 0;
  padding: 0;
  background: #fff;
  min-height: 0;
  overflow: hidden;
}

.problem-pane-inner {
  display: flex;
  gap: 0;
  min-height: 100%;
  height: 100%;
}

.problem-main {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* --- Annotation Palette --- */

.annotation-palette {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 40px;
  padding: 4px 2px;
  align-items: center;
  background: #f8fafc;
  border-radius: 0;
  border: none;
  border-right: 1px solid var(--border);
}

.palette-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 3px;
  background: #fff;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.palette-group + .palette-group {
  margin-top: 3px;
}

.palette-group-zoom {
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: center;
  width: 100%;
}

.palette-divider {
  display: none;
}

.palette-button {
  width: 30px;
  height: 30px;
  border-radius: 6px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: 18px;
  padding: 0;
  line-height: 1;
  display: grid;
  place-items: center;
  transition: var(--transition);
}

.palette-button:hover {
  background: #fff;
  color: var(--primary);
  border-color: var(--border);
  box-shadow: none;
}

.palette-button .material-symbols-outlined {
  font-size: 20px;
}

.palette-button.is-active {
  border-color: var(--primary);
  background: rgba(90, 144, 198, 0.12);
  color: var(--primary);
}

.palette-button.has-tool-color {
  box-shadow: inset 0 -4px 0 var(--tool-color, transparent);
}

.palette-page-indicator {
  width: 30px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  color: var(--muted);
  font-size: 12px;
}

.palette-page-input {
  width: 30px;
  height: 22px;
  padding: 1px 2px;
  border: 1px solid var(--border);
  border-radius: 4px;
  text-align: center;
  font-size: 12px;
  background: #fff;
}

.palette-page-total {
  display: block;
  text-align: center;
}

.palette-page-total::before {
  content: none;
}

#ann-color {
  width: 30px;
  height: 24px;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px;
}

#ann-color[hidden] {
  display: none;
}

.ann-color-presets {
  position: fixed;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: #ffffff;
  box-shadow: var(--shadow-md);
  z-index: 40;
}

.ann-eraser-presets {
  position: fixed;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: #ffffff;
  box-shadow: var(--shadow-md);
  z-index: 40;
}

.ann-color-presets[hidden] {
  display: none;
}

.ann-eraser-presets[hidden] {
  display: none;
}

.ann-color-chip {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  border: 2px solid #ffffff;
  box-shadow: 0 0 0 1px var(--border);
  padding: 0;
  transition: var(--transition);
}

.ann-color-chip.is-active {
  box-shadow: 0 0 0 2px var(--primary);
}

.ann-eraser-chip {
  width: 46px;
  height: 46px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
  display: grid;
  place-items: center;
  padding: 0;
  transition: var(--transition);
}

.ann-eraser-chip.is-active {
  box-shadow: 0 0 0 2px var(--primary);
}

.ann-eraser-size-dot {
  border-radius: 999px;
  background: #374151;
  display: inline-block;
  max-width: 30px;
  max-height: 30px;
}

.ann-sticky-editor {
  position: absolute;
  z-index: 35;
  border: 1px solid rgba(17, 24, 39, 0.45);
  border-radius: 4px;
  padding: 6px 14px 6px 8px;
  box-sizing: border-box;
  margin: 0;
  resize: none;
  outline: none;
  color: #000000;
  font-size: 14px;
  line-height: 21px;
  font-weight: 500;
  background: transparent;
  box-shadow: none;
  overflow: hidden;
  white-space: pre;
}

/* --- Problem / Law / Answer Areas --- */

#area-problem {
  grid-area: problem;
  display: flex;
  flex-direction: column;
}

#area-law {
  grid-area: law;
  display: flex;
  flex-direction: column;
  background: #ffffff;
}

#area-answer {
  grid-area: answer;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  background: #f9fbfe;
}

.exercise-layout.is-answer-only #area-answer {
  justify-self: center;
  width: min(100%, var(--answer-single-max-width));
}

/* --- Memo Pane --- */

.memo-pane {
  margin-top: 10px;
}

.memo-pane.memo-left,
.memo-pane.memo-right {
  width: calc(50% - 4px);
}

.memo-pane.memo-left {
  float: left;
  margin-right: 8px;
}

.memo-pane.memo-right {
  float: right;
  margin-left: 8px;
}

.memo-pane.memo-full {
  width: 100%;
}

.memo-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.memo-text {
  width: 100%;
  min-height: 180px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  resize: vertical;
  transition: var(--transition);
}

.memo-text:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(90, 144, 198, 0.15);
}

/* --- PDF Area --- */

.pdf-toolbar {
  margin-bottom: 8px;
  font-size: 13px;
}

.pdf-page-indicator {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  font-weight: 500;
  color: var(--muted);
}

.pdf-body {
  display: flex;
  gap: 8px;
  flex: 1;
  min-height: 0;
}

.pdf-thumbnails {
  width: 120px;
  overflow-y: auto;
  overflow-x: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px;
  background: var(--bg);
  flex-shrink: 0;
  align-self: stretch;
}

.pdf-thumbnails button {
  width: 100%;
  margin-bottom: 6px;
  background: #fff;
  color: #111827;
  border: 1px solid var(--border);
  border-radius: 4px;
}

.pdf-canvas-wrap {
  flex: 1;
  min-height: 0;
  border: none;
  border-radius: 0;
  overflow: auto;
  background: #eef1f5;
  position: relative;
}

#pdf-scroll-stack {
  padding: 8px;
}

.pdf-page-block {
  width: fit-content;
  margin: 0 auto 14px;
  border: 1px solid #d8dee6;
  background: #ffffff;
  border-radius: 3px;
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

.pdf-page-label {
  padding: 4px 8px;
  font-size: 12px;
  color: var(--muted);
  border-top: 1px solid var(--border);
}

.pdf-page-block canvas {
  display: block;
  user-select: none;
  -webkit-user-select: none;
}

.pdf-page-block.is-active {
  outline: none;
}

#annotation-canvas {
  position: absolute;
  left: 0;
  top: 0;
  transform: none;
  z-index: 10;
  pointer-events: auto;
}

/* --- Law Area --- */

.law-body {
  display: flex;
  gap: 0;
  min-height: 0;
  flex: 1;
}

.law-toolbar {
  margin-bottom: 0;
  display: flex;
  justify-content: space-between;
  gap: 6px;
  align-items: center;
  padding: 6px 10px;
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
}

.law-toolbar-left,
.law-toolbar-right {
  flex-wrap: nowrap;
  align-items: center;
  flex-shrink: 0;
}

.law-toolbar-left {
  flex: 1;
  min-width: 0;
}

.law-toolbar input {
  flex: 1;
  min-width: 80px;
  max-width: 150px;
  padding: 5px 9px;
  font-size: 12.5px;
}

.law-search-hit-status {
  min-width: 48px;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  padding: 0 4px;
  font-variant-numeric: tabular-nums;
}

.law-toc {
  width: 32%;
  border: none;
  border-right: 1px solid var(--border);
  border-radius: 0;
  min-height: 0;
  overflow: auto;
  padding: 4px 0 4px 4px;
  background: #fafbfc;
}

.law-toc-item {
  padding: 8px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  border-radius: 4px;
  transition: var(--transition);
}

.law-toc-group {
  margin-bottom: 2px;
}

.law-toc-group-title {
  font-weight: 700;
  padding: 7px 8px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
}

.law-toc-group-title::after {
  content: "⌄";
  font-size: 13px;
  color: var(--muted);
}

.law-toc-group.is-collapsed .law-toc-group-title::after {
  content: "›";
  font-size: 15px;
}

.law-toc-group.is-collapsed .law-toc-child {
  display: none;
}

.law-toc-child {
  padding: 6px 8px 6px 18px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  border-radius: 4px;
  transition: var(--transition);
  font-size: 12px;
  line-height: 1.4;
}

.law-toc-child:hover {
  background: rgba(90, 144, 198, 0.08);
}

.law-toc-child.is-selected {
  background: rgba(90, 144, 198, 0.12);
  color: var(--primary);
  font-weight: 600;
}

.law-toc-item:hover {
  background: var(--bg);
}

.law-content-wrap {
  flex: 1;
  border: none;
  border-radius: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: #ffffff;
}

.law-tabs {
  display: none;
}

.law-content {
  min-height: 0;
  flex: 1;
  overflow: auto;
  white-space: pre-wrap;
  line-height: 1.6;
  font-size: 13px;
  padding: 8px 12px 8px 8px;
}

.law-article {
  border-bottom: none;
  padding: 6px 4px 6px 2px;
}

.law-article-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}

/* Bookmark icon button */
.law-bookmark-toggle {
  background: none;
  border: none;
  padding: 2px;
  cursor: pointer;
  color: var(--border);
  transition: var(--transition);
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 4px;
  flex-shrink: 0;
}

.law-bookmark-toggle:hover {
  color: var(--primary);
  box-shadow: none;
}

.law-bookmark-toggle.is-bookmarked {
  color: var(--primary);
}

.law-bookmark-toggle .material-symbols-outlined {
  font-size: 22px;
  font-variation-settings: 'FILL' 0, 'wght' 300, 'GRAD' 0, 'opsz' 24;
}

.law-bookmark-toggle.is-bookmarked .material-symbols-outlined {
  font-variation-settings: 'FILL' 1, 'wght' 300, 'GRAD' 0, 'opsz' 24;
}

.bookmark-list {
  margin: 6px 0 0;
  padding-left: 18px;
}

.bookmark-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  align-items: center;
}

.bookmark-row .secondary-button {
  white-space: nowrap;
}

/* --- Answer Area --- */

.answer-editor {
  display: flex;
  align-items: flex-start;
  border: none;
  border-top: 1px solid #d9e1ec;
  border-radius: 0;
  min-height: 0;
  flex: 1;
  overflow-x: auto;
  overflow-y: auto;
  margin-top: 0;
  padding: 0;
  background: #fff;
}

.answer-editor .line-numbers {
  flex: 0 0 56px;
  min-height: calc(184 * var(--answer-line-step));
  overflow: hidden;
}

.answer-editor .answer-text {
  flex: 0 0 calc(30em + 20px);
  width: calc(30em + 20px);
  min-width: calc(30em + 20px);
  max-width: calc(30em + 20px);
  min-height: calc(184 * var(--answer-line-step));
  height: auto;
  overflow: hidden;
}

.answer-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 0;
  flex-wrap: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  white-space: nowrap;
  flex: 0 0 auto;
  border-bottom: 1px solid #d2dae5;
  background: linear-gradient(180deg, #eef3f8 0%, #e5edf6 100%);
  padding: 5px 6px 0;
  box-shadow: inset 0 -1px 0 rgba(255, 255, 255, 0.8);
}

.answer-tab {
  border: 1px solid transparent;
  border-bottom: none;
  background: rgba(255, 255, 255, 0.45);
  color: #4b5f77;
  padding: 7px 14px;
  border-radius: 8px 8px 0 0;
  cursor: pointer;
  font-weight: 500;
  font-size: 12.5px;
  transition: var(--transition);
  position: relative;
  margin-right: 2px;
}

.answer-tab:hover {
  background: rgba(255, 255, 255, 0.8);
  color: var(--text);
  box-shadow: none;
}

.answer-tab.is-active {
  background: #fff;
  color: var(--primary);
  border-color: #c7d2df;
  border-bottom-color: #fff;
  font-weight: 600;
  box-shadow: 0 -1px 0 rgba(255, 255, 255, 0.9);
}

.answer-toolbar {
  align-items: center;
  flex: 0 0 auto;
  gap: 6px;
  padding: 5px 10px;
  background: #eef3f9;
  border-bottom: 1px solid #d3dce8;
}

#answer-count {
  font-size: 11.5px;
  color: var(--muted);
  letter-spacing: 0.01em;
  font-variant-numeric: tabular-nums;
}

.answer-actions {
  display: inline-flex;
  gap: 0;
  margin-left: auto;
}

.answer-actions .secondary-button {
  border-radius: 0;
  padding: 4px 10px;
  font-size: 12px;
}

#answer-search {
  border-radius: var(--radius) 0 0 var(--radius);
}

#answer-replace {
  border-radius: 0 var(--radius) var(--radius) 0;
}

.line-numbers {
  width: 56px;
  background: #f8fafc;
  border-right: 1px solid var(--border);
  border-radius: 0;
  padding: 0 6px;
  text-align: right;
  color: #dc6868;
  font-size: 11.5px;
  user-select: none;
  overflow: hidden;
}

.line-numbers .page-marker {
  display: inline;
  font-size: 12px;
  font-weight: 700;
  color: #DC2626;
  margin-right: 4px;
}

.line-numbers .line-row {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  height: var(--answer-line-step);
  min-height: var(--answer-line-step);
  line-height: var(--answer-line-step);
}

.answer-text {
  flex: 1 1 auto;
  border: 0;
  border-radius: 0;
  padding: 0 10px;
  resize: none;
  outline: none;
  line-height: var(--answer-line-height);
  font-size: var(--answer-font-size);
  font-family: var(--font-serif);
  background-image: linear-gradient(to bottom, transparent calc(var(--answer-line-step) - 1px), #edf0f4 0);
  background-size: 100% var(--answer-line-step);
  background-position: left top;
}

.page-input {
  width: 62px;
}

/* --- Responsive --- */

@media (max-width: 720px) {
  .field {
    grid-template-columns: 1fr;
  }

  .select-card-button {
    padding: 14px 16px;
    font-size: 13px;
  }

  .step-header {
    padding: 14px 16px;
  }

  .step-body {
    padding: 16px;
  }

  .exercise-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
    grid-template-areas:
      "problem"
      "law"
      "answer";
  }

  .pane-resizer {
    display: none;
  }

  .memo-pane.memo-left,
  .memo-pane.memo-right,
  .memo-pane.memo-full {
    width: 100%;
    float: none;
    margin: 10px 0 0;
  }

  .problem-pane-inner {
    flex-direction: column;
  }

  .annotation-palette {
    flex-direction: row;
    width: 100%;
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  .palette-group {
    flex-direction: row;
    gap: 2px;
  }

  .palette-group + .palette-group {
    margin-top: 0;
    margin-left: 2px;
  }

  .palette-page-indicator {
    flex-direction: row;
    width: auto;
    gap: 4px;
  }

  .exercise-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .current-problem {
    max-width: 100%;
  }
}

.module-status h3 {
  margin-top: 0;
}

.module-status ul {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
}

