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

:root {
    --bg: #f7f6f3;
    --card: #ffffff;
    --text: #1a1a2e;
    --text-muted: #64648c;
    --border: #e2e1dc;
    --blue: #3b82f6;
    --blue-soft: #eff6ff;
    --green: #10b981;
    --green-soft: #ecfdf5;
    --amber: #f59e0b;
    --amber-soft: #fffbeb;
    --indigo: #6366f1;
    --indigo-soft: #eef2ff;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
    font-size: 17px;
    line-height: 1.65;
    color: var(--text);
    background: var(--bg);
    min-height: 100vh;
    min-height: 100dvh;
    -webkit-font-smoothing: antialiased;
}

.container {
    max-width: 920px;
    margin: 0 auto;
    padding: 20px 16px 60px;
}

/* Header */
header {
    text-align: center;
    margin-bottom: 20px;
}

header h1 {
    font-size: 1.8rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    color: var(--text);
    margin-bottom: 2px;
}

header .subtitle {
    font-size: 0.85rem;
    color: var(--text-muted);
    letter-spacing: 0.02em;
}

/* TAPER Steps */
.steps {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.step {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 5px 10px;
    border-radius: 20px;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    background: var(--card);
    color: var(--text-muted);
    border: 1px solid var(--border);
    transition: all 0.3s ease;
}

.step .dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--border);
    transition: background 0.3s ease;
}

.step.complete {
    background: var(--green-soft);
    color: var(--green);
    border-color: var(--green);
}

.step.complete .dot {
    background: var(--green);
}

.step.active {
    background: var(--blue-soft);
    color: var(--blue);
    border-color: var(--blue);
}

.step.active .dot {
    background: var(--blue);
}

/* Input Section */
.input-section {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}

/* Mode Tabs */
.input-mode-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.mode-tab {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 16px;
    background: var(--bg);
    border: 2px solid var(--border);
    border-radius: 10px;
    font-size: 0.92rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
}

.mode-tab:hover {
    border-color: var(--blue);
    color: var(--text);
}

.mode-tab.active {
    background: var(--blue-soft);
    border-color: var(--blue);
    color: var(--blue);
}

.mode-tab svg {
    flex-shrink: 0;
}

/* Camera/Photo Input */
.hidden-input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

.photo-label {
    display: block;
    cursor: pointer;
}

.photo-target {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 40px 20px;
    border: 2px dashed var(--border);
    border-radius: 10px;
    color: var(--text-muted);
    text-align: center;
    transition: all 0.2s;
    min-height: 160px;
}

.photo-target:active {
    background: var(--blue-soft);
    border-color: var(--blue);
}

.photo-target span {
    font-size: 1rem;
    font-weight: 500;
}

.photo-hint {
    font-size: 0.82rem !important;
    font-weight: 400 !important;
    opacity: 0.7;
}

.photo-preview {
    width: 100%;
    max-height: 300px;
    object-fit: contain;
    border-radius: 10px;
    border: 1px solid var(--border);
}

.photo-preview.hidden {
    display: none;
}

/* OCR Status */
.ocr-status {
    padding: 12px 16px;
    margin-top: 12px;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    text-align: center;
}

.ocr-status.hidden {
    display: none;
}

.ocr-status.processing {
    background: var(--blue-soft);
    color: var(--blue);
}

.ocr-status.done {
    background: var(--green-soft);
    color: var(--green);
}

.ocr-status.error {
    background: #fef2f2;
    color: #dc2626;
}

/* OCR Text Preview */
.ocr-text-preview {
    margin-top: 12px;
}

.ocr-text-preview.hidden {
    display: none;
}

.ocr-text-preview label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: 0.82rem;
    margin-bottom: 8px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.ocr-text {
    padding: 14px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.92rem;
    line-height: 1.6;
    max-height: 200px;
    overflow-y: auto;
    white-space: pre-wrap;
    margin-bottom: 8px;
}

/* Input Panels */
.input-panel {
    margin-bottom: 12px;
}

.input-panel.hidden {
    display: none;
}

.input-section label {
    display: block;
    font-weight: 600;
    font-size: 0.82rem;
    margin-bottom: 8px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

#text-input {
    width: 100%;
    min-height: 140px;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-family: inherit;
    font-size: 16px;
    line-height: 1.6;
    color: var(--text);
    background: var(--bg);
    resize: vertical;
    transition: border-color 0.2s;
}

#text-input:focus {
    outline: none;
    border-color: var(--blue);
}

#text-input::placeholder {
    color: #b0b0c0;
}

/* Buttons */
.input-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

.btn-primary {
    flex: 1;
    padding: 14px 24px;
    background: var(--blue);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 1.05rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    letter-spacing: 0.02em;
    -webkit-tap-highlight-color: transparent;
}

.btn-primary:hover {
    background: #2563eb;
}

.btn-primary:active {
    transform: scale(0.98);
}

.btn-primary:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

.btn-secondary {
    padding: 8px 16px;
    background: var(--bg);
    color: var(--text-muted);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-secondary:hover {
    border-color: var(--text-muted);
    color: var(--text);
}

.btn-ghost {
    padding: 14px 20px;
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 0.92rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
}

.btn-ghost:hover {
    border-color: var(--text-muted);
    color: var(--text);
}

.word-count {
    font-size: 0.82rem;
    color: var(--text-muted);
    text-align: right;
    margin-top: 6px;
    font-weight: 400;
    text-transform: none;
    letter-spacing: 0;
}

/* Output Section */
.output-section {
    margin-bottom: 20px;
}

.output-section.hidden {
    display: none;
}

/* Tier Tabs — horizontal scroll on mobile */
.tier-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 0;
}

.tier-tabs::-webkit-scrollbar {
    display: none;
}

.tier-tab {
    padding: 10px 14px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-bottom: none;
    border-radius: 10px 10px 0 0;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
    top: 1px;
    white-space: nowrap;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 6px;
    -webkit-tap-highlight-color: transparent;
}

.tier-tab:hover {
    background: var(--card);
    color: var(--text);
}

.tier-tab.active {
    background: var(--card);
    color: var(--blue);
    border-color: var(--border);
    border-bottom-color: var(--card);
}

.tier-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    font-size: 0.7rem;
    background: var(--border);
    color: var(--text-muted);
    flex-shrink: 0;
}

.tier-tab.active .tier-num {
    background: var(--blue);
    color: white;
}

.tier-label {
    display: inline;
}

/* Tier Content */
.tier-content {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 0 var(--radius) var(--radius) var(--radius);
    padding: 20px;
    min-height: 120px;
    box-shadow: var(--shadow);
}

.tier-text {
    font-size: 1.02rem;
    line-height: 1.7;
    white-space: pre-wrap;
}

/* Anchors View */
.anchors-view {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.anchors-view h3 {
    font-size: 0.82rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.nodes-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.anchor-node {
    display: inline-block;
    padding: 8px 16px;
    background: var(--amber-soft);
    color: #92400e;
    border: 1px solid #fcd34d;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: 600;
}

.anchor-edges {
    padding: 14px;
    background: var(--indigo-soft);
    border-radius: 8px;
}

.anchor-edge {
    padding: 5px 0;
    font-size: 0.92rem;
    color: var(--indigo);
    font-weight: 500;
}

.core-meaning {
    padding: 14px;
    background: var(--green-soft);
    border-radius: 8px;
    border-left: 4px solid var(--green);
}

.core-meaning p {
    font-size: 1rem;
    font-weight: 500;
    color: #065f46;
}

/* Notes Section */
.notes-section {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
}

.notes-section.hidden {
    display: none;
}

.notes-section label {
    display: block;
    font-weight: 600;
    font-size: 0.82rem;
    margin-bottom: 4px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.notes-hint {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 10px;
}

#notes {
    width: 100%;
    min-height: 100px;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-family: inherit;
    font-size: 16px;
    line-height: 1.6;
    color: var(--text);
    background: var(--bg);
    resize: vertical;
}

#notes:focus {
    outline: none;
    border-color: var(--green);
}

/* Loading */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(247, 246, 243, 0.88);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
}

.loading-overlay.hidden {
    display: none;
}

.spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.spinner-ring {
    width: 44px;
    height: 44px;
    border: 3px solid var(--border);
    border-top-color: var(--blue);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.spinner-text {
    font-size: 0.95rem;
    color: var(--text-muted);
    font-weight: 500;
    text-align: center;
    padding: 0 20px;
}

/* Guardrail Notice */
.guardrail {
    text-align: center;
    padding: 16px 12px;
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 24px;
    line-height: 1.5;
}

.guardrail strong {
    color: var(--text);
}

/* Auth */
.hidden {
    display: none !important;
}

.auth-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 32px 24px;
    box-shadow: var(--shadow);
    max-width: 400px;
    margin: 0 auto;
}

.auth-card h2 {
    font-size: 1.3rem;
    margin-bottom: 6px;
}

.auth-desc {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 20px;
}

.auth-input {
    display: block;
    width: 100%;
    padding: 14px 16px;
    margin-bottom: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-family: inherit;
    font-size: 16px;
    color: var(--text);
    background: var(--bg);
    transition: border-color 0.2s;
}

.auth-input:focus {
    outline: none;
    border-color: var(--blue);
}

.auth-card .btn-primary {
    width: 100%;
    margin-top: 4px;
}

.auth-switch {
    text-align: center;
    margin-top: 16px;
    font-size: 0.88rem;
    color: var(--text-muted);
}

.auth-switch a {
    color: var(--blue);
    text-decoration: none;
    font-weight: 600;
}

.auth-error {
    text-align: center;
    padding: 10px;
    margin-top: 12px;
    background: #fef2f2;
    color: #dc2626;
    border-radius: 8px;
    font-size: 0.88rem;
    font-weight: 500;
}

.logout-link {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.82rem;
}

.logout-link:hover {
    color: var(--text);
}

/* Mobile tweaks */
@media (max-width: 600px) {
    .container {
        padding: 16px 12px 40px;
    }

    header h1 {
        font-size: 1.5rem;
    }

    .steps {
        gap: 4px;
    }

    .step {
        padding: 4px 8px;
        font-size: 0.65rem;
    }

    .tier-tab {
        padding: 8px 10px;
        font-size: 0.78rem;
    }

    .tier-label {
        display: none;
    }

    .tier-content {
        padding: 16px;
    }

    .tier-text {
        font-size: 0.95rem;
    }

    .photo-target {
        padding: 30px 16px;
        min-height: 130px;
    }
}
