:root {
  --ink: #173d32;
  --ink-soft: #42665a;
  --ink-deep: #102b24;
  --brass: #b18442;
  --brass-dark: #805b24;
  --paper: #fffdf8;
  --paper-warm: #f7f2e7;
  --line: #d7d4c8;
  --line-strong: #aeb8a9;
  --danger: #a34d42;
  --shadow: 0 22px 42px rgba(27, 56, 44, 0.1);
  --radius: 16px;
  color: var(--ink);
  font-family: "Hiragino Sans", "Yu Gothic", "Noto Sans JP", system-ui, sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  overflow-x: hidden;
  background: #eae7dc;
}

body {
  margin: 0;
  min-width: 320px;
  background-color: var(--paper-warm);
  background-image:
    linear-gradient(rgba(33, 81, 66, 0.065) 1px, transparent 1px),
    linear-gradient(90deg, rgba(33, 81, 66, 0.065) 1px, transparent 1px),
    linear-gradient(rgba(177, 132, 66, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(177, 132, 66, 0.035) 1px, transparent 1px);
  background-size: 32px 32px, 32px 32px, 8px 8px, 8px 8px;
  line-height: 1.6;
  overflow-x: hidden;
}

button,
input,
select {
  font: inherit;
}

button,
select,
input {
  -webkit-tap-highlight-color: transparent;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

a {
  color: inherit;
}

.page-shell {
  width: min(1180px, calc(100% - 40px));
  margin-inline: auto;
}

.site-header {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  width: min(1180px, calc(100% - 40px));
  margin: 0 auto;
  padding: 20px 0 16px;
  border-bottom: 1px solid rgba(23, 61, 50, 0.16);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  color: var(--ink);
  text-decoration: none;
  min-height: 44px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--brass-dark);
  border-radius: 50%;
  color: var(--paper);
  background: var(--ink);
  font-family: Georgia, serif;
  font-size: 18px;
  font-style: italic;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 15px;
  letter-spacing: 0.08em;
}

.brand small {
  margin-top: 1px;
  color: var(--brass-dark);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.18em;
}

.site-nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 5px 18px;
  color: var(--ink-soft);
  font-size: 13px;
}

.site-nav a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  text-decoration: none;
}

.site-nav a:hover,
.site-nav a:focus-visible {
  color: var(--brass-dark);
  text-decoration: underline;
  text-underline-offset: 4px;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(300px, 0.95fr);
  align-items: center;
  gap: clamp(34px, 7vw, 92px);
  min-height: 420px;
  padding: 62px 0 66px;
}

.hero-copy,
.hero-visual,
main {
  min-width: 0;
}

.eyebrow,
.section-label,
.note-number {
  margin: 0 0 10px;
  color: var(--brass-dark);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.19em;
}

.hero h1 {
  max-width: 650px;
  margin: 0;
  color: var(--ink-deep);
  font-family: Georgia, "Yu Mincho", serif;
  font-size: clamp(37px, 5.1vw, 70px);
  font-weight: 700;
  letter-spacing: -0.045em;
  line-height: 1.13;
  overflow-wrap: anywhere;
}

.hero h1 em {
  position: relative;
  color: var(--brass-dark);
  font-style: normal;
}

.hero h1 em::after {
  position: absolute;
  right: 0;
  bottom: -8px;
  left: 4px;
  height: 6px;
  border-top: 1px solid var(--brass);
  border-bottom: 1px solid var(--brass);
  content: "";
  opacity: 0.6;
}

.hero-lede {
  max-width: 610px;
  margin: 27px 0 0;
  color: var(--ink-soft);
  font-size: 16px;
}

.hero-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 27px;
}

.hero-badges span,
.count-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 11px;
  border: 1px solid rgba(128, 91, 36, 0.36);
  border-radius: 999px;
  color: var(--brass-dark);
  background: rgba(255, 253, 248, 0.58);
  font-size: 11px;
  font-weight: 700;
}

.hero-visual {
  position: relative;
  min-height: 285px;
  border: 1px solid rgba(23, 61, 50, 0.36);
  border-radius: 8px 30px 8px 30px;
  background:
    linear-gradient(135deg, rgba(255, 253, 248, 0.2), rgba(23, 61, 50, 0.24)),
    url('/assets/workbench-hero.webp');
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  box-shadow: 12px 14px 0 rgba(177, 132, 66, 0.32), var(--shadow);
  overflow: hidden;
}

.hero-visual::before {
  position: absolute;
  inset: 15px;
  border: 1px dashed rgba(128, 91, 36, 0.5);
  border-radius: 4px 20px 4px 20px;
  content: "";
}

.visual-corner {
  position: absolute;
  width: 54px;
  height: 54px;
  border-color: var(--brass-dark);
  border-style: solid;
}

.visual-corner-top {
  top: 25px;
  left: 25px;
  border-width: 2px 0 0 2px;
}

.visual-corner-bottom {
  right: 25px;
  bottom: 25px;
  border-width: 0 2px 2px 0;
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.07fr) minmax(320px, 0.93fr);
  align-items: start;
  gap: 24px;
}

.paper-card {
  border: 1px solid rgba(23, 61, 50, 0.16);
  border-radius: var(--radius);
  background: rgba(255, 253, 248, 0.94);
  box-shadow: 0 12px 30px rgba(27, 56, 44, 0.075);
}

.builder-card,
.preview-card,
.examples-card,
.save-card,
.saved-list-card {
  padding: clamp(22px, 3vw, 34px);
}

.preview-card {
  position: sticky;
  top: 16px;
}

.section-heading,
.list-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}

.section-heading h2,
.list-heading h3,
.note-card h2 {
  margin: 0;
  color: var(--ink-deep);
  font-family: Georgia, "Yu Mincho", serif;
  letter-spacing: -0.025em;
}

.section-heading h2 {
  font-size: clamp(22px, 3vw, 31px);
  line-height: 1.25;
}

.brass-index {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 35px;
  height: 35px;
  border: 1px solid var(--brass-dark);
  border-radius: 50%;
  color: var(--paper);
  background: var(--brass-dark);
  font-family: Georgia, serif;
  font-size: 17px;
}

.function-picker {
  margin-top: 27px;
  padding: 16px;
  border-left: 3px solid var(--brass);
  background: rgba(235, 239, 228, 0.7);
}

.function-picker > label,
.save-card > label {
  display: block;
  margin-bottom: 7px;
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.06em;
}

.control {
  display: block;
  width: 100%;
  min-height: 46px;
  padding: 9px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  outline: none;
  color: var(--ink-deep);
  background: #fffefb;
  font-size: 16px;
}

.control:focus {
  border-color: var(--brass-dark);
  box-shadow: 0 0 0 3px rgba(177, 132, 66, 0.22);
}

.control-select {
  appearance: none;
  padding-right: 38px;
  background-image: linear-gradient(45deg, transparent 50%, var(--brass-dark) 50%), linear-gradient(135deg, var(--brass-dark) 50%, transparent 50%);
  background-position: calc(100% - 17px) 20px, calc(100% - 12px) 20px;
  background-repeat: no-repeat;
  background-size: 5px 5px, 5px 5px;
}

.field-help,
.microcopy,
.section-lede,
.inline-status,
.result-block p {
  color: var(--ink-soft);
  font-size: 12px;
}

.field-help {
  margin: 7px 0 0;
}

.form-fieldset {
  min-width: 0;
  margin: 23px 0 0;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.fieldset-legend {
  padding: 0 6px;
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.condition-grid,
.value-row,
.output-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 13px;
}

.condition-grid > .field-group:first-child,
.condition-grid > .field-group:nth-child(3) {
  grid-column: span 1;
}

.field-group {
  min-width: 0;
}

.field-label {
  display: block;
  margin: 0 0 6px;
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 700;
}

.value-row {
  align-items: end;
  grid-template-columns: minmax(0, 1fr) 130px;
}

.value-row + .value-row {
  margin-top: 14px;
}

.form-actions,
.save-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 11px;
  margin-top: 22px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: 9px 15px;
  border: 1px solid transparent;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 800;
  line-height: 1.2;
  text-align: center;
  transition: transform 120ms ease, box-shadow 120ms ease, background 120ms ease;
}

.button:hover:not(:disabled) {
  transform: translateY(-1px);
}

.button:focus-visible {
  outline: 3px solid rgba(177, 132, 66, 0.45);
  outline-offset: 2px;
}

.button-primary {
  border-color: var(--ink);
  color: var(--paper);
  background: var(--ink);
  box-shadow: 3px 3px 0 rgba(177, 132, 66, 0.5);
}

.button-secondary,
.button-quiet {
  border-color: var(--line-strong);
  color: var(--ink);
  background: #fffefb;
}

.button-danger {
  border-color: rgba(163, 77, 66, 0.38);
  color: var(--danger);
  background: #fff7f3;
}

.condition-remove {
  margin-top: 12px;
  font-size: 12px;
}

.notice {
  margin-top: 16px;
  padding: 11px 13px;
  border-radius: 8px;
  font-size: 13px;
}

.notice-warning {
  border: 1px solid rgba(128, 91, 36, 0.45);
  color: #6f4b18;
  background: #fbf3df;
}

.notice-error {
  border: 1px solid rgba(163, 77, 66, 0.42);
  color: #8b3f36;
  background: #fff4f1;
}

.formula-surface {
  display: flex;
  align-items: center;
  min-height: 112px;
  margin: 30px 0 15px;
  padding: 20px;
  border: 1px solid rgba(23, 61, 50, 0.18);
  border-radius: 8px;
  background: #edf0e8;
  overflow-x: auto;
}

.formula-surface code,
.saved-formula {
  color: var(--ink-deep);
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 14px;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.preview-card > .button-secondary {
  width: 100%;
}

.inline-status {
  min-height: 20px;
  margin: 9px 0 0;
}

.result-block {
  margin-top: 29px;
  padding: 16px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.result-label {
  display: block;
  color: var(--brass-dark);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.1em;
}

.result-block strong {
  display: block;
  margin-top: 3px;
  color: var(--ink-deep);
  font-family: Georgia, serif;
  font-size: 32px;
}

.result-block p {
  margin: 3px 0 0;
}

.privacy-note {
  margin-top: 17px;
  color: var(--ink-soft);
  font-size: 11px;
}

.privacy-note span {
  color: var(--brass-dark);
}

.examples-card {
  margin-top: 24px;
}

.section-lede {
  max-width: 700px;
  margin: 15px 0 19px;
  font-size: 14px;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 9px;
}

.example-table {
  width: 100%;
  min-width: 420px;
  border-collapse: collapse;
  background: rgba(255, 255, 255, 0.45);
  font-size: 13px;
}

.example-table th,
.example-table td {
  padding: 11px 13px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

.example-table th {
  color: var(--ink-soft);
  background: #eef1e9;
  font-size: 11px;
  letter-spacing: 0.06em;
}

.example-table tr:last-child td {
  border-bottom: 0;
}

.expected-strip {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px 13px;
  margin-top: 17px;
  padding: 13px 15px;
  border-left: 3px solid var(--brass);
  background: #fbf4e4;
}

.expected-strip span,
.expected-strip small {
  color: var(--brass-dark);
  font-size: 12px;
}

.expected-strip strong {
  color: var(--ink-deep);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 18px;
}

.saved-layout {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
  gap: 24px;
  margin-top: 24px;
}

.save-card .control {
  margin-top: 6px;
}

.saved-list-card {
  min-width: 0;
}

.list-heading {
  align-items: center;
}

.list-heading h3 {
  font-size: 21px;
}

.saved-list {
  margin-top: 18px;
}

.empty-state {
  margin: 0;
  padding: 22px 0;
  color: var(--ink-soft);
  font-size: 13px;
}

.saved-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 15px;
  padding: 14px 0;
  border-top: 1px solid var(--line);
}

.saved-details {
  min-width: 0;
}

.saved-name,
.saved-function,
.saved-formula {
  display: block;
}

.saved-name {
  overflow-wrap: anywhere;
  font-size: 14px;
}

.saved-function {
  margin-top: 2px;
  color: var(--brass-dark);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.12em;
}

.saved-formula {
  max-width: 430px;
  margin-top: 4px;
  color: var(--ink-soft);
  font-size: 11px;
}

.saved-actions {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  gap: 6px;
}

.saved-actions .button {
  min-height: 44px;
  padding-inline: 10px;
  font-size: 11px;
}

.notes-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 24px;
  margin-top: 24px;
}

.note-card {
  padding: 24px;
  border-top: 2px solid var(--brass);
  background: rgba(255, 253, 248, 0.65);
}

.note-card h2 {
  font-size: 21px;
}

.note-card p {
  margin: 11px 0 0;
  color: var(--ink-soft);
  font-size: 13px;
}

.site-footer {
  display: flex;
  justify-content: space-between;
  gap: 15px;
  padding: 34px 0 40px;
  color: var(--ink-soft);
  font-size: 11px;
}

.noscript-message {
  position: fixed;
  inset: auto 16px 16px;
  z-index: 10;
  padding: 15px;
  border: 1px solid var(--danger);
  border-radius: 8px;
  color: var(--danger);
  background: #fff4f1;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 820px) {
  .hero,
  .workspace-grid,
  .saved-layout {
    grid-template-columns: 1fr;
  }

  .hero {
    gap: 38px;
    min-height: 0;
    padding-top: 46px;
  }

  .hero-visual {
    min-height: 235px;
  }

  .preview-card {
    position: static;
  }
}

@media (max-width: 560px) {
  .page-shell,
  .site-header {
    width: min(100% - 24px, 1180px);
  }

  .site-header {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
    padding-top: 12px;
  }

  .site-nav {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: 100%;
    gap: 6px;
  }

  .site-nav a {
    justify-content: center;
    min-width: 0;
    text-align: center;
  }

  .hero h1 em {
    overflow-wrap: anywhere;
  }

  .site-nav a {
    font-size: 12px;
  }

  .hero {
    padding: 39px 0 48px;
  }

  .hero h1 {
    font-size: clamp(34px, 12vw, 52px);
  }

  .hero-lede {
    font-size: 15px;
  }

  .hero-visual {
    min-height: 200px;
    box-shadow: 7px 8px 0 rgba(177, 132, 66, 0.32), var(--shadow);
  }

  .builder-card,
  .preview-card,
  .examples-card,
  .save-card,
  .saved-list-card {
    padding: 19px 15px;
  }

  .condition-grid,
  .output-grid {
    grid-template-columns: 1fr;
  }

  .value-row {
    grid-template-columns: minmax(0, 1fr);
  }

  .form-actions,
  .save-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .form-actions .button,
  .save-actions .button {
    width: 100%;
  }

  .microcopy {
    text-align: center;
  }

  .saved-item {
    align-items: stretch;
    flex-direction: column;
  }

  .saved-actions {
    width: 100%;
  }

  .saved-actions .button {
    flex: 1;
  }

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

  .site-footer {
    flex-direction: column;
    padding-bottom: 28px;
  }
}

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

  .site-header,
  .hero-visual,
  .site-nav,
  .form-actions,
  .save-actions,
  .saved-layout,
  .notes-grid,
  .privacy-note,
  .copy-status,
  .site-footer,
  .button,
  #version-notice,
  #validation-message {
    display: none !important;
  }

  .page-shell {
    width: 100%;
  }

  .hero {
    display: block;
    min-height: 0;
    padding: 0 0 20px;
  }

  .workspace-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .preview-card {
    position: static;
  }

  .paper-card {
    box-shadow: none;
    break-inside: avoid;
  }
}
