:root {
  color-scheme: light;
  --page: #f6f7f4;
  --surface: #ffffff;
  --surface-soft: #edf3f0;
  --ink: #17201c;
  --muted: #5c6962;
  --line: #ced8d2;
  --brand: #146b4b;
  --brand-dark: #0e543a;
  --accent: #d7f163;
  --focus: #8b3dff;
  --danger: #b3261e;
  --shadow: 0 18px 50px rgba(24, 49, 38, 0.08);
  --radius: 18px;
  font-family: Inter, "Noto Sans JP", "Yu Gothic UI", Meiryo, sans-serif;
  font-synthesis: none;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  min-width: 320px;
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-size: 1rem;
  line-height: 1.7;
}

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

button,
select,
summary {
  cursor: pointer;
}

a {
  color: var(--brand-dark);
  text-underline-offset: 0.2em;
}

a:hover {
  text-decoration-thickness: 2px;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.skip-link {
  position: fixed;
  top: 0.75rem;
  left: 0.75rem;
  z-index: 1000;
  padding: 0.65rem 1rem;
  border-radius: 0.5rem;
  background: var(--ink);
  color: #fff;
  transform: translateY(-180%);
}

.skip-link:focus {
  transform: translateY(0);
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  width: min(1180px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 1.25rem 0;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  color: var(--ink);
  font-size: 1rem;
  font-weight: 750;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 2rem;
  height: 2rem;
  place-items: center;
  border-radius: 0.55rem;
  background: var(--brand);
  color: #fff;
  font-weight: 850;
}

.site-header nav,
.site-footer nav {
  display: flex;
  gap: 1.25rem;
}

.site-header nav a {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 650;
  text-decoration: none;
  white-space: nowrap;
  word-break: keep-all;
}

main {
  width: min(1180px, calc(100% - 2rem));
  margin: 0 auto;
}

.hero {
  max-width: 760px;
  padding: clamp(1rem, 2vw, 1.75rem) 0 clamp(1rem, 2vw, 1.5rem);
}

.eyebrow,
.step {
  margin: 0 0 0.5rem;
  color: var(--brand);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  overflow-wrap: anywhere;
}

h1 {
  margin: 0;
  font-size: clamp(1.85rem, 4vw, 3rem);
  font-weight: 790;
  letter-spacing: -0.045em;
  line-height: 1.05;
}

.hero-copy {
  max-width: 650px;
  margin: 0.75rem 0 0;
  color: var(--muted);
  font-size: clamp(1rem, 1.5vw, 1.1rem);
}

.boundary-note {
  max-width: 700px;
  margin: 0.75rem 0 0;
  padding: 0.65rem 0.8rem;
  border-left: 1px solid var(--brand);
  background: var(--surface-soft);
  font-size: 0.94rem;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.12fr) minmax(320px, 0.88fr);
  gap: 1.25rem;
  align-items: start;
}

.builder-card,
.result-card,
.saved-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.builder-card,
.result-card {
  padding: clamp(1.25rem, 3vw, 2rem);
}

.result-card {
  position: sticky;
  top: 1rem;
}

.section-heading {
  margin-bottom: 1.35rem;
}

.section-heading h2,
.info-section h2 {
  margin: 0;
  font-size: clamp(1.35rem, 3vw, 1.8rem);
  line-height: 1.35;
}

.field {
  min-width: 0;
  margin-bottom: 1.15rem;
}

.field label {
  display: inline-block;
  margin-bottom: 0.35rem;
  font-weight: 720;
}

.required-label {
  margin-left: 0.35rem;
  color: var(--danger);
  font-size: 0.78rem;
}

.field-help {
  margin: 0 0 0.45rem;
  color: var(--muted);
  font-size: 0.86rem;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #aebbb4;
  border-radius: 0.7rem;
  background: #fff;
  padding: 0.78rem 0.85rem;
}

textarea {
  min-height: 5.5rem;
  line-height: 1.6;
  resize: vertical;
}

.field-primary textarea {
  min-height: 10rem;
}

input:hover,
select:hover,
textarea:hover {
  border-color: #77877f;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--brand);
}

[aria-invalid="true"] {
  border-color: var(--danger);
  box-shadow: 0 0 0 2px rgba(179, 38, 30, 0.15);
}

.field-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.field-row-top {
  margin-top: 1.35rem;
}

.advanced-settings {
  margin: 0.3rem 0 1.5rem;
  border: 1px solid var(--line);
  border-radius: 0.8rem;
}

.advanced-settings summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 1rem;
  font-weight: 750;
  list-style-position: inside;
}

.advanced-settings summary::marker {
  color: var(--brand);
}

.summary-hint {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 500;
}

.advanced-content {
  padding: 1.15rem 1rem 0;
  border-top: 1px solid var(--line);
}

.settings-group {
  min-width: 0;
  margin: 1.3rem 0;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 0.8rem;
  background: var(--surface-soft);
}

.settings-group legend {
  padding: 0 0.45rem;
  color: var(--brand-dark);
  font-weight: 800;
}

.settings-group > .field-help {
  margin: 0 0 1rem;
}

.field-row-compact {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.subject-detail-panel {
  margin: 1rem 0 1.25rem;
  padding: clamp(1rem, 2.5vw, 1.35rem);
  border: 2px solid #d49300;
  border-radius: var(--radius);
  background: linear-gradient(145deg, #fff8dc, #fffdf4 58%, #f1f8f4);
  box-shadow: 0 12px 28px rgba(91, 65, 0, 0.12);
}

.subject-detail-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.9rem;
}

.subject-detail-heading h2,
.subject-detail-heading p {
  margin: 0;
}

.subject-detail-heading .step {
  margin-bottom: 0.2rem;
  color: #8a5a00;
}

.subject-detection-controls {
  display: grid;
  grid-template-columns: auto minmax(8rem, auto);
  align-items: center;
  gap: 0.35rem 0.55rem;
  flex: 0 0 auto;
}

.subject-detection-controls label {
  font-size: 0.8rem;
  font-weight: 700;
}

.subject-detection-controls select {
  min-width: 9rem;
}

.subject-detection-badge {
  grid-column: 1 / -1;
  display: inline-flex;
  justify-content: center;
  padding: 0.35rem 0.65rem;
  border: 1px solid #d9ae4a;
  border-radius: 999px;
  background: #fff;
  color: #684600;
  font-size: 0.78rem;
  font-weight: 750;
}

.subject-detail-workspace .catalog-group {
  border-color: #dfb44f;
  background: rgba(255, 255, 255, 0.82);
}

.subject-detail-workspace .catalog-group-summary {
  background: #fff4c7;
}

.catalog-controls {
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--line);
}

.catalog-intro {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1.25rem;
  margin-bottom: 0.8rem;
}

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

.global-random-actions {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.global-random-actions label {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.global-random-actions select {
  width: auto;
  min-width: 7rem;
}

.selection-summary {
  min-height: 2.5rem;
  margin: 0 0 1rem;
  padding: 0.7rem 0.85rem;
  border-radius: 0.65rem;
  background: #e7f1ec;
  color: var(--brand-dark);
  font-size: 0.86rem;
  font-weight: 650;
}

.category-workspace {
  display: grid;
  gap: 0.9rem;
}

.catalog-group {
  overflow: clip;
  border: 1px solid var(--line);
  border-radius: 0.9rem;
  background: var(--surface);
}

.catalog-group-summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 0.75rem;
  padding: 0.8rem 0.9rem;
  background: #e9f2ed;
  list-style-position: inside;
}

.catalog-group-summary::marker {
  color: var(--brand);
}

.catalog-enable {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  min-width: 0;
  font-weight: 850;
}

.catalog-enable input {
  width: 1.15rem;
  height: 1.15rem;
  accent-color: var(--brand);
}

.catalog-group-count {
  color: var(--muted);
  font-size: 0.78rem;
  white-space: nowrap;
}

.catalog-group-body {
  display: grid;
  gap: 1rem;
  padding: 0.9rem;
}

.catalog-group.is-disabled .catalog-group-body {
  opacity: 0.42;
  filter: grayscale(0.65);
  pointer-events: none;
}

.option-row {
  min-width: 0;
  padding-bottom: 0.8rem;
  border-bottom: 1px solid #e2e9e5;
}

.option-row:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.option-row-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  margin-bottom: 0.55rem;
}

.option-row-title {
  display: flex;
  align-items: baseline;
  gap: 0.55rem;
  min-width: 0;
}

.option-row-title h3 {
  margin: 0;
  font-size: 0.98rem;
}

.option-mode,
.option-selected-count {
  color: var(--muted);
  font-size: 0.72rem;
  white-space: nowrap;
}

.option-row-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.catalog-mini-button {
  min-height: 2rem;
  padding: 0.25rem 0.55rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: var(--surface);
  color: var(--ink);
  font-size: 0.75rem;
}

.catalog-mini-button:hover {
  border-color: var(--brand);
  background: #edf6f1;
}

.option-slider {
  display: grid;
  grid-template-columns: 2.4rem minmax(0, 1fr) 2.4rem;
  align-items: stretch;
  gap: 0.45rem;
}

.slider-arrow {
  border: 1px solid var(--line);
  border-radius: 0.6rem;
  background: #f3f7f5;
  color: var(--brand-dark);
  font-size: 1.55rem;
  font-weight: 800;
}

.slider-arrow:hover {
  border-color: var(--brand);
  background: #e5f1eb;
}

.option-track {
  display: flex;
  gap: 0.55rem;
  min-width: 0;
  padding: 0.2rem 0.1rem 0.45rem;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
  scroll-snap-type: x mandatory;
  scrollbar-width: thin;
}

.option-card {
  flex: 0 0 clamp(8.8rem, 30%, 12rem);
  display: grid;
  align-content: start;
  gap: 0.2rem;
  min-height: 6.7rem;
  padding: 0.7rem;
  border: 1px solid var(--line);
  border-radius: 0.7rem;
  background: var(--surface);
  color: var(--ink);
  text-align: left;
  scroll-snap-align: center;
}

.option-card:hover,
.option-card.is-active {
  border-color: var(--brand);
  box-shadow: 0 0 0 2px rgba(20, 107, 75, 0.12);
}

.option-card.is-selected {
  border-color: var(--brand-dark);
  background: #dff0e7;
  box-shadow: inset 0 0 0 1px var(--brand-dark);
}

.option-label {
  color: var(--ink);
  font-size: 0.87rem;
  line-height: 1.3;
}

.option-desc,
.option-effect {
  color: var(--muted);
  font-size: 0.7rem;
  line-height: 1.35;
}

.option-effect {
  color: var(--brand-dark);
  font-weight: 700;
}

.option-none {
  align-content: center;
  justify-items: center;
  min-height: 6.7rem;
  color: var(--muted);
  text-align: center;
}

.task-fields {
  margin: 0.2rem 0 1.15rem;
  padding: 1rem 1rem 0;
  border-radius: 0.7rem;
  background: var(--surface-soft);
}

.task-fields h3 {
  margin: 0;
  font-size: 1rem;
}

.task-fields > p {
  margin: 0.25rem 0 0.85rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.form-actions,
.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
}

.button {
  display: inline-flex;
  min-height: 2.85rem;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 0.7rem;
  padding: 0.68rem 1rem;
  font-weight: 750;
  line-height: 1.35;
  text-align: center;
  text-decoration: none;
}

.button-primary {
  border-color: var(--brand);
  background: var(--brand);
  color: #fff;
}

.button-primary:hover {
  border-color: var(--brand-dark);
  background: var(--brand-dark);
}

.button-secondary {
  border-color: var(--ink);
  background: var(--ink);
  color: #fff;
}

.button-quiet {
  border-color: var(--line);
  background: transparent;
  color: var(--ink);
}

.button-quiet:hover {
  background: var(--surface-soft);
}

.button:disabled {
  border-color: #d4dbd7;
  background: #e7ebe8;
  color: #707a74;
  cursor: not-allowed;
}

.output {
  min-height: 18rem;
  background: #f8faf8;
}

.status {
  min-height: 1.7rem;
  margin: 0.7rem 0;
  color: var(--brand-dark);
  font-size: 0.9rem;
  font-weight: 650;
}

.status[data-kind="error"] {
  color: var(--danger);
}

.status[data-kind="warning"] {
  color: #755700;
}

.status[data-kind="success"] {
  color: var(--brand-dark);
}

.saved-card {
  margin-top: 1.25rem;
  padding: clamp(1.25rem, 3vw, 2rem);
}

.history-panel {
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--line);
}

.history-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
}

.history-heading h2,
.history-heading p {
  margin: 0;
}

.history-list {
  max-height: 26rem;
  overflow: auto;
  overscroll-behavior: contain;
}

.section-heading-inline {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 2rem;
}

.section-heading-inline > p {
  max-width: 420px;
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
  text-align: right;
}

.saved-list {
  display: grid;
  gap: 0.75rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.saved-list > li {
  padding: 0.9rem 1rem;
  border: 1px solid var(--line);
  border-radius: 0.7rem;
}

.saved-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.saved-item-label {
  min-width: 0;
  overflow-wrap: anywhere;
}

.saved-item-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 0.5rem;
}

.saved-item-actions button {
  min-height: 2.5rem;
  border: 1px solid var(--line);
  border-radius: 0.55rem;
  background: var(--surface);
  padding: 0.45rem 0.75rem;
  font-weight: 650;
}

.saved-list .empty-state {
  border-style: dashed;
  color: var(--muted);
  text-align: center;
}

.info-section {
  padding: clamp(3.5rem, 8vw, 6rem) 0;
}

.guide-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
  margin: 2rem 0 0;
  padding: 0;
  counter-reset: guide;
  list-style: none;
}

.guide-list li {
  min-width: 0;
  padding: 1.25rem;
  border-top: 3px solid var(--brand);
  background: var(--surface);
}

.guide-list strong,
.guide-list span {
  display: block;
}

.guide-list span {
  margin-top: 0.35rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.model-section {
  border-top: 1px solid var(--line);
}

.model-section > p:not(.eyebrow, .review-date) {
  max-width: 760px;
  color: var(--muted);
}

.model-table-wrap {
  position: relative;
  max-width: 100%;
  margin: 1.5rem 0;
  overflow-x: auto;
  contain: layout paint;
  border: 1px solid var(--line);
  border-radius: 0.7rem;
  background: var(--surface);
}

.model-table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.model-table th,
.model-table td {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.model-table thead th {
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.04em;
}

.model-table tbody tr:last-child > * {
  border-bottom: 0;
}

.model-table small {
  color: var(--muted);
}

.model-table a {
  font-weight: 700;
  white-space: nowrap;
}

.review-date {
  color: var(--muted);
  font-size: 0.82rem;
}

.site-footer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem 2rem;
  padding: 2rem max(1rem, calc((100% - 1180px) / 2));
  border-top: 1px solid var(--line);
  background: var(--ink);
  color: #fff;
}

.site-footer p {
  margin: 0;
}

.site-footer a {
  color: #fff;
}

.copyright {
  grid-column: 1 / -1;
  color: #b9c3be;
  font-size: 0.78rem;
}

/* Shared layout for About and Privacy pages. */
body.legal-page {
  min-height: 100vh;
}

.legal-main {
  width: min(820px, calc(100% - 2rem));
  margin: clamp(2rem, 6vw, 5rem) auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: clamp(1.25rem, 4vw, 3rem);
  box-shadow: var(--shadow);
}

.legal-content {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: clamp(1.25rem, 4vw, 3rem);
  box-shadow: var(--shadow);
}

.legal-main h1,
.legal-content h1 {
  margin: 0 0 1.5rem;
  font-size: clamp(2rem, 6vw, 3.4rem);
}

.legal-main h2,
.legal-content h2 {
  margin: 2.2rem 0 0.55rem;
  font-size: 1.25rem;
  line-height: 1.4;
}

.legal-main p,
.legal-main li,
.legal-content p,
.legal-content li {
  color: var(--muted);
}

.legal-main ul,
.legal-main ol,
.legal-content ul,
.legal-content ol {
  padding-left: 1.4rem;
}

.legal-main code,
.legal-content code {
  border-radius: 0.3rem;
  background: var(--surface-soft);
  padding: 0.1em 0.35em;
  color: var(--ink);
}

.legal-footer {
  width: min(820px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 0 0 2.5rem;
  color: var(--muted);
  font-size: 0.85rem;
}

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

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

  .result-card {
    position: static;
  }

  .subject-detail-heading,
  .history-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .subject-detection-controls {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .output {
    min-height: 12rem;
  }
}

@media (max-width: 620px) {
  .site-header {
    align-items: center;
  }

  .site-header nav {
    display: flex;
    gap: 0.75rem;
  }

  .site-header .brand > span:last-child {
    display: none;
  }

  .hero {
    padding-top: 1rem;
  }

  h1 br {
    display: none;
  }

  .field-row,
  .field-row-compact,
  .guide-list,
  .official-links {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .catalog-intro,
  .option-row-header {
    align-items: stretch;
    flex-direction: column;
  }

  .global-random-actions {
    justify-content: flex-start;
  }

  .catalog-group-summary {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .catalog-group-summary .catalog-group-count {
    display: none;
  }

  .option-row-title {
    align-items: flex-start;
    flex-direction: column;
    gap: 0.1rem;
  }

  .option-slider {
    grid-template-columns: 2.2rem minmax(0, 1fr) 2.2rem;
  }

  .option-card {
    flex-basis: 72%;
  }

  .advanced-settings summary,
  .section-heading-inline {
    align-items: flex-start;
    flex-direction: column;
  }

  .summary-hint {
    display: block;
  }

  .section-heading-inline {
    gap: 0.5rem;
  }

  .section-heading-inline > p {
    text-align: left;
  }

  .form-actions,
  .result-actions {
    flex-direction: column;
  }

  .button {
    width: 100%;
  }

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

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

  .guide-list li + li {
    margin-top: 0.75rem;
  }

  .site-footer {
    grid-template-columns: 1fr;
  }

  .site-footer nav {
    flex-direction: column;
    gap: 0.4rem;
  }

  .copyright {
    grid-column: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
