:root {
  color-scheme: light;
  --bg: #f5f2ec;
  --paper: #fffdf8;
  --ink: #202822;
  --muted: #657069;
  --line: #d9d0c0;
  --green: #206b5e;
  --green-soft: #e6f1ec;
  --rose: #c94f43;
  --rose-soft: #ffe4dd;
  --blue: #315f9c;
  --blue-soft: #e8eef8;
  --gold: #bc7a1e;
  --gold-soft: #fff0cf;
  --shadow: 0 18px 42px rgba(39, 31, 20, 0.1);
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background:
    linear-gradient(120deg, rgba(32, 107, 94, 0.11), transparent 34%),
    linear-gradient(300deg, rgba(201, 79, 67, 0.12), transparent 30%),
    var(--bg);
  font-family:
    "Hiragino Sans",
    "Yu Gothic",
    "Meiryo",
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    sans-serif;
  line-height: 1.6;
  letter-spacing: 0;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  border: 0;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(49, 95, 156, 0.28);
  outline-offset: 2px;
}

.app-shell {
  width: min(1500px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 22px 0 28px;
}

.app-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  padding: 8px 0 18px;
}

.eyebrow,
.section-kicker {
  margin: 0 0 6px;
  color: var(--green);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  letter-spacing: 0;
}

h1 {
  margin: 0;
  color: var(--ink);
  font-size: clamp(2rem, 3.6vw, 4.2rem);
  line-height: 1.05;
  font-weight: 900;
}

.lead {
  margin: 8px 0 0;
  color: var(--muted);
  font-weight: 800;
}

.header-actions,
.timer-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.tool-button,
.link-button,
.primary-button,
.mini-button {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: var(--ink);
  color: #fffaf1;
  cursor: pointer;
  font-weight: 900;
  text-decoration: none;
  transition:
    transform 140ms ease,
    background 140ms ease;
}

.tool-button,
.link-button {
  min-width: 72px;
  padding: 0 14px;
}

.primary-button {
  padding: 0 20px;
}

.mini-button {
  min-height: 34px;
  padding: 0 10px;
  background: var(--green-soft);
  color: var(--green);
}

.tool-button:hover,
.link-button:hover,
.primary-button:hover,
.mini-button:hover {
  transform: translateY(-1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.46;
  transform: none;
}

.tool-button:hover,
.link-button:hover,
.primary-button:hover {
  background: var(--green);
}

.danger {
  background: var(--rose-soft);
  color: #9c3028;
}

.danger:hover {
  background: #ffd4ca;
}

.app-layout {
  display: grid;
  grid-template-columns: minmax(310px, 0.9fr) minmax(420px, 1.2fr) minmax(310px, 0.9fr);
  gap: 16px;
  align-items: start;
}

.student-shell {
  width: min(920px, calc(100vw - 32px));
}

.student-header {
  align-items: center;
}

.student-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
}

.teacher-dashboard-layout {
  display: grid;
  grid-template-columns: minmax(360px, 0.95fr) minmax(420px, 1.05fr);
  gap: 16px;
  align-items: start;
}

.session-panel,
.reader-panel,
.reaction-panel,
.dashboard-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.94);
  box-shadow: var(--shadow);
  padding: 22px;
}

.session-panel,
.reaction-panel,
.dashboard-panel {
  background: rgba(250, 248, 241, 0.96);
}

.reader-panel {
  border-color: rgba(32, 107, 94, 0.34);
  background: rgba(255, 255, 252, 0.98);
  box-shadow: 0 22px 54px rgba(32, 107, 94, 0.13);
}

.student-reader {
  padding: 26px;
}

.reaction-panel {
  position: sticky;
  top: 16px;
}

.monitor-panel {
  position: sticky;
  top: 16px;
}

.role-badge {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  border-radius: 999px;
  margin: 0 0 12px;
  padding: 4px 10px;
  font-size: 0.78rem;
  font-weight: 900;
}

.role-badge.teacher {
  background: var(--blue-soft);
  color: var(--blue);
}

.role-badge.learner {
  background: var(--green);
  color: #fffaf1;
}

.panel-heading {
  margin-bottom: 18px;
}

.panel-heading.compact {
  margin-top: 22px;
  margin-bottom: 12px;
}

.panel-heading h2 {
  margin: 0;
  color: var(--ink);
  font-size: 1.45rem;
  line-height: 1.35;
  font-weight: 900;
}

.field-grid {
  display: grid;
  gap: 12px;
}

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

.field {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.field span,
.check-row span {
  color: #41504a;
  font-size: 0.9rem;
  font-weight: 900;
}

.field.short {
  max-width: 180px;
}

.learner-name {
  max-width: 340px;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  padding: 11px 12px;
}

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

.work-form {
  border-top: 1px solid var(--line);
  margin-top: 20px;
  padding-top: 4px;
}

.file-import {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  margin-bottom: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 12px;
}

.file-import strong {
  display: block;
  color: var(--ink);
  font-size: 0.96rem;
  font-weight: 900;
}

.file-import p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
}

.file-button {
  cursor: pointer;
}

.file-button input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.file-button span {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: var(--ink);
  color: #fffaf1;
  padding: 0 14px;
  font-weight: 900;
}

.work-list,
.comment-list {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.work-card,
.comment-card,
.active-work,
.timer-card,
.reaction-summary {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.work-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 12px;
}

.work-card h3,
.active-work h3,
.comment-card h3 {
  margin: 0;
  color: var(--ink);
  font-size: 1rem;
  line-height: 1.45;
}

.work-card p,
.active-work p,
.comment-card p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.work-card.is-active {
  border-color: rgba(32, 107, 94, 0.44);
  box-shadow: 0 0 0 3px rgba(32, 107, 94, 0.12);
}

.work-actions {
  display: grid;
  gap: 6px;
}

.teacher-active-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 14px;
}

.teacher-active-card span {
  display: block;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 900;
}

.teacher-active-card strong {
  display: block;
  color: var(--ink);
  font-size: 1.2rem;
  line-height: 1.35;
  font-weight: 900;
}

.teacher-active-card p {
  margin: 4px 0 0;
  color: var(--muted);
  font-weight: 800;
}

.teacher-work-toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.active-work {
  padding: 16px;
}

.circulation-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 10px;
}

.circulation-toolbar p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 900;
}

.circulation-toolbar div {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.target-box {
  display: grid;
  gap: 5px;
  margin-top: 12px;
  border: 1px solid rgba(32, 107, 94, 0.22);
  border-radius: 8px;
  background: var(--green-soft);
  padding: 11px 12px;
}

.target-box span {
  color: var(--green);
  font-size: 0.78rem;
  font-weight: 900;
}

.target-box strong {
  color: var(--ink);
  font-size: 0.95rem;
  line-height: 1.55;
}

.body-segments {
  display: grid;
  gap: 8px;
  max-height: 330px;
  overflow: auto;
  margin-top: 12px;
  border-radius: 8px;
  background: #f8f5ee;
  padding: 10px;
}

.text-segment {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  border: 1px solid transparent;
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  cursor: pointer;
  padding: 10px 11px;
  text-align: left;
}

.text-segment:hover {
  border-color: rgba(32, 107, 94, 0.35);
  background: #fbfffd;
}

.text-segment.is-selected {
  border-color: rgba(32, 107, 94, 0.56);
  background: var(--green-soft);
  box-shadow: 0 0 0 3px rgba(32, 107, 94, 0.13);
}

.inline-stamps {
  display: inline-flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 5px;
}

.inline-stamp {
  border-radius: 999px;
  background: var(--gold-soft);
  color: #7c5117;
  padding: 4px 8px;
  font-size: 0.76rem;
  font-weight: 900;
}

.inline-note {
  border-radius: 999px;
  background: var(--blue-soft);
  color: var(--blue);
  padding: 4px 8px;
  font-size: 0.76rem;
  font-weight: 900;
}

.timer-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin: 14px 0;
  padding: 14px;
}

.timer-card span {
  display: block;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 900;
}

.timer-card strong {
  display: block;
  color: var(--ink);
  font-size: 2rem;
  line-height: 1.1;
  font-weight: 900;
}

.stamp-field {
  margin: 0 0 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 12px;
}

.stamp-field h3 {
  margin: 0;
  color: #41504a;
  font-size: 0.96rem;
  font-weight: 900;
}

.stamp-field p {
  margin: 4px 0 10px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
}

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

.stamp-button {
  display: flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  cursor: pointer;
  font-weight: 900;
  padding: 7px 8px;
  text-align: center;
}

.stamp-button:hover {
  border-color: rgba(32, 107, 94, 0.48);
  background: var(--green-soft);
}

.stamp-button:nth-child(3n + 2):hover {
  border-color: rgba(188, 122, 30, 0.48);
  background: var(--gold-soft);
}

.stamp-button:nth-child(3n):hover {
  border-color: rgba(49, 95, 156, 0.38);
  background: var(--blue-soft);
}

.check-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: start;
  margin-bottom: 16px;
}

.check-row input {
  width: 18px;
  height: 18px;
  margin-top: 4px;
}

.reaction-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 12px;
}

.summary-count {
  border-radius: 8px;
  background: var(--green-soft);
  padding: 10px;
}

.summary-count:nth-child(4n + 2) {
  background: var(--gold-soft);
}

.summary-count:nth-child(4n + 3) {
  background: var(--blue-soft);
}

.summary-count:nth-child(4n) {
  background: var(--rose-soft);
}

.summary-count span {
  display: block;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 900;
}

.summary-count strong {
  color: var(--ink);
  font-size: 1.4rem;
  font-weight: 900;
}

.comment-card {
  padding: 12px;
}

.comment-card header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.comment-card .stamp {
  border-radius: 999px;
  background: var(--green-soft);
  color: var(--green);
  padding: 4px 9px;
  font-size: 0.78rem;
  font-weight: 900;
}

.comment-card blockquote {
  margin: 8px 0;
  border-left: 4px solid var(--line);
  padding-left: 10px;
  color: var(--muted);
  font-weight: 700;
}

.message {
  min-height: 24px;
  margin: 14px 0 0;
  color: var(--green);
  font-weight: 900;
  text-align: right;
}

.empty {
  margin: 0;
  color: var(--muted);
  font-weight: 700;
}

@media (max-width: 1180px) {
  .app-layout,
  .teacher-dashboard-layout {
    grid-template-columns: minmax(310px, 0.9fr) minmax(420px, 1.1fr);
  }

  .reaction-panel,
  .monitor-panel {
    position: static;
    grid-column: 1 / -1;
  }
}

@media (max-width: 760px) {
  .app-shell {
    width: min(100% - 20px, 720px);
    padding-top: 12px;
  }

  .app-header {
    align-items: stretch;
    flex-direction: column;
    gap: 14px;
  }

  .header-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .app-layout,
  .teacher-dashboard-layout,
  .field-grid.two,
  .file-import,
  .reaction-summary {
    grid-template-columns: 1fr;
  }

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

  .session-panel,
  .reader-panel,
  .reaction-panel,
  .dashboard-panel {
    padding: 16px;
  }

  .timer-card {
    align-items: stretch;
    flex-direction: column;
  }

  .circulation-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .timer-actions {
    justify-content: flex-start;
  }

  .teacher-active-card {
    grid-template-columns: 1fr;
  }

  .teacher-work-toolbar {
    justify-content: flex-start;
  }

  .text-segment {
    grid-template-columns: 1fr;
  }

  .inline-stamps {
    justify-content: flex-start;
  }
}

@media print {
  body {
    background: #ffffff;
  }

  .header-actions,
  .session-panel,
  .message {
    display: none;
  }

  .app-shell {
    width: 100%;
    padding: 0;
  }

  .app-header,
  .app-layout,
  .teacher-dashboard-layout,
  .student-layout {
    display: block;
  }

  .reaction-panel {
    border: 0;
    box-shadow: none;
    padding: 0;
  }
}
