:root {
  --bg: #f6f3ee;
  --surface: #fffdf9;
  --surface-strong: #ffffff;
  --ink: #241f1c;
  --muted: #776f68;
  --line: #e5ddd2;
  --accent: #e35d3e;
  --accent-dark: #aa3927;
  --teal: #26766a;
  --blue: #315f9b;
  --shadow: 0 20px 60px rgba(42, 35, 27, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.55), rgba(255, 255, 255, 0)),
    var(--bg);
  font-family:
    Inter, "Noto Sans JP", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

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

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 28px 20px;
  background: #1f2523;
  color: #fffaf2;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.brand {
  display: flex;
  gap: 14px;
  align-items: center;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: var(--accent);
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 22px;
}

.brand h1,
.page-heading h2,
.output-header h3,
.section-title h3 {
  margin: 0;
  letter-spacing: 0;
}

.brand h1 {
  font-size: 19px;
  line-height: 1.25;
}

.eyebrow {
  margin: 0 0 4px;
  color: color-mix(in srgb, currentColor 62%, transparent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav-button {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.06);
  color: inherit;
  text-align: left;
}

.nav-button.is-active {
  background: #fffaf2;
  color: #202321;
}

.profile-meter {
  margin-top: auto;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 12px;
  align-items: center;
  color: rgba(255, 250, 242, 0.82);
  font-size: 13px;
}

.meter-track {
  grid-column: 1 / -1;
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
  overflow: hidden;
}

.meter-bar {
  width: 0%;
  height: 100%;
  background: #74c9b9;
  transition: width 180ms ease;
}

.workspace {
  padding: 32px;
}

.view {
  display: none;
}

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

.page-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 20px;
  margin-bottom: 22px;
}

.page-heading h2 {
  font-size: clamp(28px, 4vw, 44px);
  line-height: 1.08;
}

.layout-grid {
  display: grid;
  grid-template-columns: minmax(320px, 430px) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 20px;
}

.field,
.field-group {
  display: grid;
  gap: 9px;
  margin: 0 0 18px;
}

.field span,
.field-group legend {
  color: #3d3731;
  font-size: 13px;
  font-weight: 800;
}

textarea,
select,
input[type="text"] {
  width: 100%;
  border: 1px solid #d7cec3;
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--ink);
  padding: 12px 13px;
  outline: none;
}

textarea {
  resize: vertical;
  line-height: 1.65;
}

textarea:focus,
select:focus,
input[type="text"]:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(38, 118, 106, 0.15);
}

.radio-line,
.check-line {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 32px;
  color: var(--muted);
}

.notice {
  margin: 8px 0 18px;
  border-left: 4px solid var(--blue);
  background: #eef4fb;
  color: #294866;
  padding: 12px 14px;
  border-radius: 6px;
  line-height: 1.6;
  font-size: 13px;
}

.primary-button,
.ghost-button {
  border-radius: 8px;
  min-height: 42px;
  padding: 0 16px;
  font-weight: 800;
}

.primary-button {
  border: 0;
  background: var(--accent);
  color: white;
}

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

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

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

.output-panel {
  min-height: 620px;
}

.output-header,
.section-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
}

.output-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.source-badge {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-strong);
  color: var(--muted);
  padding: 0 12px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.source-badge[data-source="gemini"] {
  border-color: #bee3d6;
  background: #eff7f5;
  color: var(--teal);
}

.source-badge[data-source="local"] {
  border-color: #ead7b7;
  background: #fff7e8;
  color: #9b5f17;
}

.source-badge[data-source="loading"] {
  color: var(--ink);
}

.empty-state {
  min-height: 180px;
  display: grid;
  place-items: center;
  color: var(--muted);
  border: 1px dashed #d8cfc5;
  border-radius: 8px;
  padding: 24px;
  text-align: center;
  line-height: 1.7;
}

.script-output {
  display: grid;
  gap: 14px;
}

.story-card {
  border: 1px solid #e6ddd3;
  border-radius: 8px;
  background: #fff;
  padding: 16px;
}

.story-card header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 10px;
}

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

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  background: #eff7f5;
  color: var(--teal);
  padding: 0 10px;
  font-size: 12px;
  font-weight: 800;
}

.story-card pre,
.history-detail pre {
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
  line-height: 1.75;
}

.story-meta {
  display: grid;
  gap: 7px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 13px;
}

.settings-form {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(320px, 0.85fr);
  gap: 20px;
  align-items: start;
}

.settings-form .profile-card,
.settings-form .sticky-save {
  grid-column: 1 / -1;
}

.product-list {
  display: grid;
  gap: 14px;
  margin-top: 16px;
}

.product-card {
  border: 1px solid #e4dbd1;
  border-radius: 8px;
  padding: 14px;
  background: #fff;
}

.product-card .field {
  margin-bottom: 12px;
}

.product-actions {
  display: flex;
  justify-content: flex-end;
}

.profile-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin: 0;
}

.profile-summary div {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 14px;
}

.profile-summary dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  margin-bottom: 7px;
}

.profile-summary dd {
  margin: 0;
  font-weight: 800;
}

.history-grid {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 20px;
}

.history-list {
  display: grid;
  gap: 8px;
  align-content: start;
}

.history-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
  text-align: left;
}

.history-item.is-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(227, 93, 62, 0.13);
}

.history-item strong {
  display: block;
  margin-bottom: 4px;
}

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

.history-detail {
  min-height: 520px;
}

.is-hidden {
  display: none;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  transform: translateY(18px);
  opacity: 0;
  border-radius: 8px;
  background: #202321;
  color: #fffaf2;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

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

@media (max-width: 980px) {
  .app-shell,
  .layout-grid,
  .settings-form,
  .history-grid {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .workspace {
    padding: 22px 16px 36px;
  }

  .page-heading {
    align-items: stretch;
    flex-direction: column;
  }
}

@media (max-width: 620px) {
  .sidebar {
    padding: 20px 16px;
  }

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

  .nav-button {
    text-align: center;
    padding: 10px 8px;
  }

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

  .output-header,
  .section-title {
    align-items: stretch;
    flex-direction: column;
  }

  .output-actions {
    justify-content: space-between;
  }
}
