* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    linear-gradient(135deg, rgba(57, 79, 87, 0.18), transparent 36%),
    linear-gradient(315deg, rgba(187, 95, 75, 0.12), transparent 44%),
    #f1f2ed;
  color: #1f2827;
  overflow: hidden;
}

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

button {
  min-height: 38px;
  border: 0;
  border-radius: 8px;
  background: #394f57;
  color: #fbf7ef;
  padding: 0 12px;
  font-weight: 850;
  cursor: pointer;
}

button:disabled {
  opacity: 0.55;
  cursor: default;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #c8d4cf;
  border-radius: 8px;
  background: #fffdfa;
  color: #1f2827;
  padding: 9px 10px;
}

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

.novel-shell {
  width: min(100%, 1180px);
  height: 100dvh;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto auto;
  gap: 10px;
  padding: 14px;
}

.novel-header {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) minmax(260px, auto);
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid rgba(57, 79, 87, 0.2);
  padding-bottom: 10px;
}

.novel-header a {
  color: #394f57;
  text-decoration: none;
  font-size: 20px;
  font-weight: 900;
}

h1 {
  margin: 0;
  font-size: 24px;
  font-weight: 950;
}

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

label {
  display: grid;
  gap: 5px;
  color: #52665f;
  font-size: 13px;
  font-weight: 850;
}

.setup-panel {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid rgba(57, 79, 87, 0.18);
  border-radius: 8px;
  background: rgba(255, 253, 250, 0.82);
}

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

.mode-tabs button {
  background: #dce6df;
  color: #22312f;
}

.mode-tabs button.active {
  background: #6b5f86;
  color: #fff7fa;
}

.starter-panel {
  display: grid;
  gap: 8px;
  border: 1px solid #d5ded8;
  border-radius: 8px;
  background: rgba(238, 245, 240, 0.72);
  padding: 10px;
}

.starter-title {
  color: #394f57;
  font-size: 13px;
  font-weight: 900;
}

.starter-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.starter-button {
  min-height: 32px;
  padding: 0 10px;
  background: #edf2ed;
  color: #22312f;
  font-size: 13px;
}

.setup-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.wide {
  grid-column: 1 / -1;
}

.inline-label {
  color: #52665f;
  font-size: 12px;
  font-weight: 850;
}

.story-panel {
  min-height: 0;
  overflow-y: auto;
  padding: 18px;
  border: 1px solid rgba(57, 79, 87, 0.18);
  border-radius: 8px;
  background: #fffdfa;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.72);
}

.director-state-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 9px 10px;
  border: 1px solid rgba(57, 79, 87, 0.18);
  border-radius: 8px;
  background: rgba(255, 253, 250, 0.72);
}

.director-state-panel > div:first-child {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.state-label {
  color: #6b5f86;
  font-size: 12px;
  font-weight: 900;
}

#directorStateSummary {
  min-width: 0;
  color: #304047;
  font-size: 13px;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.state-keywords {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.state-keywords span {
  min-height: 24px;
  display: inline-flex;
  align-items: center;
  border: 1px solid #d5ded8;
  border-radius: 999px;
  background: #eef4f1;
  color: #394f57;
  padding: 0 8px;
  font-size: 12px;
  font-weight: 800;
}

.state-keywords span[data-type="pinned"] {
  background: #6b5f86;
  color: #fff7fa;
}

.empty-state {
  max-width: 560px;
  margin: 24px auto;
  color: #667873;
  line-height: 1.6;
}

.story-turn {
  max-width: 820px;
  margin: 0 auto 18px;
  padding: 0 0 18px;
  border-bottom: 1px solid #e4e8e3;
  line-height: 1.76;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.story-turn.ai {
  color: #1f2827;
}

.story-turn.note {
  max-width: 760px;
  padding: 10px 12px;
  border: 1px dashed #aebfb7;
  border-radius: 8px;
  background: #eef4f1;
  color: #43564f;
}

.story-meta {
  display: block;
  margin-bottom: 8px;
  color: #6b5f86;
  font-size: 12px;
  font-weight: 900;
}

.director-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(220px, auto);
  gap: 10px;
  align-items: end;
  padding: 10px;
  border: 1px solid rgba(57, 79, 87, 0.2);
  border-radius: 8px;
  background: rgba(255, 253, 250, 0.94);
  box-shadow: 0 -12px 34px rgba(31, 40, 39, 0.08);
}

.director-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}

#startButton {
  grid-column: 1 / -1;
  background: #b75f4b;
}

.status-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 10px;
  align-items: center;
  min-height: 36px;
  color: #7d4d34;
  font-size: 13px;
  font-weight: 750;
}

.status-row button {
  min-height: 32px;
  background: #dce6df;
  color: #22312f;
}

.novel-score-toolbar {
  display: flex;
  gap: 6px;
  align-items: center;
  overflow-x: auto;
}

.novel-score-toolbar span,
.novel-score-toolbar button {
  flex: 0 0 auto;
  min-height: 30px;
  font-size: 12px;
}

.novel-score-toolbar span {
  display: inline-flex;
  align-items: center;
  border: 1px solid #c8d4cf;
  border-radius: 999px;
  background: rgba(255, 253, 250, 0.86);
  color: #394f57;
  padding: 0 9px;
  font-weight: 900;
}

.novel-score-toolbar button {
  padding: 0 9px;
  background: #edf2ed;
  color: #22312f;
}

#novelScoreBadge[data-state="complete"] {
  background: #394f57;
  color: #fff;
}

#novelScoreBadge[data-state="discard"] {
  background: #b75f4b;
  color: #fff8f1;
}

@media (max-width: 760px) {
  .novel-shell {
    gap: 8px;
    padding: 10px;
  }

  .novel-header {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .header-actions {
    grid-column: 1 / -1;
    grid-template-columns: minmax(0, 1fr) 96px;
  }

  .setup-grid,
  .director-row {
    grid-template-columns: 1fr;
  }

  .setup-panel {
    max-height: 34dvh;
    overflow-y: auto;
    padding: 9px;
  }

  .starter-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .director-actions {
    grid-template-columns: 1fr 1fr;
  }

  .story-panel {
    padding: 13px;
  }

  .story-turn {
    margin-bottom: 14px;
    padding-bottom: 14px;
  }

  .status-row {
    grid-template-columns: 1fr;
  }

  .director-state-panel {
    grid-template-columns: 1fr;
  }

  .state-keywords {
    justify-content: flex-start;
  }
}
