:root {
  color-scheme: light;
  --linen: #f7f0e4;
  --paper: #fffaf2;
  --paper-deep: #f0e4d3;
  --berry: #b94363;
  --berry-dark: #7f2945;
  --ink: #254b63;
  --ink-soft: #587080;
  --sage: #7c9a84;
  --gold: #e6ba55;
  --line: #dacbb9;
  --shadow: 0 18px 50px rgba(52, 39, 35, .08);
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", system-ui, sans-serif;
  background: var(--linen);
  color: #382f2c;
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--linen); }

body {
  margin: 0;
  min-width: 320px;
  background:
    radial-gradient(circle at 15% 0%, rgba(230, 186, 85, .12), transparent 25rem),
    var(--linen);
  line-height: 1.6;
}

button, input { font: inherit; }

button {
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  transition: border-color .18s ease, background-color .18s ease, transform .18s ease;
}

button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { cursor: not-allowed; opacity: .45; }
button:focus-visible, input:focus-visible, [role="gridcell"]:focus-visible {
  outline: 3px solid rgba(230, 186, 85, .9);
  outline-offset: 2px;
}

.site-header {
  position: relative;
  display: flex;
  min-height: 178px;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  overflow: hidden;
  padding: 24px max(20px, calc((100vw - 1120px) / 2));
  background: var(--ink);
  color: var(--paper);
}

.site-header::after {
  position: absolute;
  right: 8%;
  bottom: -46px;
  width: 160px;
  height: 160px;
  border: 1px solid rgba(255, 250, 242, .22);
  border-radius: 50%;
  content: "";
}

.header-copy { position: relative; z-index: 1; max-width: 530px; }
.kicker, .eyebrow {
  margin: 0 0 7px;
  color: var(--berry);
  font-size: .72rem;
  font-weight: 800;
  letter-spacing: .16em;
}
.site-header .kicker { color: var(--gold); }
.brand-name { margin: 0; font-family: Georgia, serif; font-size: clamp(1.7rem, 4vw, 2.5rem); letter-spacing: .08em; }
.header-lead { margin: 5px 0 0; color: rgba(255, 250, 242, .8); font-size: .95rem; }
.header-art { position: absolute; top: 0; right: 0; width: min(46%, 470px); height: 100%; object-fit: cover; object-position: right center; opacity: .22; mix-blend-mode: screen; }

.page-shell { width: min(1120px, calc(100% - 32px)); margin: 28px auto 42px; }
.intro-card, .editor-card, .info-card { border: 1px solid rgba(218, 203, 185, .9); background: rgba(255, 250, 242, .88); box-shadow: var(--shadow); }
.intro-card { display: flex; align-items: center; justify-content: space-between; gap: 1.5rem; padding: clamp(22px, 4vw, 42px); border-radius: 24px; }
h1, h2, h3 { line-height: 1.2; }
h1 { margin: 0; color: var(--ink); font-family: Georgia, "Times New Roman", serif; font-size: clamp(2rem, 5vw, 3.6rem); font-weight: 500; letter-spacing: .02em; }
h2 { margin: 0; color: var(--ink); font-family: Georgia, "Times New Roman", serif; font-size: clamp(1.55rem, 3vw, 2.15rem); font-weight: 600; }
h3 { margin: 0; color: var(--ink); font-size: 1rem; }
.intro-copy { max-width: 610px; margin: 13px 0 0; color: var(--ink-soft); }
.intro-note { display: grid; min-width: 150px; gap: 2px; padding: 16px; border-left: 3px solid var(--berry); color: var(--berry-dark); }
.intro-note span { font-size: .7rem; font-weight: 800; letter-spacing: .18em; }
.intro-note strong { font-family: Georgia, serif; font-size: 1.8rem; line-height: 1.2; }
.intro-note small { color: var(--ink-soft); font-size: .72rem; }

.editor-card { margin-top: 20px; padding: clamp(18px, 3vw, 32px); border-radius: 24px; }
.section-heading, .grid-stage-heading, .tool-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; }
.grid-summary, .tool-status, .grid-direction { color: var(--ink-soft); font-size: .82rem; }
.app-error { margin: 16px 0 0; padding: 11px 13px; border: 1px solid #c95c66; border-radius: 10px; background: #fff0ed; color: #8e263e; }
.project-title-row { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 14px; margin-top: 24px; }
label { color: var(--ink); font-size: .84rem; font-weight: 700; }
input { width: 100%; min-height: 44px; border: 1px solid var(--line); border-radius: 9px; background: #fffdf9; color: #382f2c; font-size: 16px; padding: 8px 11px; }
input:hover { border-color: var(--ink-soft); }

.editor-layout { display: grid; grid-template-columns: minmax(205px, 260px) minmax(0, 1fr); gap: clamp(20px, 4vw, 42px); margin-top: 28px; }
.tool-panel { display: grid; align-content: start; gap: 0; }
.tool-section { padding: 0 0 22px; margin-bottom: 22px; border-bottom: 1px solid var(--line); }
.tool-section:last-child { border-bottom: 0; margin-bottom: 0; }
.palette { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; margin-top: 12px; }
.palette-button { display: grid; min-height: 52px; place-items: center; gap: 0; padding: 4px; border: 2px solid transparent; background: var(--swatch); color: var(--swatch-ink); }
.palette-button span { font-size: 1.18rem; line-height: 1; }
.palette-button small { max-width: 100%; overflow: hidden; font-size: .62rem; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.palette-button.is-selected { border-color: var(--berry); box-shadow: 0 0 0 2px var(--paper), 0 0 0 4px var(--berry); }
.usage-card { margin-top: 14px; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fffdf9; }
.usage-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; color: var(--ink-soft); font-size: .72rem; }
.usage-heading strong { color: var(--ink); font-family: Georgia, serif; font-size: .9rem; white-space: nowrap; }
.usage-list { display: grid; gap: 5px; margin: 9px 0 0; padding: 0; list-style: none; }
.usage-item { display: grid; grid-template-columns: 24px minmax(0, 1fr) auto; align-items: center; gap: 6px; color: var(--ink-soft); font-size: .74rem; }
.usage-symbol { display: grid; width: 23px; height: 23px; place-items: center; border-radius: 6px; background: var(--usage-color); color: var(--ink); font-family: Georgia, serif; font-size: .88rem; font-weight: 700; }
.usage-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.usage-item strong { color: var(--ink); font-size: .74rem; }
.usage-empty { margin: 8px 0 0; color: var(--ink-soft); font-size: .72rem; }
.tool-toggle { display: grid; grid-template-columns: repeat(2, 1fr); gap: 7px; margin-top: 14px; }
.tool-toggle > :last-child { grid-column: 1 / -1; }
.tool-button, .secondary-button { border-color: var(--line); background: var(--paper); color: var(--ink); }
.tool-button.is-active { border-color: var(--ink); background: var(--ink); color: var(--paper); }
.hint, .section-description, .grid-footnote { margin: 10px 0 0; color: var(--ink-soft); font-size: .78rem; }
.inline-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.inline-fields label { display: grid; gap: 5px; font-size: .72rem; }
.secondary-button, .primary-button { padding: 8px 13px; font-size: .82rem; font-weight: 700; }
.secondary-button:hover:not(:disabled) { border-color: var(--ink); background: #f4ecdf; }
.primary-button { border-color: var(--berry); background: var(--berry); color: #fffaf2; }
.primary-button:hover:not(:disabled) { background: var(--berry-dark); }
.tool-section .secondary-button { width: 100%; margin-top: 10px; }
.gauge-result { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-top: 13px; padding: 12px; border-radius: 10px; background: #eef1eb; color: var(--ink); }
.gauge-result span:first-child { font-size: .72rem; font-weight: 700; }
.gauge-result strong { font-family: Georgia, serif; font-size: 1.22rem; }
.gauge-result small { margin-left: 2px; font-family: inherit; font-size: .7rem; }

.grid-stage { min-width: 0; }
.grid-stage-heading { margin-bottom: 13px; }
.grid-scroll { width: 100%; max-width: 720px; margin: 0 auto; overflow: auto; border: 2px solid var(--ink); background: var(--ink); overscroll-behavior: contain; }
.grid-scroll:focus-visible { outline: 3px solid rgba(230, 186, 85, .9); outline-offset: 2px; }
.stitch-grid { display: grid; grid-template-columns: repeat(var(--grid-cols, 10), minmax(28px, 1fr)); width: max(100%, calc(var(--grid-cols, 10) * 28px)); margin: 0; background: var(--ink); touch-action: none; user-select: none; }
.stitch-grid.is-pan { cursor: grab; touch-action: pan-x pan-y; }
.stitch-grid.is-pan:active { cursor: grabbing; }
.grid-cell { display: grid; min-width: 0; min-height: 0; aspect-ratio: 1; place-items: center; padding: 0; border: 0; border-right: 1px solid rgba(37, 75, 99, .55); border-bottom: 1px solid rgba(37, 75, 99, .55); border-radius: 0; background: var(--cell-color); color: var(--cell-ink); font-family: Georgia, serif; font-size: clamp(.7rem, 2.4vw, 1.05rem); font-weight: 700; line-height: 1; }
.grid-cell:hover { filter: brightness(.96); }
.grid-footnote { text-align: center; }
.action-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-top: 28px; padding-top: 22px; border-top: 1px solid var(--line); }
.history-actions, .file-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.info-grid { display: grid; grid-template-columns: minmax(0, .85fr) minmax(0, 1.15fr); gap: 20px; margin-top: 20px; }
.info-card { padding: clamp(20px, 3vw, 30px); border-radius: 20px; }
.info-card ol { margin: 15px 0 0; padding-left: 1.35rem; color: var(--ink-soft); }
.info-card li + li { margin-top: 8px; }
.info-card p:not(.eyebrow) { color: var(--ink-soft); font-size: .88rem; }
.info-card p:last-child { margin-bottom: 0; }
.article-links { margin-top: 20px; padding: clamp(18px, 3vw, 30px); border: 1px solid var(--line); border-radius: 24px; background: rgba(255, 250, 242, .88); box-shadow: var(--shadow); }
.article-links-heading { max-width: 650px; }
.article-links-heading > p:last-child { margin: 9px 0 0; color: var(--ink-soft); }
.article-index-link { display: inline-flex; min-height: 44px; align-items: center; margin-top: 5px; font-weight: 700; }
.article-link-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-top: 18px; }
.article-link-card { display: grid; align-content: start; gap: 8px; min-height: 150px; padding: 16px; border: 1px solid var(--line); border-radius: 14px; background: #fffdf9; color: var(--ink); text-decoration: none; }
.article-link-card:hover { border-color: var(--berry); background: #fff7f5; }
.article-link-card:focus-visible { outline: 3px solid rgba(230, 186, 85, .9); outline-offset: 2px; }
.article-link-card > span { color: var(--berry-dark); font-size: .74rem; font-weight: 800; letter-spacing: .06em; }
.article-link-card strong { line-height: 1.45; }
.article-link-card small { color: var(--ink-soft); font-size: .82rem; }
.site-footer { display: flex; justify-content: space-between; gap: 1rem; width: min(1120px, calc(100% - 32px)); margin: 0 auto 32px; color: var(--ink-soft); font-size: .75rem; }
.print-sheet { display: none; }

@media (max-width: 820px) {
  .editor-layout { grid-template-columns: 1fr; }
  .tool-panel { grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 18px; }
  .tool-section { margin-bottom: 0; }
  .tool-section:last-child { grid-column: 1 / -1; margin-top: 18px; }
  .grid-stage { grid-row: 1; }
  .palette { grid-template-columns: repeat(6, minmax(0, 1fr)); }
}

@media (max-width: 580px) {
  .site-header { min-height: 150px; padding: 20px 16px; }
  .header-art { width: 66%; opacity: .18; }
  .page-shell { width: min(100% - 20px, 1120px); margin-top: 14px; }
  .intro-card { display: block; padding: 22px 18px; }
  .intro-note { margin-top: 20px; padding: 10px 0 0; border-top: 1px solid var(--line); border-left: 0; }
  .editor-card { padding: 16px 12px; border-radius: 18px; }
  .project-title-row { grid-template-columns: 1fr; gap: 5px; margin-top: 18px; }
  .tool-panel { display: block; }
  .tool-section { padding-bottom: 18px; margin-bottom: 18px; }
  .palette { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid-direction { display: none; }
  .action-bar { align-items: stretch; }
  .history-actions, .file-actions { width: 100%; }
  .history-actions > *, .file-actions > * { flex: 1 1 auto; }
  .info-grid { grid-template-columns: 1fr; gap: 12px; }
  .article-link-grid { grid-template-columns: 1fr; }
  .article-link-card { min-height: 0; }
  .site-footer { display: grid; width: min(100% - 20px, 1120px); }
}

@media (max-width: 340px) {
  .site-header { padding-inline: 12px; }
  .page-shell { width: calc(100% - 12px); }
  .editor-card { padding-inline: 9px; }
  .file-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .file-actions > :first-child { grid-column: 1 / -1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}

@media print {
  @page { margin: 12mm; }
  body { background: white; }
  .site-header, .intro-card, .editor-card, .info-grid, .article-links, .site-footer, .app-error { display: none !important; }
  .page-shell { width: 100%; margin: 0; }
  .print-sheet { display: block; color: #382f2c; }
  .print-sheet h2 { margin: 0; font-size: 20pt; }
  .print-sheet > p { margin: 3mm 0; font-size: 9pt; }
  .print-sheet svg { display: block; width: 100%; max-width: 180mm; max-height: 245mm; height: auto; margin: 5mm auto 0; print-color-adjust: exact; -webkit-print-color-adjust: exact; }
  .print-note { break-inside: avoid; }
}

/* SOU100 Stage A: first-view */
.intro-card { padding: 18px 22px; gap: clamp(16px, 3vw, 34px); }
.intro-card h1 { font-size: clamp(1.9rem, 3.5vw, 3rem); line-height: 1.12; letter-spacing: -.035em; word-break: auto-phrase; }
.intro-copy-lede { margin: 10px 0; line-height: 1.5; }
.intro-note { max-width: 250px; }
.hero-steps { display: flex; flex-wrap: wrap; gap: 6px 16px; list-style: none; counter-reset: stage; padding: 0; margin: 10px 0 0; }
.hero-steps li { counter-increment: stage; position: relative; padding-left: 1.35rem; font-size: .86rem; line-height: 1.4; }
.hero-steps li::before { content: counter(stage); position: absolute; left: 0; top: .08em; font-weight: 800; }
.hero-cta { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; margin-top: 10px; padding: 9px 17px; border: 2px solid #203c34; border-radius: 999px; background: #203c34; color: #fff; font-weight: 750; line-height: 1.25; text-decoration: none; }
.hero-cta:focus-visible { outline: 3px solid #fff; outline-offset: 3px; box-shadow: 0 0 0 6px #203c34; }
.hero-privacy { margin: 7px 0 0; font-size: .78rem; line-height: 1.45; }
@media (max-width: 640px) {
  .intro-card { padding: 14px 15px; gap: 10px; }
  .header-art { display: none; }
  .intro-card h1 { font-size: clamp(1.75rem, 8vw, 2.05rem); line-height: 1.14; }
  .intro-copy-lede { margin: 7px 0; font-size: .94rem; line-height: 1.42; }
  .hero-steps { flex-direction: column; gap: 4px; margin-top: 7px; }
  .hero-steps li { font-size: .83rem; }
  .hero-cta { margin-top: 8px; }
  .editor-card .section-heading .eyebrow { display: none; }
  .editor-card .section-heading h2 { font-size: 1.15rem; }
  .editor-card .section-heading { margin-bottom: .7rem; }
}
