:root {
  color-scheme: light;
  --bg: #f3f5f4;
  --surface: #ffffff;
  --surface-soft: #f9fbfa;
  --ink: #1c2423;
  --muted: #61706d;
  --line: #dfe7e4;
  --line-strong: #c6d4cf;
  --green: #26766b;
  --green-soft: #e6f2ef;
  --red: #b64f43;
  --red-soft: #f8e9e6;
  --blue: #386b9b;
  --blue-soft: #e8f0f7;
  --yellow: #9b6f21;
  --yellow-soft: #fbf1d5;
  --max: 1440px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Hiragino Kaku Gothic ProN", "Noto Sans JP", Meiryo, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.6;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

.app-header {
  max-width: var(--max);
  margin: 0 auto;
  padding: 24px 22px 16px;
}

.header-main {
  min-height: 190px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 520px);
  gap: 24px;
  align-items: center;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--green);
  font-weight: 700;
  font-size: 14px;
}

h1 {
  max-width: 780px;
  margin: 0;
  font-size: clamp(34px, 5vw, 64px);
  line-height: 1.06;
  letter-spacing: 0;
}

.axis-art {
  width: 100%;
  max-height: 260px;
  object-fit: contain;
}

.toolbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto auto;
  gap: 10px;
  align-items: end;
  padding: 12px;
  background: rgba(243, 245, 244, .9);
  border: 1px solid var(--line);
  border-radius: 8px;
  backdrop-filter: blur(8px);
}

.search {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.search input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 9px 12px;
  background: var(--surface);
  color: var(--ink);
  outline: none;
}

.search input:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px var(--green-soft);
}

.view-switch {
  display: inline-grid;
  grid-template-columns: repeat(4, auto);
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
}

.seg,
.plain-button,
.primary-button {
  min-height: 42px;
  border: 0;
  background: var(--surface);
  padding: 8px 13px;
  cursor: pointer;
  white-space: nowrap;
}

.seg + .seg {
  border-left: 1px solid var(--line);
}

.seg.is-active {
  background: var(--green);
  color: #fff;
  font-weight: 700;
}

.plain-button {
  border: 1px solid var(--line-strong);
  border-radius: 6px;
}

.primary-button {
  width: 100%;
  border-radius: 6px;
  background: var(--green);
  color: #fff;
  font-weight: 800;
}

.plain-button:hover,
.seg:hover {
  background: var(--green-soft);
}

.seg.is-active:hover,
.primary-button:hover {
  background: var(--green);
}

.layout {
  max-width: var(--max);
  margin: 0 auto;
  padding: 0 22px 54px;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 20px;
}

.filters {
  position: sticky;
  top: 82px;
  align-self: start;
  max-height: calc(100vh - 96px);
  overflow: auto;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.filters section + section {
  margin-top: 18px;
}

.side-title {
  margin-bottom: 9px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.stats-grid div {
  min-height: 62px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
}

.stats-grid b {
  display: block;
  font-size: 22px;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.stats-grid span {
  color: var(--muted);
  font-size: 12px;
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-soft);
  padding: 5px 9px;
  cursor: pointer;
  font-size: 12px;
  line-height: 1.35;
}

.chip:hover {
  border-color: var(--green);
}

.chip.is-active {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
  font-weight: 700;
}

.content {
  min-width: 0;
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.summary-item {
  min-height: 82px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.summary-item b {
  display: block;
  margin-bottom: 4px;
  font-size: 13px;
}

.summary-item span {
  color: var(--muted);
  font-size: 12px;
}

.panel {
  display: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 18px;
}

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

.section-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
  margin-bottom: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

h2,
h3 {
  margin: 0;
  line-height: 1.3;
  letter-spacing: 0;
}

h2 {
  font-size: 22px;
}

h3 {
  font-size: 17px;
}

.section-head p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.mechanism-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
  gap: 12px;
}

.card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 246px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.card h3 {
  font-size: 16px;
}

.card-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: start;
}

.index {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.badge {
  border-radius: 999px;
  padding: 3px 7px;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.35;
}

.badge.find {
  background: var(--green-soft);
  color: var(--green);
}

.badge.solve {
  background: var(--blue-soft);
  color: var(--blue);
}

.badge.trigger {
  background: var(--yellow-soft);
  color: var(--yellow);
}

.card p {
  margin: 0;
}

.field {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: 8px;
  font-size: 13px;
}

.field b {
  color: var(--muted);
  font-size: 12px;
}

.risk {
  margin-top: auto;
  padding: 8px 10px;
  border-left: 3px solid var(--red);
  background: var(--red-soft);
  color: #6f2d27;
  font-size: 12px;
}

.empty {
  display: none;
  margin: 38px 0 20px;
  color: var(--muted);
  text-align: center;
}

.empty.is-active {
  display: block;
}

.matrix-wrap {
  overflow: auto;
}

.matrix {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
}

.matrix th,
.matrix td {
  border: 1px solid var(--line);
  padding: 8px;
  text-align: center;
  vertical-align: middle;
}

.matrix th {
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.matrix th:first-child {
  left: 0;
  z-index: 2;
}

.matrix .row-head {
  position: sticky;
  left: 0;
  min-width: 138px;
  max-width: 160px;
  background: var(--surface);
  text-align: left;
  color: var(--ink);
}

.matrix-cell {
  min-width: 58px;
  border: 0;
  border-radius: 6px;
  padding: 6px 8px;
  background: #edf1f0;
  color: var(--muted);
  cursor: pointer;
  font-variant-numeric: tabular-nums;
}

.matrix-cell.has-items {
  background: var(--green-soft);
  color: var(--green);
  font-weight: 800;
}

.matrix-cell:hover {
  box-shadow: 0 0 0 2px var(--green) inset;
}

.axis-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.axis-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.axis-card {
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.axis-card h4 {
  margin: 0 0 6px;
  font-size: 15px;
}

.axis-card p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.axis-card .examples {
  margin-top: 9px;
  color: var(--ink);
  font-size: 12px;
}

.planner-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.planner-layout {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.planner-controls {
  display: grid;
  gap: 12px;
}

.planner-field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.planner-field textarea,
.planner-field select {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  padding: 9px 11px;
  outline: none;
}

.planner-field textarea {
  min-height: 150px;
  resize: vertical;
  font-size: 13px;
  line-height: 1.55;
}

.planner-field textarea:focus,
.planner-field select:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px var(--green-soft);
}

.planner-button-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.theme-list {
  display: grid;
  gap: 8px;
  max-height: 360px;
  overflow: auto;
}

.theme-button {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 10px;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}

.theme-button:hover {
  border-color: var(--green);
}

.theme-button.is-active {
  border-color: #d8aa53;
  background: #fff8ea;
  box-shadow: 0 0 0 1px #efd19b inset;
}

.theme-button b {
  display: block;
  font-size: 13px;
}

.theme-button span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
}

.planner-output {
  min-width: 0;
}

.plan-empty {
  display: grid;
  min-height: 280px;
  place-items: center;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--muted);
  text-align: center;
}

.plan-empty.is-hidden {
  display: none;
}

.plan-result {
  display: grid;
  gap: 12px;
}

.plan-card,
.beat-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 14px;
}

.plan-card h3,
.beat-card h3 {
  margin: 0 0 8px;
  font-size: 16px;
}

.plan-card p,
.beat-card p {
  margin: 0;
}

.plan-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0 0;
}

.plan-chip {
  border-radius: 999px;
  background: var(--green-soft);
  color: var(--green);
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 800;
}

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

.beat-card {
  background: var(--surface);
}

.beat-card .level {
  color: var(--red);
  font-size: 12px;
  font-weight: 800;
}

.artifact-list {
  display: grid;
  gap: 6px;
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
}

.artifact-list li {
  padding-left: 16px;
  position: relative;
  color: var(--muted);
  font-size: 13px;
}

.artifact-list li::before {
  content: "";
  position: absolute;
  left: 0;
  top: .78em;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green);
}

.plan-pre {
  overflow: auto;
  max-height: 360px;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7f9f8;
  padding: 12px;
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
}

mark {
  background: #ffe08a;
  color: inherit;
  border-radius: 3px;
  padding: 0 1px;
}

@media (max-width: 1060px) {
  .header-main {
    grid-template-columns: 1fr;
  }

  .axis-art {
    max-width: 640px;
  }

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

  .filters {
    position: static;
    max-height: none;
  }
}

@media (max-width: 760px) {
  .app-header {
    padding: 18px 14px 12px;
  }

  .toolbar {
    position: static;
    grid-template-columns: 1fr;
  }

  .view-switch {
    grid-template-columns: 1fr 1fr;
  }

  .seg,
  .plain-button {
    white-space: normal;
  }

  .layout {
    padding: 0 14px 40px;
  }

  .summary-strip {
    grid-template-columns: 1fr 1fr;
  }

  .panel {
    padding: 14px;
  }

  .section-head {
    flex-direction: column;
  }

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

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

  .planner-layout {
    grid-template-columns: 1fr;
  }

  .field {
    grid-template-columns: 1fr;
    gap: 2px;
  }
}

@media (max-width: 480px) {
  h1 {
    font-size: 32px;
  }

  .summary-strip {
    grid-template-columns: 1fr;
  }

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

  .view-switch,
  .planner-button-row {
    grid-template-columns: 1fr 1fr;
  }
}
