:root {
  color-scheme: light;
  --ink: #18312d;
  --muted: #64716e;
  --line: #71807b;
  --light-line: #c4cdc9;
  --paper: #fffef9;
  --canvas: #e9eeeb;
  --teal: #176f65;
  --teal-dark: #10564f;
  --teal-soft: #dceee9;
  --green-soft: #edf4dd;
  --sand: #f7eedc;
  --gray-soft: #f0f1ed;
  font-family: "Avenir Next", "Hiragino Sans", "Yu Gothic UI", "Yu Gothic", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  margin: 0;
  color: var(--ink);
  background: var(--canvas);
  font-size: 14px;
}

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

button,
summary,
select {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible {
  outline: 3px solid rgb(23 111 101 / 25%);
  outline-offset: 2px;
}

.memo-controls {
  position: sticky;
  z-index: 20;
  top: 0;
  display: grid;
  grid-template-columns: minmax(230px, 0.85fr) minmax(420px, 1.5fr) auto;
  gap: 24px;
  align-items: center;
  min-height: 86px;
  padding: 12px 24px;
  border-bottom: 1px solid #c9d2cd;
  background: rgb(255 254 249 / 97%);
  box-shadow: 0 8px 28px rgb(31 50 46 / 8%);
  backdrop-filter: blur(12px);
}

.control-heading {
  display: flex;
  gap: 18px;
  align-items: center;
}

.back-link {
  color: var(--teal);
  text-decoration: none;
  font-size: 12px;
  font-weight: 850;
  white-space: nowrap;
}

.control-heading p,
.control-heading h1 {
  margin: 0;
}

.control-heading p {
  color: var(--teal);
  font-size: 9px;
  font-weight: 900;
  letter-spacing: 0.15em;
}

.control-heading h1 {
  margin-top: 2px;
  font-size: 17px;
  line-height: 1.2;
}

.control-fields {
  display: grid;
  grid-template-columns: 130px 165px minmax(150px, 1fr);
  gap: 10px;
}

.control-fields label {
  display: grid;
  gap: 3px;
  color: var(--muted);
  font-size: 9px;
  font-weight: 900;
}

.control-fields input,
.control-fields select {
  width: 100%;
  min-height: 40px;
  padding: 0 10px;
  color: var(--ink);
  border: 1px solid #c4cec9;
  border-radius: 8px;
  background: white;
  font-size: 13px;
  font-weight: 750;
}

.control-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.row-count-badge {
  padding: 8px 10px;
  color: var(--teal-dark);
  border: 1px solid #b9d5ce;
  border-radius: 999px;
  background: var(--teal-soft);
  font-size: 11px;
  font-weight: 900;
  white-space: nowrap;
}

.primary-button,
.secondary-button {
  min-height: 42px;
  padding: 0 16px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 850;
}

.primary-button {
  color: white;
  border: 1px solid var(--teal);
  background: var(--teal);
}

.primary-button:hover {
  background: var(--teal-dark);
}

.secondary-button {
  color: var(--teal-dark);
  border: 1px solid #a9c9c1;
  background: white;
}

.setup-strip {
  display: grid;
  max-width: 1120px;
  margin: 24px auto 0;
  padding: 0 24px;
}

.setup-intro {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 14px 16px;
  border: 1px solid #c8d2cd;
  border-radius: 12px 12px 0 0;
  background: #f9fbf9;
}

.step-number {
  display: grid;
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  color: white;
  border-radius: 50%;
  background: var(--teal);
  font-size: 13px;
  font-weight: 900;
  place-items: center;
}

.setup-intro h2,
.setup-intro p {
  margin: 0;
}

.setup-intro h2 {
  font-size: 15px;
}

.setup-intro p {
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.55;
}

.import-details {
  border: 1px solid #c8d2cd;
  border-top: 0;
  border-radius: 0 0 12px 12px;
  background: white;
}

.import-details summary {
  padding: 13px 16px;
  color: var(--teal-dark);
  font-size: 12px;
  font-weight: 900;
}

.paste-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  padding: 4px 16px 14px;
}

.paste-field {
  display: grid;
  gap: 7px;
}

.paste-field > span {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: baseline;
  font-size: 12px;
}

.paste-field small {
  color: var(--muted);
  font-size: 10px;
}

.paste-field textarea {
  width: 100%;
  min-height: 132px;
  padding: 10px;
  color: #253d38;
  border: 1px solid #c9d1ce;
  border-radius: 8px;
  background: #fbfcfb;
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 11px;
  line-height: 1.5;
  resize: vertical;
}

.import-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 0 16px 16px;
}

.import-status {
  margin: 0 0 0 4px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.5;
}

.import-status[data-tone="success"] {
  color: #17643d;
}

.import-status[data-tone="warning"] {
  color: #80600c;
}

.import-status[data-tone="error"] {
  color: #a43f32;
}

.memo-document {
  display: grid;
  justify-content: center;
  padding: 24px 24px 40px;
}

.paper-page {
  width: 210mm;
  min-height: 297mm;
  padding: 8mm;
  background: var(--paper);
  box-shadow: 0 16px 50px rgb(25 44 40 / 15%);
}

.paper-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 7mm;
  align-items: end;
  min-height: 15mm;
  padding-bottom: 2mm;
  border-bottom: 1.2px solid var(--ink);
}

.paper-brand {
  margin: 0 0 1mm;
  color: var(--teal);
  font-size: 8pt;
  font-weight: 900;
  letter-spacing: 0.16em;
}

.paper-title h2 {
  margin: 0;
  font-size: 17pt;
  line-height: 1;
  letter-spacing: -0.035em;
}

.paper-title h2 span {
  margin-right: 2.5mm;
  color: var(--teal-dark);
}

.paper-meta {
  display: grid;
  grid-template-columns: 34mm 31mm 20mm;
  gap: 3mm;
}

.paper-meta span {
  display: grid;
  min-width: 0;
  padding-bottom: 0.7mm;
  border-bottom: 0.5px solid var(--line);
}

.paper-meta small {
  color: var(--muted);
  font-size: 7pt;
  font-weight: 900;
  letter-spacing: 0.07em;
}

.paper-meta strong {
  overflow: hidden;
  font-size: 9pt;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.paper-guide {
  display: grid;
  grid-template-columns: 1.1fr 1.7fr 1fr;
  gap: 2mm;
  margin: 1.5mm 0 1.3mm;
  padding: 1.1mm 1.8mm;
  color: #5b4a1e;
  border: 0.45px solid #dccca8;
  background: var(--sand);
  font-size: 8pt;
  line-height: 1.25;
}

.paper-guide span + span {
  padding-left: 2mm;
  border-left: 0.45px solid #cdbd98;
}

.paper-guide b {
  margin-right: 1mm;
  color: var(--ink);
}

.memo-table {
  width: 100%;
  height: 244mm;
  table-layout: fixed;
  border-collapse: collapse;
  border: 1.1px solid var(--ink);
}

.memo-table th,
.memo-table td {
  border: 0.5px solid var(--line);
}

.memo-table th {
  padding: 0.7mm 0.4mm;
  color: var(--ink);
  background: var(--teal-soft);
  font-size: 9pt;
  font-weight: 900;
  line-height: 1.15;
  text-align: center;
}

.memo-table th small {
  color: var(--muted);
  font-size: 8pt;
}

.memo-table .group-row {
  height: 5.2mm;
}

.memo-table .detail-row {
  height: 7.8mm;
}

.memo-table .prepare-group,
.memo-table .lesson-number-column,
.memo-table .home-test-column {
  background: var(--sand);
}

.memo-table .lesson-group,
.memo-table .attendance-column,
.memo-table .reading-column,
.memo-table .typing-column {
  background: var(--green-soft);
}

.memo-table .internal-column {
  background: var(--gray-soft);
}

.memo-table tbody tr {
  height: 11.35mm;
  break-inside: avoid;
}

.memo-table td {
  position: relative;
  padding: 0.7mm;
  vertical-align: middle;
  background: var(--paper);
}

.number-column { width: 2%; }
.time-column { width: 6.2%; }
.student-column { width: 12.8%; }
.lesson-number-column { width: 4.3%; }
.home-test-column { width: 5.5%; }
.attendance-column { width: 5.9%; }
.reading-column { width: 13%; }
.typing-column { width: 14%; }
.shared-column { width: 23%; }
.internal-column { width: 13.3%; }

.number-cell {
  color: #8a9692;
  background: #f6f7f3 !important;
  font-family: ui-monospace, monospace;
  font-size: 8pt;
  font-weight: 800;
  text-align: center;
}

.memo-table input {
  width: 100%;
  min-width: 0;
  height: auto;
  padding: 0;
  color: var(--ink);
  border: 0;
  outline: 0;
  background: transparent;
  font-size: 9pt;
  font-weight: 750;
  line-height: 1.2;
}

.memo-table input::placeholder {
  color: #a8b1ad;
}

.time-cell input {
  text-align: center;
}

.student-cell {
  padding: 0.55mm 0.8mm !important;
}

.student-name {
  font-size: 9.5pt !important;
  font-weight: 850 !important;
}

.student-id {
  margin-top: 0.8mm;
  color: var(--muted) !important;
  font-size: 8pt !important;
  font-weight: 700 !important;
}

.student-id.needs-match {
  color: #a05235 !important;
}

.lesson-number-cell,
.home-test-cell {
  background: #fffaf0 !important;
}

.write-box {
  display: block;
  width: 6.7mm;
  height: 8.7mm;
  margin: auto;
  border: 0.65px solid #89928f;
  border-radius: 1mm;
}

.choice-set {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.45mm 0.25mm;
  align-items: center;
  justify-items: center;
}

.choice-set span {
  display: grid;
  width: 4.4mm;
  height: 4.4mm;
  border: 0.5px solid #8b9692;
  border-radius: 50%;
  font-size: 7.5pt;
  font-weight: 850;
  line-height: 1;
  place-items: center;
}

.write-lines {
  position: absolute;
  inset: 0.8mm;
  background-image: linear-gradient(to bottom, transparent calc(100% - 0.45px), #ccd2ce 0);
  background-size: 100% 50%;
}

.internal-cell {
  background: #f6f6f2 !important;
}

.paper-footer {
  display: flex;
  justify-content: space-between;
  margin-top: 1mm;
  color: var(--muted);
  font-size: 8pt;
  font-weight: 750;
}

@page {
  size: A4 portrait;
  margin: 7mm;
}

@media print {
  * {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  body {
    min-width: 0;
    background: white;
  }

  .no-print {
    display: none !important;
  }

  .memo-document {
    display: block;
    padding: 0;
  }

  .paper-page {
    width: auto;
    height: 283mm;
    min-height: 0;
    padding: 0;
    box-shadow: none;
  }

  .memo-table input::placeholder {
    color: transparent;
  }

  .memo-table input {
    appearance: none;
  }
}

@media screen and (max-width: 980px) {
  .memo-controls {
    position: static;
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .control-fields {
    grid-template-columns: repeat(3, 1fr);
  }

  .control-actions {
    justify-content: space-between;
  }

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

  .import-actions {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .memo-document {
    justify-content: start;
    overflow-x: auto;
  }
}

@media screen and (max-width: 560px) {
  .memo-controls,
  .setup-strip {
    padding-right: 14px;
    padding-left: 14px;
  }

  .control-heading {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }

  .control-fields {
    grid-template-columns: 1fr 1fr;
  }

  .control-fields label:last-child {
    grid-column: 1 / -1;
  }

  .setup-intro {
    align-items: flex-start;
  }
}
