:root {
  font-family: system-ui, -apple-system, "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;
  color: #263d4d;
  background: #fffaf3;
  line-height: 1.6;
  font-size: 16px;
}
* { box-sizing: border-box; }
body { margin: 0; }
.toolbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: .8rem max(1rem, calc((100vw - 1100px) / 2));
  background: #fff;
  border-bottom: 2px solid #f3d6ae;
}
.toolbar a { color: #1e6970; font-weight: 700; text-decoration: none; white-space: nowrap; }
.toolbar h1 { font-size: 1.2rem; margin: 0; }
main {
  max-width: 1100px;
  margin: 1.25rem auto;
  padding: 0 1rem;
  display: grid;
  grid-template-columns: minmax(260px, 340px) minmax(0, 1fr);
  gap: 1.25rem;
  align-items: start;
}
.controls, .preview-wrap {
  min-width: 0;
  background: #fff;
  border: 1px solid #d9e4dc;
  border-radius: 18px;
  padding: 1.2rem;
  box-shadow: 0 4px 14px #173d4a0b;
}
.controls h2, .preview-wrap > h2 { margin: .05rem 0 1rem; font-size: 1.15rem; }
.controls label { display: block; font-weight: 700; margin-bottom: .35rem; }
.controls input { width: 100%; min-width: 0; font: inherit; padding: .75rem .8rem; border: 2px solid #8ab6a8; border-radius: 10px; }
.controls input:focus { outline: 3px solid #ffe093; outline-offset: 2px; }
.controls p { font-size: .9rem; margin: .55rem 0; }
.privacy-note { padding: .65rem .75rem; background: #f0f7ee; border-radius: 10px; }
.validation { min-height: 1.5em; color: #9a4f25; }
.actions { display: flex; gap: .6rem; flex-wrap: wrap; margin: 1rem 0; }
button { font: inherit; font-weight: 700; border: 0; border-radius: 10px; padding: .7rem 1rem; background: #e97748; color: #fff; cursor: pointer; }
button.secondary { background: #e9f1ee; color: #285b5a; }
button:disabled { opacity: .48; cursor: not-allowed; }
details { border-top: 1px solid #e5e9e4; padding-top: .7rem; }
summary { font-weight: 700; cursor: pointer; }
details p, details li { font-size: .9rem; }
.preview-wrap { overflow: hidden; }
.empty-state {
  display: grid;
  place-items: center;
  min-height: 200px;
  text-align: center;
  color: #657782;
  background: #f7f8f5;
  border: 1px dashed #c5d2cc;
  border-radius: 12px;
  padding: 1rem;
}
.worksheet {
  container-type: inline-size;
  width: min(100%, 690px);
  aspect-ratio: 210 / 297;
  min-width: 0;
  margin: 0 auto;
  padding: 6.1cqw 7cqw;
  background: #fff;
  color: #263d4d;
  border: 1px solid #d8ddd9;
  box-shadow: 0 2px 10px #22334418;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sheet-head { text-align: center; border-bottom: 2px solid #e7a276; padding-bottom: 3.2cqw; }
.sheet-kicker { margin: 0; color: #a95432; font-size: 2.6cqw; font-weight: 700; letter-spacing: .15em; }
.sheet-head h2 { font-size: 4.6cqw; margin: .6cqw 0 2cqw; }
.sheet-name {
  margin: 0 auto;
  min-height: 10.5cqw;
  display: grid;
  place-items: center;
  font-size: var(--name-size, 7.5cqw);
  font-weight: 700;
  letter-spacing: .14em;
  overflow-wrap: anywhere;
}
.trace-section, .write-section { margin-top: 4.3cqw; }
.worksheet h3 { margin: 0 0 1.7cqw; font-size: 2.9cqw; }
.trace-rows { display: grid; gap: 1.7cqw; }
.trace-row {
  height: 15.2cqw;
  min-width: 0;
  border: 1px solid #b9c7c6;
  border-radius: 1.2cqw;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: .28em;
  overflow: hidden;
  padding: 1.1cqw;
  background: repeating-linear-gradient(to bottom, transparent 0, transparent 7.35cqw, #d7dedb 7.5cqw, #d7dedb 7.65cqw, transparent 7.8cqw);
}
.trace-char {
  flex: 0 1 auto;
  min-width: 0;
  font-family: "Hiragino Maru Gothic ProN", "Yu Gothic", sans-serif;
  font-size: var(--trace-size, 11cqw);
  line-height: 1;
  color: transparent;
  -webkit-text-stroke: 1px #9ba9aa;
}
.write-rows { display: grid; gap: 1.9cqw; }
.write-row {
  height: 13.6cqw;
  border: 1.5px solid #bac8c8;
  border-radius: 1.2cqw;
  background: linear-gradient(to bottom, transparent 49%, #d8e0de 50%, transparent 51%), linear-gradient(to right, transparent calc(50% - .5px), #e7ece9 50%, transparent calc(50% + .5px));
}
.sheet-footer { margin-top: auto; padding-top: 3cqw; text-align: center; font-size: 2.3cqw; color: #61726f; }
.worksheet[hidden], .empty-state[hidden] { display: none !important; }
@media (max-width: 760px) {
  main { grid-template-columns: minmax(0, 1fr); margin: .75rem auto; }
  .toolbar { padding: .7rem 1rem; }
  .worksheet { width: min(100%, 690px); }
  .preview-wrap { width: 100%; }
}
@media print {
  @page { size: A4 portrait; margin: 0; }
  body { background: #fff; }
  .toolbar, .controls, .preview-wrap > h2, .empty-state { display: none !important; }
  main { display: block; max-width: none; margin: 0; padding: 0; }
  .preview-wrap { border: 0; border-radius: 0; box-shadow: none; padding: 0; overflow: visible; }
  .worksheet { display: flex !important; width: 210mm; height: 297mm; aspect-ratio: auto; min-height: 0; margin: 0; padding: 15mm 17mm; border: 0; box-shadow: none; page-break-after: avoid; }
  .worksheet[hidden] { display: none !important; }
  .sheet-head { padding-bottom: 8mm; }
  .sheet-kicker { font-size: 13pt; }
  .sheet-head h2 { font-size: 24pt; margin: 1mm 0 4mm; }
  .sheet-name { font-size: var(--name-print-size, 34pt); min-height: 18mm; }
  .worksheet h3 { font-size: 15pt; margin-bottom: 3mm; }
  .trace-section, .write-section { margin-top: 8mm; }
  .trace-rows { gap: 3mm; }
  .trace-row { height: 29mm; border-radius: 2mm; gap: 2mm; padding: 1mm; }
  .trace-char { font-size: var(--trace-print-size, 22mm); -webkit-text-stroke: 1.2px #9ba9aa; }
  .write-rows { gap: 4mm; }
  .write-row { height: 25mm; border-radius: 2mm; }
  .sheet-footer { font-size: 12pt; padding-top: 6mm; }
}
