:root {
    --ink: #14211f;
    --muted: #60706b;
    --paper: #f4f1e9;
    --white: #ffffff;
    --line: #d6ddd9;
    --primary: #214e47;
    --primary-dark: #173a35;
    --accent: #efb94f;
    --danger: #a53a32;
    --success: #24745e;
    --shadow: 0 24px 70px rgba(20, 33, 31, 0.09);
    --radius: 22px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
    margin: 0;
    color: var(--ink);
    background:
        radial-gradient(circle at 90% 0%, rgba(239, 185, 79, 0.13), transparent 26rem),
        var(--paper);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.5;
}
button, input, textarea, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }
a { color: inherit; }

.site-header {
    width: min(1440px, calc(100% - 48px));
    margin: 0 auto;
    min-height: 92px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(20, 33, 31, 0.15);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 13px;
    text-decoration: none;
}
.brand strong { display: block; font-size: 1.05rem; letter-spacing: -0.02em; }
.brand small { color: var(--muted); font-size: 0.75rem; }
.brand-mark {
    width: 42px;
    height: 42px;
    padding: 8px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    align-items: end;
    gap: 3px;
    border-radius: 12px;
    background: var(--primary);
}
.brand-mark span { display: block; background: var(--white); border-radius: 2px; }
.brand-mark span:nth-child(1) { height: 42%; }
.brand-mark span:nth-child(2) { height: 100%; }
.brand-mark span:nth-child(3) { height: 68%; }

.ghost-button, .secondary-button, .icon-button, .card-actions a, .card-actions button, .history-actions button {
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.45);
    border-radius: 999px;
    padding: 10px 16px;
    cursor: pointer;
    text-decoration: none;
    transition: 160ms ease;
}
.ghost-button:hover, .secondary-button:hover, .card-actions a:hover, .card-actions button:hover, .history-actions button:hover {
    background: var(--white);
    border-color: var(--primary);
}

main { width: min(1440px, calc(100% - 48px)); margin: 0 auto; }
.hero {
    display: grid;
    grid-template-columns: minmax(0, 1.45fr) minmax(280px, 0.55fr);
    gap: 60px;
    padding: 86px 0 70px;
    align-items: end;
}
.eyebrow, .step {
    margin: 0 0 14px;
    color: var(--primary);
    font-size: 0.75rem;
    font-weight: 800;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}
h1, h2, h3, p { margin-top: 0; }
h1 {
    max-width: 950px;
    margin-bottom: 24px;
    font-size: clamp(3rem, 6vw, 6.8rem);
    line-height: 0.94;
    letter-spacing: -0.065em;
}
.hero-copy {
    max-width: 790px;
    margin: 0;
    color: var(--muted);
    font-size: clamp(1.05rem, 1.6vw, 1.35rem);
}
.hero-note {
    padding: 24px 0 0 24px;
    border-left: 2px solid var(--accent);
}
.hero-note strong { font-size: 0.9rem; text-transform: uppercase; letter-spacing: 0.06em; }
.hero-note p { margin: 10px 0 0; color: var(--muted); }

.workspace {
    display: grid;
    grid-template-columns: minmax(0, 1.55fr) minmax(320px, 0.45fr);
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.generator-panel { padding: clamp(26px, 5vw, 64px); }
.principles-panel {
    padding: clamp(26px, 4vw, 50px);
    color: var(--white);
    background: var(--primary);
}
.section-heading, .results-header, .dialog-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
}
.section-heading h2, .principles-panel h2, .results-header h2, .dialog-header h2 {
    margin-bottom: 0;
    font-size: clamp(1.8rem, 3vw, 3rem);
    line-height: 1;
    letter-spacing: -0.045em;
}
.status-dot {
    white-space: nowrap;
    padding: 8px 12px;
    color: var(--success);
    background: #eaf7f1;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 800;
    text-transform: uppercase;
}
.field-label, .settings label > span {
    display: block;
    margin: 30px 0 9px;
    font-size: 0.8rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}
.field-label em { color: var(--muted); font-style: normal; font-weight: 500; text-transform: none; }
textarea, input, select {
    width: 100%;
    color: var(--ink);
    background: #fbfcfb;
    border: 1px solid var(--line);
    border-radius: 14px;
    outline: none;
    transition: border 150ms ease, box-shadow 150ms ease;
}
textarea { min-height: 190px; padding: 18px; resize: vertical; font-size: 1.05rem; }
input, select { height: 50px; padding: 0 14px; }
textarea:focus, input:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(33, 78, 71, 0.1); }
.field-help {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-top: 8px;
    color: var(--muted);
    font-size: 0.78rem;
}
.field-help.single { justify-content: flex-start; }
.examples { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.examples button {
    padding: 8px 11px;
    color: var(--primary);
    background: transparent;
    border: 1px dashed #98aaa5;
    border-radius: 8px;
    font-size: 0.72rem;
    font-weight: 800;
    cursor: pointer;
}
.settings { margin-top: 30px; padding-top: 24px; border-top: 1px solid var(--line); }
.settings summary { font-weight: 800; cursor: pointer; }
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; }
.checkbox-row { display: flex !important; align-items: center; gap: 11px; margin-top: 22px; cursor: pointer; }
.checkbox-row input { width: 20px; height: 20px; accent-color: var(--primary); }
.checkbox-row span { margin: 0 !important; text-transform: none !important; font-weight: 600 !important; letter-spacing: 0 !important; }

.primary-button {
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    width: 100%;
    min-height: 58px;
    margin-top: 30px;
    padding: 0 20px;
    color: var(--white);
    background: var(--primary);
    border: 0;
    border-radius: 14px;
    font-weight: 800;
    text-decoration: none;
    cursor: pointer;
    transition: 160ms ease;
}
.primary-button:hover { background: var(--primary-dark); transform: translateY(-1px); }
.primary-button:disabled { cursor: wait; opacity: 0.65; transform: none; }
.primary-button.compact { width: auto; min-height: 44px; margin: 0; padding: 0 17px; }
.cost-note { margin: 10px 0 0; color: var(--muted); font-size: 0.75rem; }

.principles-panel .step { color: #b9d4ce; }
.principles-panel ol { list-style: none; padding: 0; margin: 50px 0 0; }
.principles-panel li { display: grid; grid-template-columns: 42px 1fr; gap: 12px; padding: 22px 0; border-top: 1px solid rgba(255,255,255,0.2); }
.principles-panel li > span { color: var(--accent); font-size: 0.75rem; font-weight: 800; }
.principles-panel li strong { display: block; margin-bottom: 4px; }
.principles-panel li p { margin: 0; color: #c6d6d2; font-size: 0.88rem; }

.progress-section {
    margin: 28px 0;
    padding: clamp(22px, 4vw, 38px);
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: 20px;
    box-shadow: 0 18px 48px rgba(20, 33, 31, 0.06);
}
.progress-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 24px;
}
.progress-heading h2 {
    margin-bottom: 8px;
    font-size: clamp(1.55rem, 3vw, 2.45rem);
    line-height: 1;
    letter-spacing: -0.04em;
}
.progress-heading p:last-child { margin: 0; color: var(--muted); }
.progress-percent {
    min-width: 74px;
    color: var(--primary);
    font-size: clamp(1.7rem, 4vw, 3rem);
    line-height: 1;
    text-align: right;
}
.progress-track {
    height: 10px;
    margin: 25px 0 28px;
    overflow: hidden;
    background: #e7ece9;
    border-radius: 999px;
}
.progress-track span {
    display: block;
    width: 0;
    height: 100%;
    background: var(--primary);
    border-radius: inherit;
    transition: width 320ms ease;
}
.stage-list {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 10px;
    margin: 0;
    padding: 0;
    list-style: none;
}
.stage-list li {
    min-height: 132px;
    padding: 16px;
    background: #f8faf9;
    border: 1px solid var(--line);
    border-radius: 14px;
    opacity: 0.58;
    transition: 180ms ease;
}
.stage-list li.active,
.stage-list li.done,
.stage-list li.error { opacity: 1; }
.stage-list li.active { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(33, 78, 71, 0.08); }
.stage-list li.done { background: #eef8f4; border-color: #a8d2c3; }
.stage-list li.error { background: #fff1ef; border-color: #e0aaa4; }
.stage-icon {
    width: 30px;
    height: 30px;
    display: grid;
    place-items: center;
    margin-bottom: 18px;
    color: var(--muted);
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: 50%;
    font-size: 0.75rem;
    font-weight: 800;
}
.stage-list li.active .stage-icon { color: var(--white); background: var(--primary); border-color: var(--primary); }
.stage-list li.done .stage-icon { color: var(--white); background: var(--success); border-color: var(--success); }
.stage-list li.done .stage-icon::before { content: '✓'; }
.stage-list li.done .stage-icon { font-size: 0; }
.stage-list li.done .stage-icon::before { font-size: 0.85rem; }
.stage-list li.error .stage-icon { color: var(--white); background: var(--danger); border-color: var(--danger); }
.stage-list li.error .stage-icon::before { content: '!'; }
.stage-list li.error .stage-icon { font-size: 0; }
.stage-list li.error .stage-icon::before { font-size: 0.9rem; }
.stage-list strong { display: block; margin-bottom: 5px; font-size: 0.85rem; }
.stage-list small { display: block; color: var(--muted); font-size: 0.72rem; line-height: 1.4; }
.item-progress { margin-top: 30px; padding-top: 26px; border-top: 1px solid var(--line); }
.item-progress h3 { margin-bottom: 14px; font-size: 1rem; }
.item-progress-list { display: grid; gap: 9px; }
.item-progress-row {
    display: grid;
    grid-template-columns: 52px minmax(0, 1fr) 18px;
    gap: 13px;
    align-items: center;
    min-height: 68px;
    padding: 8px 13px 8px 8px;
    background: #fafbfa;
    border: 1px solid var(--line);
    border-radius: 12px;
}
.item-progress-row.generating,
.item-progress-row.saving { border-color: var(--primary); }
.item-progress-row.completed { background: #f0f9f5; border-color: #acd6c7; }
.item-progress-row.failed { background: #fff3f1; border-color: #e0aaa4; }
.item-preview {
    width: 52px;
    height: 52px;
    display: grid;
    place-items: center;
    overflow: hidden;
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: 9px;
}
.item-preview img { width: 100%; height: 100%; object-fit: contain; }
.item-number { color: var(--muted); font-size: 0.72rem; font-weight: 800; }
.item-progress-copy strong { display: block; font-size: 0.88rem; }
.item-progress-copy span { display: block; margin-top: 2px; color: var(--muted); font-size: 0.74rem; }
.item-error { display: block; margin-top: 5px; color: var(--danger); }
.item-status {
    width: 12px;
    height: 12px;
    background: #a9b3af;
    border-radius: 50%;
}
.item-progress-row.generating .item-status,
.item-progress-row.saving .item-status { background: var(--accent); animation: pulse 1s ease-in-out infinite; }
.item-progress-row.completed .item-status { background: var(--success); }
.item-progress-row.failed .item-status { background: var(--danger); }
.progress-error {
    margin-top: 22px;
    padding: 16px 18px;
    color: #6c211c;
    background: #fff0ee;
    border: 1px solid #e0aaa4;
    border-radius: 13px;
}
.progress-error p { margin: 5px 0; }
.progress-error small { color: #8d4b46; }
@keyframes pulse { 50% { transform: scale(1.28); opacity: 0.55; } }

.results-section { padding: 90px 0 40px; }
.results-header { align-items: end; margin-bottom: 28px; }
.results-header > div:first-child { max-width: 800px; }
.results-header p:last-child { margin: 12px 0 0; color: var(--muted); }
.results-actions { display: flex; gap: 10px; }
.secondary-button { min-height: 44px; padding: 0 17px; }
.review-notes {
    margin-bottom: 24px;
    padding: 18px 20px;
    background: #fff9e8;
    border: 1px solid #ecd794;
    border-radius: 14px;
}
.review-notes ul { margin: 8px 0 0; padding-left: 20px; }
.pictogram-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.pictogram-card {
    position: relative;
    padding: 14px;
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: 18px;
    box-shadow: 0 12px 35px rgba(20, 33, 31, 0.05);
}
.card-order {
    position: absolute;
    top: 24px;
    left: 24px;
    z-index: 2;
    min-width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    color: var(--white);
    background: var(--primary);
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 800;
}
.image-frame { aspect-ratio: 1; overflow: hidden; background: #f6f7f5; border-radius: 12px; }
.image-frame img { width: 100%; height: 100%; display: block; object-fit: contain; }
.pictogram-card h3 { margin: 18px 8px 4px; font-size: clamp(1.15rem, 2vw, 1.55rem); letter-spacing: -0.03em; }
.pictogram-card > p { min-height: 48px; margin: 0 8px 14px; color: var(--muted); font-size: 0.88rem; }
.pictogram-card details { margin: 0 8px; padding: 12px 0; border-top: 1px solid var(--line); font-size: 0.82rem; }
.pictogram-card details summary { cursor: pointer; font-weight: 700; }
.pictogram-card details span { display: block; margin-top: 8px; color: var(--muted); }
.card-actions { display: flex; gap: 8px; margin: 10px 8px 4px; }
.card-actions a, .card-actions button { flex: 1; padding: 8px 10px; text-align: center; font-size: 0.75rem; }

.review-warning {
    display: grid;
    grid-template-columns: 220px 1fr;
    gap: 30px;
    margin: 70px 0;
    padding: 28px 0;
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
}
.review-warning strong { text-transform: uppercase; font-size: 0.8rem; letter-spacing: 0.08em; }
.review-warning p { margin: 0; color: var(--muted); }

.history-dialog {
    width: min(920px, calc(100% - 32px));
    max-height: 86vh;
    padding: 0;
    color: var(--ink);
    background: var(--paper);
    border: 0;
    border-radius: 20px;
    box-shadow: 0 40px 120px rgba(0, 0, 0, 0.28);
}
.history-dialog::backdrop { background: rgba(14, 24, 22, 0.68); backdrop-filter: blur(4px); }
.dialog-header { position: sticky; top: 0; z-index: 2; padding: 26px; background: rgba(244, 241, 233, 0.94); border-bottom: 1px solid var(--line); backdrop-filter: blur(8px); }
.icon-button { width: 42px; height: 42px; padding: 0; font-size: 1.6rem; }
.history-content { padding: 18px 26px 28px; }
.history-item {
    display: grid;
    grid-template-columns: 110px minmax(0, 1fr) auto;
    gap: 16px;
    align-items: center;
    padding: 14px 0;
    border-bottom: 1px solid var(--line);
}
.history-item img, .history-placeholder { width: 110px; height: 110px; object-fit: contain; background: var(--white); border-radius: 12px; }
.history-placeholder { display: grid; place-items: center; }
.history-copy span, .history-copy small { color: var(--muted); font-size: 0.72rem; }
.history-copy h3 { margin: 4px 0; }
.history-copy p { max-width: 540px; margin: 0 0 5px; color: var(--muted); font-size: 0.82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-actions { display: flex; flex-direction: column; gap: 8px; }
.history-actions button { font-size: 0.75rem; }
.history-actions .danger-link { color: var(--danger); }
.empty-state, .error-state { padding: 50px 10px; text-align: center; color: var(--muted); }
.error-state { color: var(--danger); }

.toast {
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 20;
    max-width: min(440px, calc(100% - 44px));
    padding: 14px 18px;
    color: var(--white);
    background: var(--ink);
    border-radius: 12px;
    box-shadow: var(--shadow);
    opacity: 0;
    transform: translateY(18px);
    pointer-events: none;
    transition: 180ms ease;
}
.toast.visible { opacity: 1; transform: translateY(0); }
.toast[data-type="error"] { background: var(--danger); }
.toast[data-type="success"] { background: var(--success); }

@media (max-width: 1100px) {
    .stage-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .stage-list li:last-child { grid-column: span 2; min-height: auto; }
}

@media (max-width: 980px) {
    .hero, .workspace { grid-template-columns: 1fr; }
    .hero { gap: 32px; padding-top: 64px; }
    .hero-note { max-width: 620px; }
    .pictogram-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 680px) {
    .site-header, main { width: min(100% - 24px, 1440px); }
    .site-header { min-height: 76px; }
    .brand small { display: none; }
    .hero { padding: 50px 0 42px; }
    h1 { font-size: clamp(2.65rem, 14vw, 4.5rem); }
    .generator-panel, .principles-panel { padding: 24px 18px; }
    .section-heading, .results-header, .progress-heading { display: block; }
    .progress-percent { margin-top: 14px; text-align: left; }
    .stage-list { grid-template-columns: 1fr; }
    .stage-list li:last-child { grid-column: auto; }
    .stage-list li { min-height: auto; }
    .status-dot { display: inline-block; margin-top: 16px; }
    .settings-grid, .pictogram-grid { grid-template-columns: 1fr; }
    .results-actions { margin-top: 18px; }
    .review-warning { grid-template-columns: 1fr; gap: 8px; }
    .history-item { grid-template-columns: 76px 1fr; }
    .history-item img, .history-placeholder { width: 76px; height: 76px; }
    .history-actions { grid-column: 1 / -1; flex-direction: row; }
}

@media print {
    body { background: #fff; }
    .site-header, .hero, .workspace, .progress-section, .results-actions, .review-warning, .card-actions, .pictogram-card details, .toast { display: none !important; }
    main { width: 100%; }
    .results-section { display: block !important; padding: 0; }
    .results-header { margin-bottom: 20px; }
    .pictogram-grid { grid-template-columns: repeat(2, 1fr); gap: 10mm; }
    .pictogram-card { break-inside: avoid; box-shadow: none; }
}
