:root {
    color-scheme: light;
    --ink: #171916;
    --muted: #656a63;
    --line: #d9ddd5;
    --paper: #f5f5f0;
    --surface: #ffffff;
    --surface-soft: #eceee8;
    --charcoal: #20241f;
    --accent: #d94f2b;
    --accent-strong: #b93d20;
    --green: #2f6e4f;
    --green-soft: #e5f1e9;
    --amber: #a16614;
    --danger: #b33a35;
    --shadow: 0 18px 55px rgba(28, 34, 27, 0.12);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { min-width: 320px; overflow-x: hidden; background: var(--paper); }

body {
    margin: 0;
    min-height: 100dvh;
    overflow-x: hidden;
    color: var(--ink);
    background: var(--paper);
    font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    -webkit-font-smoothing: antialiased;
}

button, input, textarea, select { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
a { color: inherit; }

.app-shell { min-height: 100dvh; display: flex; flex-direction: column; }

.app-header {
    position: sticky;
    top: 0;
    z-index: 20;
    min-height: 68px;
    padding: 10px clamp(16px, 3vw, 44px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    background: rgba(245, 245, 240, 0.94);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(14px);
}

.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; min-width: 0; }
.brand-mark {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    color: #fff;
    background: var(--charcoal);
    border-radius: 6px;
}
.brand-mark svg { width: 22px; height: 22px; }
.brand > span:last-child { display: grid; line-height: 1.15; }
.brand strong { font-size: 15px; }
.brand small { margin-top: 4px; color: var(--muted); font-size: 11px; font-weight: 600; }

.header-actions { display: flex; align-items: center; gap: 8px; }
.quota-chip, .active-config {
    min-height: 38px;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 0 11px;
    color: #3f443e;
    background: var(--surface-soft);
    border: 1px solid var(--line);
    border-radius: 6px;
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
}
.quota-chip svg { width: 16px; }

main { flex: 1; }

.btn, .icon-btn, .field-icon {
    border: 0;
    border-radius: 6px;
    transition: background-color 160ms ease, border-color 160ms ease, color 160ms ease, transform 160ms ease;
}

.btn {
    min-height: 40px;
    padding: 9px 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 750;
}
.btn svg { width: 17px; height: 17px; flex: 0 0 auto; }
.btn-primary { color: #fff; background: var(--accent); }
.btn-primary:hover:not(:disabled) { background: var(--accent-strong); }
.btn-secondary { color: #fff; background: var(--charcoal); }
.btn-secondary:hover:not(:disabled) { background: #343a32; }
.btn-quiet { color: var(--ink); background: var(--surface-soft); border: 1px solid var(--line); }
.btn-quiet:hover:not(:disabled) { background: #e2e5de; }
.btn-block { width: 100%; }
.btn:active:not(:disabled), .icon-btn:active:not(:disabled), .field-icon:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.46; cursor: not-allowed; }
.btn:focus-visible, .icon-btn:focus-visible, .field-icon:focus-visible,
input:focus-visible, textarea:focus-visible, select:focus-visible, [tabindex]:focus-visible {
    outline: 3px solid rgba(217, 79, 43, 0.24);
    outline-offset: 2px;
}

.icon-btn, .field-icon {
    width: 40px;
    height: 40px;
    display: inline-grid;
    place-items: center;
    color: var(--ink);
    background: transparent;
    border: 1px solid var(--line);
}
.icon-btn:hover, .field-icon:hover { background: var(--surface-soft); }
.icon-btn svg, .field-icon svg { width: 18px; height: 18px; }

.auth-layout {
    width: min(1080px, calc(100% - 32px));
    min-height: min(690px, calc(100vh - 118px));
    margin: 24px auto;
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) minmax(340px, 0.8fr);
    overflow: hidden;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.auth-visual { position: relative; min-height: 560px; overflow: hidden; background: #252822; }
.auth-visual::after {
    content: "";
    position: absolute;
    inset: 55% 0 0;
    background: rgba(10, 12, 9, 0.68);
    pointer-events: none;
}
.auth-visual img { width: 100%; height: 100%; display: block; object-fit: cover; }
.auth-visual-copy { position: absolute; z-index: 1; left: 36px; right: 36px; bottom: 34px; color: #fff; }
.auth-visual-copy p { max-width: 520px; margin: 0 0 10px; font-family: Georgia, serif; font-size: 48px; line-height: 1.04; }
.auth-visual-copy span { display: block; max-width: 480px; color: rgba(255,255,255,.82); font-size: 14px; line-height: 1.65; }

.auth-form { align-self: center; padding: clamp(28px, 5vw, 58px); }
.auth-heading { margin-bottom: 24px; }
.eyebrow { margin: 0 0 7px; color: var(--accent); font-size: 11px; font-weight: 800; text-transform: uppercase; }
.auth-heading h1, .workspace-bar h1 { margin: 0; font-size: 36px; line-height: 1.12; }
.auth-heading h1 { font-size: 30px; }

.segmented {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 3px;
    padding: 3px;
    margin-bottom: 22px;
    background: var(--surface-soft);
    border: 1px solid var(--line);
    border-radius: 7px;
}
.segmented button {
    min-height: 36px;
    padding: 6px 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    color: var(--muted);
    background: transparent;
    border: 0;
    border-radius: 5px;
    font-size: 13px;
    font-weight: 750;
}
.segmented button[aria-selected="true"] { color: var(--ink); background: #fff; box-shadow: 0 2px 8px rgba(32, 36, 31, .08); }
.segmented.compact { width: 210px; margin: 0; }
.segmented.compact svg { width: 15px; height: 15px; }

.form-field { min-width: 0; margin-bottom: 16px; }
.form-field label { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 7px; color: #3f443e; font-size: 12px; font-weight: 750; }
.form-field label span, .field-note { color: var(--muted); font-size: 11px; font-weight: 500; }
input, textarea, select {
    width: 100%;
    min-height: 42px;
    padding: 9px 11px;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid #cbd0c7;
    border-radius: 6px;
}
textarea { min-height: 82px; line-height: 1.55; resize: vertical; }
input::placeholder, textarea::placeholder { color: #989e96; }
input[type="range"] { height: 36px; padding: 0; border: 0; accent-color: var(--accent); }
.input-with-action { position: relative; }
.input-with-action input { padding-right: 48px; }
.input-with-action .field-icon { position: absolute; top: 3px; right: 3px; width: 36px; height: 36px; border: 0; }
.field-note { display: block; margin-top: 7px; line-height: 1.45; }
.form-message { min-height: 20px; margin: 10px 0 0; color: var(--danger); font-size: 12px; line-height: 1.5; }
.form-message.success { color: var(--green); }
.turnstile-container { min-height: 65px; margin-bottom: 12px; }
.turnstile-container:empty { display: none; }

.workspace { width: min(1480px, calc(100% - 32px)); margin: 0 auto; padding: 28px 0 48px; }
.workspace-bar { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 22px; }
.active-config { max-width: min(420px, 50vw); overflow: hidden; text-overflow: ellipsis; }
.status-dot { width: 8px; height: 8px; flex: 0 0 auto; background: var(--green); border-radius: 50%; box-shadow: 0 0 0 4px rgba(47,110,79,.12); }
.status-dot.offline { background: var(--amber); box-shadow: 0 0 0 4px rgba(161,102,20,.12); }
.status-dot.neutral { background: #92988f; box-shadow: none; }

.config-alert {
    margin-bottom: 16px;
    padding: 12px;
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px;
    color: #3c2b15;
    background: #fff1d8;
    border: 1px solid #e8c985;
    border-radius: 7px;
    font-size: 13px;
}
.config-alert > div { width: 34px; height: 34px; display: grid; place-items: center; color: #fff; background: var(--amber); border-radius: 6px; }
.config-alert svg { width: 17px; }
.config-alert strong { display: block; margin-bottom: 2px; }

.workspace-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(380px, .65fr); gap: 16px; align-items: start; }
.source-panel, .result-panel { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.source-panel { padding: 18px; }
.result-panel { position: sticky; top: 84px; min-height: 650px; overflow: hidden; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 14px; }
.panel-heading.slim { margin: 0 0 14px; }
.panel-heading h2, .history-heading h2 { margin: 0; font-size: 18px; }
.optional-label { color: var(--muted); font-size: 11px; }

.media-stage {
    position: relative;
    width: 100%;
    aspect-ratio: 4 / 3;
    max-height: 620px;
    display: grid;
    place-items: center;
    overflow: hidden;
    color: #d8ddd5;
    background: #20231f;
    border-radius: 7px;
}
.upload-zone, .camera-placeholder { width: 100%; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 9px; text-align: center; }
.upload-zone { border: 1px dashed #72796f; touch-action: manipulation; user-select: none; }
.upload-zone:hover, .upload-zone.dragging { background: #292d27; border-color: #d6dcd2; }
.upload-zone strong, .camera-placeholder strong { color: #fff; font-size: 16px; }
.upload-zone span, .camera-placeholder span { max-width: 360px; padding: 0 18px; color: #aeb5ab; font-size: 12px; line-height: 1.55; }
.upload-symbol { width: 52px; height: 52px; display: grid; place-items: center; color: var(--charcoal); background: #f4c849; border-radius: 7px; }
.upload-symbol svg { width: 24px; height: 24px; }
.camera-placeholder > svg { width: 42px; height: 42px; color: #f4c849; }
.photo-preview, #cameraPreview { width: 100%; height: 100%; display: block; object-fit: contain; background: #171916; }
.media-badge { position: absolute; left: 12px; bottom: 12px; max-width: calc(100% - 24px); padding: 6px 9px; overflow: hidden; color: #fff; background: rgba(23,25,22,.82); border-radius: 5px; font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.media-actions { min-height: 50px; display: flex; align-items: center; gap: 8px; padding: 10px 0 0; }

.shooting-context { padding-top: 16px; border-top: 1px solid var(--line); }
.context-grid, .form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.full-row { grid-column: 1 / -1; }
.character-count { display: block; margin-top: 4px; color: var(--muted); font-size: 10px; text-align: right; }

.analyze-bar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding-top: 6px; }
.analysis-status { min-width: 0; display: flex; align-items: center; gap: 9px; color: var(--muted); font-size: 12px; }
.analysis-status span:last-child { overflow: hidden; text-overflow: ellipsis; }
.analyze-button { min-width: 180px; }
.progress-track { width: 100%; height: 3px; margin-top: 12px; overflow: hidden; background: var(--surface-soft); border-radius: 2px; }
.progress-track span { display: block; width: 4%; height: 100%; background: var(--accent); transition: width 400ms ease; }

.result-tabs { height: 54px; display: grid; grid-template-columns: 1fr 1fr; border-bottom: 1px solid var(--line); }
.result-tabs button { display: inline-flex; align-items: center; justify-content: center; gap: 7px; color: var(--muted); background: transparent; border: 0; border-bottom: 2px solid transparent; font-size: 12px; font-weight: 800; }
.result-tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.result-tabs svg { width: 16px; }
.result-view, .history-view { min-height: 595px; padding: 18px; }
.empty-result { min-height: 500px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.empty-result > div { width: 54px; height: 54px; display: grid; place-items: center; color: var(--green); background: var(--green-soft); border-radius: 7px; }
.empty-result svg { width: 25px; height: 25px; }
.empty-result h2 { margin: 18px 0 8px; font-size: 18px; }
.empty-result p { max-width: 320px; margin: 0; color: var(--muted); font-size: 13px; line-height: 1.65; }

.result-summary { margin-bottom: 16px; padding-bottom: 15px; border-bottom: 1px solid var(--line); }
.result-summary .scene { margin: 0; font-family: Georgia, serif; font-size: 28px; line-height: 1.1; }
.result-summary .light { margin: 8px 0 0; color: var(--muted); font-size: 12px; }
.parameter-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.parameter {
    min-height: 82px;
    padding: 11px;
    background: var(--surface-soft);
    border: 1px solid transparent;
    border-radius: 6px;
}
.parameter .label { display: block; margin-bottom: 8px; color: var(--muted); font-size: 10px; font-weight: 800; text-transform: uppercase; }
.parameter .value { display: block; overflow-wrap: anywhere; font-size: 15px; font-weight: 800; line-height: 1.3; }
.advice-section { margin-top: 18px; }
.advice-section h3 { margin: 0 0 9px; font-size: 12px; }
.advice-list { margin: 0; padding: 0; list-style: none; border-top: 1px solid var(--line); }
.advice-list li { display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 12px; line-height: 1.45; }
.advice-list span:first-child { color: var(--muted); }
.tip-block { padding: 12px; color: #244e39; background: var(--green-soft); border-left: 3px solid var(--green); border-radius: 0 6px 6px 0; font-size: 12px; line-height: 1.6; white-space: pre-wrap; }

.history-heading { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.history-list { display: grid; gap: 8px; }
.history-item { width: 100%; padding: 11px; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 6px; text-align: left; }
.history-item:hover { border-color: #9fa59c; background: var(--surface-soft); }
.history-item strong { display: block; overflow: hidden; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.history-item span { display: block; margin-top: 5px; color: var(--muted); font-size: 10px; }
.history-item svg { width: 16px; color: var(--muted); }
.history-empty { padding: 48px 12px; color: var(--muted); font-size: 12px; text-align: center; }

.modal-mask { position: fixed; z-index: 50; inset: 0; padding: 20px; display: grid; place-items: center; background: rgba(16,18,15,.66); }
.modal { width: min(920px, 100%); max-height: min(760px, calc(100dvh - 40px)); overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 25px 80px rgba(0,0,0,.28); }
.modal-header { position: sticky; top: 0; z-index: 2; padding: 18px 20px 12px; display: flex; align-items: center; justify-content: space-between; gap: 12px; background: var(--surface); }
.modal-header h2 { margin: 0; font-size: 21px; }
.modal-intro { margin: 0; padding: 0 20px 16px; color: var(--muted); border-bottom: 1px solid var(--line); font-size: 12px; line-height: 1.6; }
.config-layout { display: grid; grid-template-columns: 270px minmax(0, 1fr); min-height: 470px; }
.config-sidebar { padding: 16px; background: var(--surface-soft); border-right: 1px solid var(--line); }
.config-list-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; color: var(--muted); font-size: 11px; font-weight: 800; }
.config-list-heading strong { min-width: 24px; padding: 3px 7px; color: var(--ink); background: #fff; border: 1px solid var(--line); border-radius: 5px; text-align: center; }
.config-list { display: grid; gap: 7px; margin-bottom: 10px; }
.config-item { padding: 10px; background: #fff; border: 1px solid var(--line); border-radius: 6px; }
.config-item.active { border-color: #83ac95; box-shadow: inset 3px 0 var(--green); }
.config-item-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.config-item strong { display: block; overflow: hidden; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.config-item p { margin: 5px 0 9px; overflow: hidden; color: var(--muted); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.active-badge { padding: 3px 5px; color: var(--green); background: var(--green-soft); border-radius: 4px; font-size: 9px; font-weight: 800; white-space: nowrap; }
.config-item-actions { display: flex; gap: 5px; }
.config-item-actions button { min-height: 29px; padding: 5px 7px; flex: 1; color: var(--ink); background: var(--surface-soft); border: 0; border-radius: 5px; font-size: 10px; font-weight: 700; }
.config-item-actions button.danger { color: var(--danger); }
.config-form { padding: 20px; }
.config-form-actions { display: flex; gap: 8px; }

.switch-field { min-height: 58px; margin-top: 2px; padding: 8px 0; display: flex; align-items: center; justify-content: space-between; gap: 10px; cursor: pointer; }
.switch-field > span:first-child { display: grid; gap: 4px; }
.switch-field strong { font-size: 12px; }
.switch-field small { color: var(--muted); font-size: 10px; }
.switch-field input { position: absolute; opacity: 0; pointer-events: none; }
.switch { position: relative; width: 38px; height: 22px; flex: 0 0 auto; background: #bbc0b7; border-radius: 12px; transition: background 160ms ease; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; background: #fff; border-radius: 50%; transition: transform 160ms ease; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.switch-field input:checked + .switch { background: var(--green); }
.switch-field input:checked + .switch::after { transform: translateX(16px); }

.toast-region { position: fixed; z-index: 80; right: 16px; bottom: 16px; display: grid; gap: 8px; pointer-events: none; }
.toast { width: min(340px, calc(100vw - 32px)); padding: 11px 13px; color: #fff; background: var(--charcoal); border-radius: 6px; box-shadow: var(--shadow); font-size: 12px; line-height: 1.5; animation: toast-in 180ms ease-out; }
.toast.error { background: var(--danger); }
.spinner { width: 15px; height: 15px; border: 2px solid rgba(255,255,255,.45); border-top-color: #fff; border-radius: 50%; animation: spin 700ms linear infinite; }
.spin-icon { animation: spin 1200ms linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.site-footer { min-height: 44px; padding: 12px 20px; display: flex; align-items: center; justify-content: center; gap: 14px; color: #777d74; font-size: 10px; }
.site-footer a { text-decoration: none; }
.site-footer a:hover { color: var(--accent); }

@media (max-width: 1080px) {
    .workspace-grid { grid-template-columns: minmax(0, 1fr) 360px; }
    .parameter-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 860px) {
    .auth-layout { grid-template-columns: 1fr; min-height: 0; }
    .auth-visual { min-height: 260px; max-height: 34vh; }
    .auth-visual-copy { left: 24px; right: 24px; bottom: 22px; }
    .auth-visual-copy p { font-size: 30px; }
    .workspace-grid { grid-template-columns: 1fr; }
    .result-panel { position: static; min-height: 500px; }
    .result-view, .history-view { min-height: 445px; }
    .empty-result { min-height: 370px; }
}

@media (max-width: 640px) {
    .app-header { min-height: 60px; padding: calc(9px + env(safe-area-inset-top)) 12px 9px; }
    .brand small { display: none; }
    .brand-mark { width: 34px; height: 34px; }
    .quota-chip { display: none; }
    .header-actions .btn { width: 44px; padding: 0; }
    .header-actions .btn span { display: none; }
    .auth-layout { width: 100%; margin: 0; border-width: 0; border-radius: 0; box-shadow: none; }
    .auth-visual { min-height: 230px; }
    .auth-form { padding: 26px 20px 38px; }
    .workspace { width: 100%; padding: 18px 10px calc(36px + env(safe-area-inset-bottom)); }
    .workspace-bar { align-items: flex-start; flex-direction: column; gap: 12px; padding: 0 4px; }
    .workspace-bar h1 { font-size: 27px; }
    .active-config { max-width: 100%; }
    .config-alert { grid-template-columns: 34px minmax(0, 1fr); }
    .config-alert .btn { grid-column: 1 / -1; width: 100%; }
    .source-panel { padding: 12px; }
    .panel-heading { align-items: flex-start; flex-direction: column; gap: 10px; }
    .panel-heading.slim { flex-direction: row; align-items: center; }
    .segmented.compact { width: 100%; }
    .media-stage { aspect-ratio: 1 / 1; }
    .context-grid, .form-grid { grid-template-columns: 1fr; gap: 0; }
    input, textarea, select { min-height: 44px; font-size: 16px; }
    input[type="range"] { height: 44px; }
    .input-with-action .field-icon { top: 0; right: 0; width: 44px; height: 44px; }
    .btn { min-height: 44px; }
    .icon-btn { width: 44px; height: 44px; }
    .analyze-bar {
        position: sticky;
        z-index: 4;
        bottom: 0;
        align-items: stretch;
        flex-direction: column;
        margin: 0 -12px;
        padding: 12px 12px calc(10px + env(safe-area-inset-bottom));
        background: rgba(255, 255, 255, .96);
        border-top: 1px solid var(--line);
        box-shadow: 0 -8px 18px rgba(28, 34, 27, .08);
        backdrop-filter: blur(10px);
    }
    .analyze-button { width: 100%; }
    .config-layout { grid-template-columns: 1fr; }
    .config-sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
    .modal-mask { padding: 0; align-items: end; }
    .modal { width: 100%; max-height: 94dvh; border-radius: 8px 8px 0 0; }
    .modal-header { padding-top: calc(14px + env(safe-area-inset-top)); }
    .modal-intro { padding-bottom: 14px; }
    .config-form { padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
    .config-form-actions .btn { flex: 1; }
    .toast-region { bottom: calc(16px + env(safe-area-inset-bottom)); }
    .site-footer { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
}

@media (pointer: coarse) {
    .segmented button, .result-tabs button { min-height: 44px; }
    .history-item { min-height: 58px; padding: 13px 12px; }
    .config-item-actions button { min-height: 44px; }
    .switch-field { min-height: 64px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
