:root {
  --bg: #f6f5f1;
  --paper: #ffffff;
  --ink: #20272a;
  --muted: #697277;
  --line: #d8d6ce;
  --teal: #2f776d;
  --teal-dark: #1e5c54;
  --clay: #a95d45;
  --gold: #a8832e;
  --sky: #4e7d95;
  --shadow: 0 18px 45px rgba(24, 34, 36, 0.08);
  --radius: 8px;
  font-family: "Yu Gothic", "Hiragino Kaku Gothic ProN", Meiryo, system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(47, 119, 109, 0.08), transparent 260px),
    var(--bg);
}

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

button {
  min-height: 44px;
  border: 0;
  cursor: pointer;
}

.app-header {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
  padding: 22px 18px 14px;
}

.app-header h1,
h2,
h3,
p {
  margin: 0;
}

.app-header h1 {
  font-size: clamp(1.45rem, 4vw, 2.15rem);
  letter-spacing: 0;
}

.eyebrow {
  color: var(--teal-dark);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
}

.header-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(84px, 1fr));
  gap: 8px;
}

.primary-button,
.ghost-button {
  border-radius: var(--radius);
  padding: 0 14px;
  font-weight: 700;
}

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

.ghost-button {
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
}

.tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  padding: 0 12px 12px;
}

.tab {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.72);
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
  white-space: normal;
}

.tab.is-active {
  border-color: var(--teal);
  background: var(--teal);
  color: #fff;
}

main {
  padding: 0 12px 32px;
}

.tab-panel {
  display: none;
}

.tab-panel.is-active {
  display: block;
}

.workspace,
.dictionary-layout,
.phrase-layout,
.relation-tools {
  width: min(1180px, 100%);
  margin: 0 auto;
}

.workspace {
  display: grid;
  gap: 14px;
}

.control-panel,
.result-panel,
.dictionary-detail,
.relation-tools,
.phrase-layout > section {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.control-panel {
  display: grid;
  gap: 14px;
  padding: 14px;
}

.field {
  display: grid;
  gap: 6px;
}

.field-note {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.6;
}

label,
legend {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  padding: 10px 12px;
}

.birthdate-row {
  display: grid;
  grid-template-columns: minmax(96px, 1.2fr) minmax(76px, 0.9fr) minmax(76px, 0.9fr);
  gap: 8px;
}

.date-part {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.date-part.year-part {
  align-items: stretch;
}

.date-part.year-part input {
  text-align: left;
}

.date-part span {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

textarea {
  min-height: 180px;
  resize: vertical;
  line-height: 1.7;
}

.copy-panel {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
  border: 1px solid var(--teal);
  border-radius: var(--radius);
  background: #eef8f6;
  padding: 12px;
}

.copy-panel[hidden] {
  display: none;
}

.copy-panel textarea {
  min-height: 150px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin: 0;
  padding: 0;
  border: 0;
}

.segmented legend {
  grid-column: 1 / -1;
}

.segmented label {
  min-width: 0;
}

.segmented input {
  position: absolute;
  width: 1px;
  min-height: 1px;
  opacity: 0;
  pointer-events: none;
}

.segmented span {
  display: grid;
  min-height: 44px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--muted);
  text-align: center;
}

.segmented input:checked + span {
  border-color: var(--clay);
  background: #fff4ef;
  color: var(--clay);
  font-weight: 700;
}

.select-grid {
  display: grid;
  gap: 10px;
}

.result-panel {
  padding: 16px;
}

.result-heading {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 14px;
}

.result-heading h2 {
  margin-top: 4px;
  font-size: 1.22rem;
}

#resultMeta {
  color: var(--muted);
  line-height: 1.7;
}

.output-stack {
  display: grid;
  gap: 12px;
}

.info-card {
  display: grid;
  gap: 10px;
  border-left: 5px solid var(--teal);
  border-radius: var(--radius);
  background: #fff;
  padding: 14px;
}

.info-card.clay {
  border-left-color: var(--clay);
}

.info-card.gold {
  border-left-color: var(--gold);
}

.info-card.sky {
  border-left-color: var(--sky);
}

.info-card h3 {
  font-size: 1.02rem;
}

.info-card p,
.info-card li {
  line-height: 1.8;
  white-space: pre-line;
}

.info-card ul {
  display: grid;
  gap: 6px;
  margin: 0;
  padding-left: 1.1rem;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 9px;
  background: #fbfbf8;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.dictionary-layout {
  display: grid;
  gap: 12px;
}

.star-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.star-list button {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
}

.star-list button.is-active {
  border-color: var(--teal);
  color: var(--teal-dark);
  background: #eef8f6;
}

.dictionary-detail {
  display: grid;
  gap: 14px;
  padding: 16px;
}

.detail-grid {
  display: grid;
  gap: 10px;
}

.detail-box {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  background: #fff;
}

.detail-box h3 {
  margin: 0 0 8px;
  font-size: 0.96rem;
}

.detail-box p {
  line-height: 1.8;
}

.phrase-layout {
  display: grid;
  gap: 12px;
}

.phrase-layout > section {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.phrase-list {
  display: grid;
  gap: 8px;
}

.phrase-item {
  display: grid;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  background: #fff;
  white-space: pre-line;
}

.phrase-item strong {
  color: var(--clay);
}

.toast {
  position: fixed;
  right: 14px;
  bottom: 14px;
  z-index: 5;
  max-width: min(360px, calc(100vw - 28px));
  border-radius: var(--radius);
  background: var(--ink);
  color: #fff;
  padding: 12px 14px;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 160ms ease, transform 160ms ease;
  pointer-events: none;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

@media (min-width: 760px) {
  .app-header {
    padding: 28px 28px 18px;
  }

  .tabs {
    display: flex;
    padding-inline: 28px;
  }

  .tab {
    min-width: 112px;
  }

  main {
    padding-inline: 28px;
  }

  .workspace {
    grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
    align-items: start;
  }

  .select-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .select-grid.two {
    grid-template-columns: repeat(2, 1fr);
  }

  .dictionary-layout {
    grid-template-columns: 230px minmax(0, 1fr);
    align-items: start;
  }

  .star-list {
    grid-template-columns: 1fr;
  }

  .detail-grid,
  .phrase-layout {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

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

  .tabs,
  .control-panel,
  .header-actions,
  .toast {
    display: none;
  }

  .workspace {
    display: block;
  }

  .result-panel {
    box-shadow: none;
    border: 0;
  }
}
