@font-face { font-family: 'VIC Hand'; src: url('../fonts/vic-hand.woff2') format('woff2'); font-weight: 400 700; font-display: block; }
@font-face { font-family: 'VIC Hand Start'; src: url('../fonts/vic-hand-start.woff2') format('woff2'); font-weight: 400 700; font-display: block; }
@font-face { font-family: 'VIC Hand Arrows'; src: url('../fonts/vic-hand-arrows.woff2') format('woff2'); font-weight: 400 700; font-display: block; }
@font-face { font-family: 'VIC Hand Dots'; src: url('../fonts/vic-hand-dots.woff2') format('woff2'); font-weight: 400 700; font-display: block; }
@font-face { font-family: 'VIC Cursive'; src: url('../fonts/vic-cursive.woff2') format('woff2'); font-weight: 100 400; font-display: block; }

:root {
  color-scheme: light;
  --bg: #f6f3ec;
  --panel: #ffffff;
  --ink: #1d2433;
  --muted: #5b6577;
  --line: #e4dfd4;
  --accent: #2f5fb3;
  --accent-hover: #264f97;
  --accent-soft: #e9effa;
  --margin-red: #d64545;
  --radius: 10px;
  --ui: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 var(--ui);
}

a { color: var(--accent); }

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

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

/* Header: a strip of exercise-book paper with its red margin line. */
.masthead {
  background: repeating-linear-gradient(180deg, #fff 0 23px, #dbe5f5 23px 24px);
  border-bottom: 1px solid var(--line);
}

.masthead-inner {
  position: relative;
  max-width: 1320px;
  margin: 0 auto;
  padding: 18px 24px 18px 84px;
  display: flex;
  align-items: center;
  gap: 14px;
}

.masthead-inner::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 70px;
  width: 2px;
  background: var(--margin-red);
}

.masthead-inner .logo { margin-left: -2px; }

.logo { width: 40px; height: 40px; flex: none; }
.logo rect { fill: var(--accent); }
.logo path { fill: none; stroke: #fff; stroke-width: 2.6; stroke-linecap: round; }

.masthead h1 {
  margin: 0;
  font: 400 32px/1.1 'VIC Hand', var(--ui);
  letter-spacing: 0.2px;
}

.masthead p { margin: 2px 0 0; color: var(--muted); }

.mode-link {
  margin-left: auto;
  flex: none;
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}

.mode-link:hover { background: var(--accent-hover); }

.layout {
  max-width: 1320px;
  margin: 0 auto;
  padding: 24px;
  display: grid;
  grid-template-columns: minmax(300px, 360px) 1fr;
  gap: 28px;
  align-items: start;
}

/* Controls */
.controls { display: grid; gap: 14px; }

.group {
  margin: 0;
  padding: 14px 16px 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: grid;
  gap: 12px;
  min-width: 0;
}

.group[hidden], .field[hidden] { display: none; }

legend {
  float: left;
  width: 100%;
  padding: 0;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.field { display: grid; gap: 6px; }
.field > span { font-size: 13px; font-weight: 600; }

select, input[type="text"], textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #cfd6e1;
  border-radius: 8px;
  background: #fff;
}

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

select:focus-visible, input:focus-visible, textarea:focus-visible, button:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 35%, transparent);
  outline-offset: 1px;
}

.hint { color: var(--muted); font-size: 12.5px; }

.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { width: 17px; height: 17px; accent-color: var(--accent); }

/* Segmented buttons and chips share the "pressed" look. */
.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  background: #eef1f6;
  border-radius: 9px;
  padding: 3px;
  gap: 3px;
}

.segmented button, .chips button, .letter-grid button {
  border: 0;
  border-radius: 7px;
  background: transparent;
  padding: 8px 6px;
  cursor: pointer;
  font-weight: 600;
  white-space: nowrap;
}

.segmented.small button { padding: 6px 4px; font-size: 13px; }
.segmented button:hover, .letter-grid button:hover { background: #e2e7f0; }

.segmented button[aria-pressed="true"],
.chips button[aria-pressed="true"],
.letter-grid button[aria-pressed="true"] {
  background: var(--accent);
  color: #fff;
}

.chips { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.chips button { background: #f2f4f8; border: 1px solid #e3e8f0; text-align: left; padding: 9px 12px; }
.chips button:hover { background: var(--accent-soft); }

.letter-grid { display: grid; grid-template-columns: repeat(9, 1fr); gap: 4px; }
.letter-grid button {
  background: #f2f4f8;
  padding: 2px 0 6px;
  font: 400 24px/1.2 'VIC Hand', var(--ui);
}

/* Preview */
.preview {
  position: sticky;
  top: 16px;
  display: grid;
  gap: 12px;
  justify-items: center;
}

.toolbar {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.pager { display: flex; align-items: center; gap: 8px; font-weight: 600; }

.icon-button {
  width: 34px;
  height: 34px;
  border: 1px solid #cfd6e1;
  border-radius: 8px;
  background: #fff;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.icon-button:disabled { opacity: 0.4; cursor: default; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; }

.button {
  border: 1px solid #cfd6e1;
  border-radius: 8px;
  background: #fff;
  padding: 9px 14px;
  font-weight: 600;
  cursor: pointer;
}

.button:hover { background: #f2f4f8; }
.button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.button.primary:hover { background: var(--accent-hover); }
.button:disabled { opacity: 0.6; cursor: progress; }

.status { margin: 0; flex: 1 1 160px; min-height: 1.45em; color: var(--muted); font-size: 14px; text-align: center; }
.status.error { color: #b42318; }

.paper {
  width: min(100%, calc((100vh - 200px) * 210 / 297));
  min-width: 280px;
  aspect-ratio: 210 / 297;
  background: #fff;
  box-shadow: 0 1px 2px rgb(29 36 51 / 0.08), 0 10px 30px rgb(29 36 51 / 0.12);
  border-radius: 3px;
}

.paper canvas { display: block; width: 100%; height: 100%; border-radius: 3px; }

.site-footer {
  max-width: 1320px;
  margin: 0 auto;
  padding: 8px 24px 32px;
  color: var(--muted);
  font-size: 13px;
}

.site-footer p { margin: 4px 0; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; padding: 16px; }
  .preview { position: static; }
  .paper { width: 100%; min-width: 0; }
  .masthead-inner { padding-left: 70px; }
}

@media (max-width: 640px) {
  .masthead-inner { flex-wrap: wrap; }
  .mode-link { margin-left: 0; }
}

@media (max-width: 420px) {
  .masthead h1 { font-size: 26px; }
  .letter-grid { grid-template-columns: repeat(7, 1fr); }
  .actions { width: 100%; }
  .actions .button { flex: 1; }
}
