:root {
  color-scheme: light;
  --bg: #f7f4ef;
  --ink: #241f1b;
  --muted: #72685e;
  --line: #d9d0c5;
  --paper: #fffdf8;
  --soft: #eee8df;
  --accent: #9b1c31;
  --accent-dark: #741324;
  --green: #2f6f5e;
  --shadow: 0 18px 38px rgba(44, 34, 24, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(155, 28, 49, 0.05), transparent 24%),
    var(--bg);
  font-family: "Hiragino Mincho ProN", "Yu Mincho", "YuMincho", serif;
}

button,
select,
textarea {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(320px, 390px) minmax(520px, 1fr);
  gap: 16px;
  min-height: 100vh;
  padding: 16px;
}

.result-column {
  display: flex;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  gap: 16px;
}

.input-pane,
.output-pane,
.reference-pane {
  min-width: 0;
  background: rgba(255, 253, 248, 0.88);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.input-pane,
.reference-pane {
  padding: 20px;
}

.output-pane {
  display: flex;
  flex-direction: column;
  flex: 1;
  padding: 20px;
}

.brand,
.toolbar,
.reference-head,
.button-row,
.toolbar-actions {
  display: flex;
  align-items: center;
}

.brand,
.toolbar,
.reference-head {
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-family: system-ui, sans-serif;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
}

h1,
h2 {
  margin: 0;
  line-height: 1.15;
  font-weight: 700;
}

h1 {
  font-size: 28px;
}

h2 {
  font-size: 20px;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 72px;
  min-height: 30px;
  padding: 4px 10px;
  border: 1px solid var(--line);
  background: var(--soft);
  color: var(--muted);
  border-radius: 6px;
  font-family: system-ui, sans-serif;
  font-size: 12px;
}

.status-badge.ready {
  color: #fff;
  background: var(--green);
  border-color: var(--green);
}

.form-stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

fieldset {
  margin: 0;
  padding: 0;
  border: 0;
}

legend,
.field span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-family: system-ui, sans-serif;
  font-size: 13px;
  font-weight: 700;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--paper);
}

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

.segmented label {
  min-width: 0;
}

.segmented input {
  position: absolute;
  opacity: 0;
}

.segmented span {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 42px;
  color: var(--muted);
  cursor: pointer;
  font-family: system-ui, sans-serif;
  font-weight: 700;
}

.segmented input:checked + span {
  color: #fff;
  background: var(--accent);
}

select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
}

select {
  height: 44px;
  padding: 0 12px;
}

textarea {
  resize: vertical;
  padding: 12px;
  line-height: 1.8;
}

textarea:focus,
select:focus,
button:focus-visible {
  outline: 2px solid rgba(155, 28, 49, 0.35);
  outline-offset: 2px;
}

.button-row {
  gap: 10px;
  justify-content: flex-end;
}

button {
  min-height: 42px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 0 16px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-family: system-ui, sans-serif;
  font-weight: 700;
}

button:hover {
  background: var(--accent-dark);
}

button:disabled {
  cursor: wait;
  opacity: 0.65;
}

button.secondary {
  color: var(--accent);
  background: transparent;
}

button.secondary:hover {
  color: #fff;
  background: var(--accent);
}

button.small {
  min-height: 34px;
  padding: 0 10px;
  font-size: 13px;
}

.icon-button {
  width: 40px;
  min-height: 40px;
  padding: 0;
  border-color: var(--line);
  background: var(--paper);
  color: var(--ink);
  font-family: system-ui, sans-serif;
  font-size: 20px;
}

.icon-button:hover {
  color: #fff;
  border-color: var(--accent);
}

.toolbar-actions {
  gap: 8px;
}

.norito-editor {
  flex: 1;
  min-height: 430px;
  max-height: calc(100vh - 190px);
  font-size: 17px;
  line-height: 2.2;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  overflow: auto;
  white-space: pre-wrap;
  letter-spacing: 0;
}

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

.reference-card {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
}

.reference-card h3 {
  margin: 0 0 8px;
  font-size: 16px;
  line-height: 1.45;
}

.meta,
.reason {
  margin: 0;
  color: var(--muted);
  font-family: system-ui, sans-serif;
  font-size: 12px;
  line-height: 1.55;
}

.reason {
  margin-top: 8px;
}

.reference-card a {
  display: inline-flex;
  margin-top: 10px;
  color: var(--accent);
  font-family: system-ui, sans-serif;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
}

.reference-card a:hover {
  text-decoration: underline;
}

@media (max-width: 1120px) {
  .app-shell {
    grid-template-columns: 360px 1fr;
  }

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

@media (max-width: 780px) {
  .app-shell {
    grid-template-columns: 1fr;
    padding: 10px;
  }

  .input-pane,
  .output-pane,
  .reference-pane {
    padding: 16px;
  }

  .norito-editor {
    min-height: 420px;
    max-height: 620px;
  }
}
