*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #eef2f6;
  --bg-accent: linear-gradient(180deg, rgba(233,241,250,0.95) 0%, rgba(238,242,246,1) 42%, rgba(244,247,250,1) 100%);
  --surface: #ffffff;
  --surface-alt: #f5f7fa;
  --surface-strong: #e9eef5;
  --border: #d8dee7;
  --border-focus: #2962c7;
  --text: #18202b;
  --text-muted: #667085;
  --accent: #2962c7;
  --accent-dark: #1f4d9d;
  --accent-soft: #e9f1ff;
  --success: #177245;
  --success-soft: #eaf8ef;
  --warning: #b56a00;
  --warning-soft: #fff4e5;
  --error: #c62828;
  --error-bg: #fff2f2;
  --error-border: #f0c6c6;
  --shadow: 0 10px 30px rgba(19, 33, 55, 0.08);
  --radius: 16px;
  --radius-sm: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}

body {
  font-family: var(--font);
  background: var(--bg-accent);
  color: var(--text);
  min-height: 100vh;
  padding: 1.5rem 1rem 3rem;
  line-height: 1.5;
}

.container {
  max-width: 1040px;
  margin: 0 auto;
}

header {
  margin-bottom: 1.5rem;
}

header h1 {
  font-size: clamp(1.75rem, 3vw, 2.35rem);
  line-height: 1.05;
  letter-spacing: -0.03em;
  margin-bottom: 0.55rem;
}

header p {
  max-width: 760px;
  color: var(--text-muted);
  font-size: 1rem;
}

.layout {
  display: grid;
  gap: 1rem;
}

.panel {
  background: rgba(255,255,255,0.92);
  border: 1px solid rgba(216, 222, 231, 0.95);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.panel-main {
  padding: 1.4rem;
}

.intro-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(280px, 0.95fr);
  gap: 1rem;
  align-items: start;
}

.field {
  margin-bottom: 1rem;
}

.field:last-child {
  margin-bottom: 0;
}

label,
.field-label {
  display: block;
  margin-bottom: 0.45rem;
  font-size: 0.88rem;
  font-weight: 700;
}

.optional {
  color: var(--text-muted);
  font-weight: 500;
  margin-left: 0.25rem;
  font-size: 0.8rem;
}

textarea,
input[type="number"],
select {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.7rem 0.85rem;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
  appearance: none;
}

textarea:focus,
input[type="number"]:focus,
select:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(41, 98, 199, 0.14);
  background: #fff;
}

textarea {
  min-height: 240px;
  resize: vertical;
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23667085' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.8rem center;
  padding-right: 2.2rem;
}

.hint,
.mini-copy {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.input-meta {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 0.45rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.details-block {
  margin-top: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  overflow: hidden;
}

.details-block summary {
  list-style: none;
  cursor: pointer;
  font-weight: 700;
  padding: 0.9rem 1rem;
  position: relative;
}

.details-block summary::-webkit-details-marker { display: none; }

.details-block summary::after {
  content: "+";
  position: absolute;
  right: 1rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
}

.details-block[open] summary::after {
  content: "−";
}

.details-content {
  padding: 0 1rem 1rem;
}

.row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
}

.action-row,
.results-actions,
.card-actions,
.suggestion-actions,
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: center;
}

.action-row {
  margin-top: 1.15rem;
}

button {
  font: inherit;
  font-weight: 700;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, opacity 0.15s, transform 0.08s, box-shadow 0.15s;
}

button:active { transform: scale(0.98); }
button:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

.btn-primary {
  background: var(--accent);
  color: #fff;
  padding: 0.72rem 1.15rem;
  box-shadow: 0 8px 18px rgba(41, 98, 199, 0.22);
}

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

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.72rem 1rem;
}

.btn-secondary:hover { background: var(--surface-alt); }

.btn-soft {
  background: var(--accent-soft);
  color: var(--accent-dark);
  padding: 0.62rem 0.9rem;
}

.btn-soft:hover { background: #dce9ff; }

.btn-danger-soft {
  background: #fff6f6;
  color: var(--error);
  padding: 0.62rem 0.9rem;
}

.btn-danger-soft:hover { background: #ffeaea; }

.btn-copy.copied {
  background: var(--success-soft);
  color: var(--success);
}

.guide-card {
  padding: 1.1rem;
  background:
    radial-gradient(circle at top right, rgba(41,98,199,0.12), transparent 48%),
    linear-gradient(180deg, rgba(255,255,255,0.98), rgba(245,247,250,0.98));
}

.guide-card h2 {
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.85rem;
}

.guide-list {
  display: grid;
  gap: 0.8rem;
}

.guide-item {
  padding: 0.8rem 0.85rem;
  border-radius: 12px;
  background: rgba(255,255,255,0.72);
  border: 1px solid rgba(216, 222, 231, 0.95);
}

.guide-item strong {
  display: block;
  margin-bottom: 0.2rem;
  font-size: 0.88rem;
}

.guide-item p {
  font-size: 0.83rem;
  color: var(--text-muted);
}

#loading {
  display: none;
  align-items: center;
  gap: 0.65rem;
  margin-top: 1rem;
  color: var(--text-muted);
  font-size: 0.92rem;
}

.spinner {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

#error-msg {
  display: none;
  margin-top: 1rem;
  padding: 0.85rem 1rem;
  border-radius: 12px;
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  color: var(--error);
}

#results-section {
  display: none;
  margin-top: 1rem;
}

.results-shell {
  padding: 1.25rem;
}

.results-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.results-header h2 {
  font-size: 1.1rem;
  margin-bottom: 0.2rem;
}

.results-header p {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.results-meta-top {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 0.7rem;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.65rem;
  border-radius: 999px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 700;
}

.cards {
  display: grid;
  gap: 1rem;
}

.outcome-card {
  border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(255,255,255,0.98), rgba(248,250,252,0.98));
  border-radius: 16px;
  padding: 1rem;
  box-shadow: 0 12px 24px rgba(19,33,55,0.04);
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.8rem;
  margin-bottom: 0.9rem;
}

.card-index {
  font-size: 0.76rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 700;
  margin-bottom: 0.35rem;
}

.card-title {
  font-size: 1rem;
  font-weight: 750;
  line-height: 1.45;
}

.score-block {
  flex-shrink: 0;
  text-align: right;
  min-width: 110px;
}

.stars {
  color: #e0a100;
  font-size: 1.02rem;
  letter-spacing: 0.08em;
}

.score-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 700;
  margin-top: 0.15rem;
}

.suggestion-panel,
.analysis-box,
.content-row {
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
}

.content-stack {
  display: grid;
  gap: 0.7rem;
  margin-bottom: 0.9rem;
}

.content-row {
  padding: 0.8rem 0.9rem;
  background: rgba(255,255,255,0.88);
}

.content-row.working-row {
  background: transparent;
  border: none;
  border-radius: 0;
  border-top: 1px solid rgba(24, 32, 43, 0.08);
  border-bottom: 1px solid rgba(24, 32, 43, 0.08);
  padding: 1rem 0 1.05rem;
}

.content-row-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
  margin-bottom: 0.45rem;
}

.content-row-label {
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.working-row .content-row-label {
  color: var(--text);
  letter-spacing: 0.09em;
}

.working-row .content-row-head {
  margin-bottom: 0.6rem;
}

.working-row .content-text {
  font-size: 1rem;
  line-height: 1.65;
}

.content-row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  justify-content: flex-end;
}

.btn-compact {
  padding: 0.45rem 0.75rem;
  font-size: 0.82rem;
  line-height: 1.1;
}

.content-text {
  font-size: 0.94rem;
  line-height: 1.55;
  white-space: pre-wrap;
}

.inline-editor {
  display: grid;
  gap: 0.6rem;
}

.inline-editor textarea {
  min-height: 88px;
  padding: 0.65rem 0.75rem;
  font-size: 0.92rem;
}

.inline-editor-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.suggestion-actions {
  margin-top: 0.8rem;
  padding-top: 0.1rem;
}

.analysis-grid {
  display: grid;
  gap: 0.85rem;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 0.9fr);
  margin-bottom: 0.95rem;
}

.analysis-box {
  padding: 0.85rem 0.9rem;
  background: rgba(255,255,255,0.8);
}

.analysis-box h3 {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.45rem;
}

.analysis-box p,
.analysis-box li {
  font-size: 0.9rem;
}

.analysis-box ul {
  padding-left: 1.15rem;
  display: grid;
  gap: 0.35rem;
}

.controls-grid {
  display: grid;
  grid-template-columns: minmax(200px, 260px) 1fr;
  gap: 0.8rem;
  align-items: end;
  margin-bottom: 0.9rem;
}

.suggestion-panel {
  padding: 0.95rem;
  background: linear-gradient(180deg, #f7fbff, #f0f6ff);
  border-color: #cadefb;
}

.suggestion-panel h3 {
  font-size: 0.88rem;
  margin-bottom: 0.45rem;
}

.suggestion-text {
  white-space: pre-wrap;
  font-size: 0.94rem;
  line-height: 1.6;
  margin-bottom: 0.75rem;
}

.suggestion-note {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.card-status {
  font-size: 0.82rem;
  color: var(--text-muted);
  min-height: 1.2em;
}

.footer-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}

.meta-row {
  font-size: 0.8rem;
  color: var(--text-muted);
}

@media (max-width: 900px) {
  .intro-grid,
  .analysis-grid,
  .controls-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  body { padding: 1rem 0.8rem 2rem; }
  .panel-main, .results-shell { padding: 1rem; }
  textarea { min-height: 220px; }
  .row-2 { grid-template-columns: 1fr; }
  .card-head { flex-direction: column; }
  .score-block { text-align: left; min-width: 0; }
  .footer-bar { align-items: stretch; }
  .content-row-head { flex-direction: column; }
  .content-row-actions { justify-content: flex-start; }
  .action-row button,
  .results-actions button,
  .suggestion-actions button { flex: 1 1 auto; justify-content: center; }
}
