:root {
  color-scheme: light;
  --ink: #172033;
  --muted: #637083;
  --line: #d8e0ea;
  --paper: #fbfcff;
  --teacher: #246bfe;
  --student-a: #12a46f;
  --student-b: #e26a2c;
  --button: #172033;
  --button-text: #ffffff;
  font-family: "Avenir Next", "Hiragino Sans", "Yu Gothic", "Noto Sans JP", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  background: #eef4f8;
  color: var(--ink);
}

button,
select,
input,
a.big-link {
  min-height: 48px;
  border: 0;
  border-radius: 8px;
  padding: 0 18px;
  font: inherit;
  font-weight: 800;
}

button {
  background: var(--button);
  color: var(--button-text);
  cursor: pointer;
  border: 3px solid transparent;
  box-shadow: 0 3px 0 rgba(23, 32, 51, 0.22);
}

button.quiet {
  background: #dfe8f2;
  color: var(--ink);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

select {
  min-width: 180px;
  border: 2px solid var(--line);
  background: #ffffff;
}

input {
  border: 2px solid var(--line);
  background: #ffffff;
  color: var(--ink);
}

[hidden] {
  display: none !important;
}

.teacher-gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(36, 107, 254, 0.12), rgba(18, 164, 111, 0.12)),
    #eef4f8;
}

.gate-box {
  width: min(420px, 100%);
  display: grid;
  gap: 14px;
  padding: 24px;
  border: 3px solid #172033;
  border-radius: 8px;
  background: #ffffff;
  text-align: center;
}

.gate-icon {
  font-size: 4rem;
  color: #f5b700;
}

.gate-box h1 {
  margin: 0;
}

#teacherLoginError {
  min-height: 24px;
  margin: 0;
  color: #c2410c;
  font-weight: 900;
}

.config-warning {
  margin: 16px;
  padding: 14px 16px;
  border: 2px solid #f59e0b;
  border-radius: 8px;
  background: #fff8df;
}

.home {
  width: min(760px, calc(100% - 32px));
  margin: 8vh auto;
}

.home h1 {
  margin: 0 0 10px;
  font-size: clamp(2.2rem, 6vw, 4.8rem);
}

.home p {
  color: var(--muted);
  font-size: 1.2rem;
}

.home-links {
  display: grid;
  gap: 14px;
  margin-top: 28px;
}

a.big-link {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 76px;
  color: #ffffff;
  text-decoration: none;
  font-size: 1.35rem;
}

.big-link.teacher {
  background: var(--teacher);
}

.big-link.student-a {
  background: var(--student-a);
}

.big-link.student-b {
  background: var(--student-b);
}

.teacher-layout {
  width: min(1440px, calc(100% - 32px));
  margin: 0 auto;
  padding: 20px 0 36px;
}

.teacher-top,
.controls-panel,
.preview-head,
.student-top {
  display: flex;
  align-items: center;
  gap: 14px;
}

.teacher-top {
  justify-content: space-between;
  margin-bottom: 16px;
}

.eyebrow {
  margin: 0;
  color: var(--muted);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}

.teacher-top h1 {
  margin: 0;
  font-size: clamp(4rem, 10vw, 8rem);
  line-height: 0.95;
}

.timer-card {
  display: flex;
  align-items: center;
  gap: 16px;
}

#teacherTimer {
  min-width: 160px;
  font-size: clamp(2.4rem, 6vw, 5.5rem);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.controls-panel {
  flex-wrap: wrap;
  padding: 16px 0;
}

.lesson-panel,
.mode-panel,
.teacher-tools-grid {
  display: grid;
  gap: 12px;
  margin-bottom: 16px;
}

.lesson-panel {
  grid-template-columns: minmax(160px, 1fr) auto auto auto auto;
  align-items: end;
  padding: 14px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.lesson-panel label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-weight: 800;
}

.section-label {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 900;
  text-transform: uppercase;
}

#lessonPairText {
  font-size: 2rem;
  line-height: 1;
}

.mode-panel {
  grid-template-columns: auto repeat(3, auto) 1fr;
  align-items: center;
}

.settings-panel {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
  padding: 12px;
  border: 2px solid #b6e2d8;
  border-radius: 8px;
  background: #ecfdf5;
}

.settings-panel label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
}

#settingsSavedText {
  color: #0f766e;
  font-weight: 900;
}

button.active,
.mode-panel button.active,
.student-tools button.active {
  background: #0f766e;
  border-color: #fef08a;
  color: #ffffff;
  box-shadow: 0 0 0 4px #99f6e4, 0 4px 0 rgba(15, 118, 110, 0.35);
  transform: translateY(-1px);
}

button.active::after,
.mode-panel button.active::after,
.student-tools button.active::after {
  content: " ✓";
}

#studentEraseButton,
#clearAButton,
#clearBButton,
#clearWhiteboardButton {
  background: #f97316;
}

.select-label {
  color: var(--muted);
  font-weight: 800;
}

.progress {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 2px 0 18px;
}

.progress-dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 999px;
  background: #ffffff;
  border: 2px solid var(--line);
  color: var(--muted);
  font-weight: 900;
}

.progress-dot.done {
  background: #ffe37a;
  border-color: #d8ae15;
  color: var(--ink);
}

.preview-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.repeat-monitor {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  margin: 18px 0;
  padding: 16px;
  border: 2px solid #f6c453;
  border-radius: 8px;
  background: #fffbeb;
}

body[data-mode="practice"] .repeat-monitor,
body[data-mode="practice"] .teacher-tools-grid,
body[data-mode="repeat"] .preview-grid,
body[data-mode="repeat"] .teacher-tools-grid,
body[data-mode="whiteboard"] .preview-grid,
body[data-mode="whiteboard"] .repeat-monitor {
  display: none;
}

body[data-mode="whiteboard"] .teacher-tools-grid {
  grid-template-columns: minmax(0, 1fr);
}

.repeat-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
}

.repeat-grid.small {
  gap: 10px;
}

.repeat-cell {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  border: 2px solid #c9d4e1;
  border-radius: 8px;
  background-color: var(--paper);
  background-image:
    linear-gradient(#dfe5ec 2px, transparent 2px),
    linear-gradient(90deg, #dfe5ec 2px, transparent 2px),
    linear-gradient(#edf1f5 1px, transparent 1px),
    linear-gradient(90deg, #edf1f5 1px, transparent 1px);
  background-size: 50% 50%, 50% 50%, 12.5% 12.5%, 12.5% 12.5%;
}

.repeat-number {
  position: absolute;
  top: 6px;
  left: 6px;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: #f97316;
  color: #ffffff;
  font-size: 0.85rem;
  font-weight: 900;
}

.teacher-tools-grid {
  grid-template-columns: minmax(0, 1fr);
  align-items: start;
  margin-top: 20px;
}

.tool-section {
  min-width: 0;
}

.student-preview {
  min-width: 0;
}

.preview-head {
  justify-content: space-between;
  margin-bottom: 10px;
}

.preview-head h2,
.saved-panel h2 {
  margin: 0;
  font-size: 1.35rem;
}

.preview-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.brush-control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  border-radius: 8px;
  padding: 0 12px;
  background: #ffffff;
  color: var(--ink);
  font-weight: 900;
}

.brush-control input {
  width: 120px;
  min-height: auto;
  padding: 0;
}

.preview-canvas-wrap,
.student-board {
  position: relative;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 2px solid #c9d4e1;
  border-radius: 8px;
  background-color: var(--paper);
  background-image:
    linear-gradient(#dfe5ec 2px, transparent 2px),
    linear-gradient(90deg, #dfe5ec 2px, transparent 2px),
    linear-gradient(#edf1f5 1px, transparent 1px),
    linear-gradient(90deg, #edf1f5 1px, transparent 1px);
  background-size: 50% 50%, 50% 50%, 12.5% 12.5%, 12.5% 12.5%;
}

.preview-canvas-wrap {
  aspect-ratio: 1;
}

.whiteboard-wrap {
  aspect-ratio: auto;
  height: min(72vh, 980px);
  align-items: start;
  overflow: auto;
  padding: 14px;
  background-color: #f8fbff;
  background-image: none;
}

body.whiteboard-fullscreen {
  overflow: hidden;
}

body.whiteboard-fullscreen[data-view="teacher"] .teacher-layout {
  width: 100%;
  min-height: 100vh;
  padding: 10px;
}

body.whiteboard-fullscreen[data-view="teacher"] .teacher-top,
body.whiteboard-fullscreen[data-view="teacher"] .controls-panel,
body.whiteboard-fullscreen[data-view="teacher"] .lesson-panel,
body.whiteboard-fullscreen[data-view="teacher"] .mode-panel,
body.whiteboard-fullscreen[data-view="teacher"] .settings-panel,
body.whiteboard-fullscreen[data-view="teacher"] .progress,
body.whiteboard-fullscreen[data-view="teacher"] .saved-panel {
  display: none;
}

body.whiteboard-fullscreen .teacher-tools-grid {
  margin: 0;
}

body.whiteboard-fullscreen .whiteboard-wrap {
  height: calc(100vh - 92px);
}

body.whiteboard-fullscreen[data-view="student"] .student-layout {
  padding: max(6px, env(safe-area-inset-top)) max(6px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
}

body.whiteboard-fullscreen[data-view="student"] .student-name,
body.whiteboard-fullscreen[data-view="student"] .student-timer {
  display: none;
}

.whiteboard-wrap canvas,
.student-board.whiteboard-mode canvas {
  background-color: #fffef8;
  background-image:
    linear-gradient(#cbd5e1 1px, transparent 1px),
    linear-gradient(90deg, rgba(203, 213, 225, 0.35) 1px, transparent 1px);
  background-size: 100% 42px, 42px 42px;
  box-shadow: 0 0 0 2px #c9d4e1;
}

.guide-char,
.student-guide {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #9aa6b5;
  font-family: "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif JP", serif;
  font-weight: 800;
  line-height: 1;
  opacity: 0.24;
  pointer-events: none;
  user-select: none;
}

.guide-char {
  font-size: clamp(9rem, 28vw, 25rem);
}

canvas {
  position: relative;
  z-index: 1;
  display: block;
  max-width: 100%;
  max-height: 100%;
}

.saved-panel {
  margin-top: 22px;
}

.saved-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.saved-link {
  display: inline-flex;
  align-items: center;
  min-height: 42px;
  border-radius: 8px;
  padding: 0 12px;
  background: #ffffff;
  color: var(--ink);
  text-decoration: none;
  font-weight: 800;
}

.student-layout {
  width: 100%;
  height: 100svh;
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  overflow: hidden;
}

.student-top {
  justify-content: space-between;
  padding-bottom: 12px;
}

.student-name {
  min-width: 116px;
  font-size: clamp(1.1rem, 4vw, 1.8rem);
  font-weight: 900;
}

.student-timer {
  flex: 1;
  text-align: center;
  font-size: clamp(1.8rem, 8vw, 4.8rem);
  font-weight: 1000;
  font-variant-numeric: tabular-nums;
}

.student-board {
  width: 100%;
  min-height: 0;
}

.student-board.whiteboard-mode {
  place-items: start center;
  overflow: auto;
  padding: 12px;
  background: #dbeafe;
}

.whiteboard-hint {
  position: sticky;
  top: 8px;
  left: 8px;
  z-index: 4;
  justify-self: start;
  align-self: start;
  display: none;
  min-height: 36px;
  align-items: center;
  border-radius: 999px;
  padding: 0 12px;
  background: #172033;
  color: #ffffff;
  font-weight: 900;
}

.student-board.whiteboard-mode .whiteboard-hint {
  display: inline-flex;
}

.student-board.whiteboard-mode .student-guide {
  display: none;
}

.student-guide {
  font-size: min(68vw, 68vh);
}

.student-tools {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.student-tools span {
  min-width: 86px;
  color: var(--muted);
  font-weight: 900;
}

.student-tools button {
  min-width: 88px;
}

.student-tools [data-brush-size] {
  min-width: 52px;
  background: #246bfe;
}

.student-repeat {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 12px;
  min-height: 0;
  padding: 12px;
  border: 2px solid #c9d4e1;
  border-radius: 8px;
  background: #fff7ed;
  overflow: hidden;
}

.student-repeat .repeat-grid {
  height: 100%;
  min-height: 0;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  grid-auto-rows: minmax(132px, 1fr);
}

.student-repeat .repeat-cell {
  aspect-ratio: auto;
  min-height: 0;
}

.repeat-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  color: var(--ink);
  font-weight: 900;
}

.repeat-top strong {
  display: inline-grid;
  place-items: center;
  width: 76px;
  height: 76px;
  margin-left: 8px;
  border-radius: 8px;
  background: #172033;
  color: #ffffff;
  font-size: 3.8rem;
  line-height: 1;
}

#studentRepeatStatus {
  min-height: 52px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  padding: 0 18px;
  background: #fef08a;
  color: #713f12;
  font-size: 1.4rem;
}

.approval-message {
  min-height: 54px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #dcfce7;
  color: #166534;
  font-size: clamp(1rem, 3vw, 1.6rem);
  font-weight: 900;
  text-align: center;
}

.congrats {
  min-height: 100%;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  border-radius: 8px;
  background:
    linear-gradient(135deg, #fef08a, #bbf7d0 45%, #bfdbfe);
  color: #172033;
  text-align: center;
}

.congrats div {
  font-size: clamp(5rem, 16vw, 10rem);
  color: #f59e0b;
}

.congrats h1 {
  margin: 0;
  font-size: clamp(3rem, 9vw, 6rem);
}

.congrats p {
  margin: 0;
  font-size: clamp(1.2rem, 4vw, 2rem);
  font-weight: 900;
}

@media (max-width: 880px) {
  .teacher-top,
  .timer-card {
    align-items: flex-start;
    flex-direction: column;
  }

  .preview-grid {
    grid-template-columns: 1fr;
  }

  .teacher-tools-grid,
  .repeat-monitor,
  .lesson-panel,
  .mode-panel {
    grid-template-columns: 1fr;
  }

  .preview-head {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (max-width: 620px) {
  .student-top {
    display: grid;
    grid-template-columns: 1fr;
  }

  .student-timer {
    text-align: left;
  }

  .student-tools {
    justify-content: flex-start;
  }

  .student-tools button {
    min-width: 0;
    flex: 1;
    padding: 0 8px;
  }

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

  .student-repeat .repeat-grid {
    grid-template-columns: 1fr;
    grid-auto-rows: minmax(170px, 22vh);
    gap: 10px;
    overflow: auto;
    padding-right: 4px;
  }

  .repeat-top strong {
    width: 56px;
    height: 56px;
    font-size: 2.8rem;
  }
}

@media (orientation: portrait) and (max-width: 900px) {
  .student-repeat .repeat-grid {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    grid-auto-rows: minmax(160px, 1fr);
    gap: 10px;
  }
}

@media (orientation: portrait) and (max-width: 620px) {
  .student-repeat .repeat-grid {
    grid-template-columns: 1fr;
    grid-auto-rows: minmax(170px, 22vh);
  }
}
