:root {
    --bg-primary: #fafafa;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f5f5f5;
    --bg-hover: #f0f0f0;
    --border-primary: #e5e5e5;
    --border-secondary: #d4d4d4;
    --border-focus: #171717;
    --text-primary: #171717;
    --text-secondary: #525252;
    --text-tertiary: #737373;
    --text-inverse: #ffffff;
    --accent-primary: #171717;
    --accent-hover: #404040;
    --accent-subtle: #e5e5e5;
    --success-bg: #f0fdf4;
    --success-text: #166534;
    --success-border: #bbf7d0;
    --error-bg: #fef2f2;
    --error-text: #991b1b;
    --error-border: #fecaca;
    --info-bg: #f0f9ff;
    --info-text: #075985;
    --info-border: #bae6fd;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -2px rgba(0,0,0,0.05);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -4px rgba(0,0,0,0.04);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --transition-fast: 150ms ease;
    --transition-base: 200ms ease;
    --transition-slow: 300ms ease;
    --font-mono: 'SF Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
}

[data-theme="dark"] {
    --bg-primary: #0a0a0a;
    --bg-secondary: #171717;
    --bg-tertiary: #1f1f1f;
    --bg-hover: #262626;
    --border-primary: #2e2e2e;
    --border-secondary: #404040;
    --border-focus: #fafafa;
    --text-primary: #fafafa;
    --text-secondary: #a3a3a3;
    --text-tertiary: #737373;
    --text-inverse: #0a0a0a;
    --accent-primary: #fafafa;
    --accent-hover: #d4d4d4;
    --accent-subtle: #262626;
    --success-bg: #052e16;
    --success-text: #86efac;
    --success-border: #166534;
    --error-bg: #450a0a;
    --error-text: #fecaca;
    --error-border: #991b1b;
    --info-bg: #082f49;
    --info-text: #bae6fd;
    --info-border: #075985;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.4), 0 2px 4px -2px rgba(0,0,0,0.3);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.5), 0 4px 6px -4px rgba(0,0,0,0.4);
}

*,*::before,*::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
    transition: background var(--transition-slow), color var(--transition-slow);
}
body::before {
    content: '';
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background-image: radial-gradient(circle, var(--border-primary) 1px, transparent 1px);
    background-size: 32px 32px;
    opacity: 0.4;
    pointer-events: none;
    z-index: -1;
}
.app-container { max-width: 1100px; margin: 0 auto; padding: 2rem 1.5rem; position: relative; }

h1, h2, h3 { font-weight: 700; letter-spacing: -0.02em; line-height: 1.2; }
.app-title { font-size: 1.75rem; font-weight: 800; color: var(--text-primary); }
.app-subtitle { font-size: 0.85rem; color: var(--text-tertiary); margin-top: 0.15rem; }
label { font-size: 0.85rem; font-weight: 600; color: var(--text-secondary); display: block; margin-bottom: 0.4rem; }
.label-required { color: var(--error-text); }
.label-hint { font-weight: 400; color: var(--text-tertiary); font-size: 0.8rem; }

.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2.5rem;
    flex-wrap: wrap;
    gap: 1rem;
}
.header-left { display: flex; align-items: center; gap: 0.75rem; }

.logo-mark {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.logo-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
}
.logo-fallback {
    font-size: 1.6rem;
    color: var(--text-inverse);
    background: var(--accent-primary);
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
}

.header-right { display: flex; align-items: center; gap: 0.5rem; }
.btn-icon-header, .theme-toggle {
    width: 40px; height: 40px;
    border: 1px solid var(--border-primary);
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    font-size: 1rem;
    color: var(--text-secondary);
    transition: all var(--transition-base);
}
.btn-icon-header:hover, .theme-toggle:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--border-secondary);
}

.main-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
@media (max-width: 850px) { .main-grid { grid-template-columns: 1fr; } }

.card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-xl);
    padding: 1.75rem;
    box-shadow: var(--shadow-sm);
    transition: box-shadow var(--transition-base), border-color var(--transition-base);
}
.card:hover { box-shadow: var(--shadow-md); border-color: var(--border-secondary); }
.card-header-main {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
    padding-bottom: 1.25rem;
    border-bottom: 1px solid var(--border-primary);
}
.card-header-main h2 { font-size: 1.2rem; color: var(--text-primary); }
.card-header-main p { font-size: 0.8rem; color: var(--text-tertiary); margin-top: 0.15rem; }
.card-badge {
    width: 40px; height: 40px;
    border-radius: var(--radius-md);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.1rem;
    flex-shrink: 0;
}
.generate-badge { background: var(--accent-subtle); color: var(--accent-primary); }
.verify-badge { background: var(--accent-subtle); color: var(--accent-primary); }

.field-group { margin-bottom: 1.25rem; }
.input-wrapper { position: relative; }
.input-field {
    width: 100%;
    padding: 0.7rem 2.6rem 0.7rem 0.9rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    font-family: var(--font-mono);
    color: var(--text-primary);
    outline: none;
    transition: all var(--transition-base);
}
.input-field::placeholder { color: var(--text-tertiary); font-family: 'Inter', sans-serif; }
.input-field:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(23,23,23,0.1);
    background: var(--bg-secondary);
}
[data-theme="dark"] .input-field:focus { box-shadow: 0 0 0 3px rgba(250,250,250,0.1); }
.textarea-field { padding: 0.7rem 0.9rem; resize: vertical; min-height: 80px; }
.input-action {
    position: absolute;
    right: 8px; top: 50%; transform: translateY(-50%);
    background: none; border: none;
    color: var(--text-tertiary);
    cursor: pointer; padding: 6px; border-radius: var(--radius-sm);
    font-size: 0.9rem;
    transition: color var(--transition-base);
}
.input-action:hover { color: var(--text-primary); }

.strength-meter {
    margin-top: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.6rem;
}
.strength-bar {
    flex: 1; height: 4px;
    background: var(--border-primary);
    border-radius: 4px;
    overflow: hidden;
}
.strength-fill {
    height: 100%; width: 0%;
    border-radius: 4px;
    transition: width var(--transition-base), background var(--transition-base);
}
.strength-fill.weak { background: #ef4444; width: 25%; }
.strength-fill.fair { background: #f59e0b; width: 50%; }
.strength-fill.good { background: #22c55e; width: 75%; }
.strength-fill.strong { background: #16a34a; width: 100%; }
.strength-text { font-size: 0.75rem; font-weight: 600; min-width: 45px; }
.strength-text.weak { color: #ef4444; }
.strength-text.fair { color: #f59e0b; }
.strength-text.good { color: #22c55e; }
.strength-text.strong { color: #16a34a; }

.cost-control-group {
    display: flex;
    align-items: center;
    gap: 1rem;
}
.slider-wrapper {
    flex: 1;
    min-width: 0;
}
.range-slider {
    width: 100%;
    -webkit-appearance: none;
    appearance: none;
    height: 6px;
    background: var(--border-primary);
    border-radius: 6px;
    outline: none;
    cursor: pointer;
}
.range-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    background: var(--accent-primary);
    border-radius: 50%;
    cursor: pointer;
    transition: transform var(--transition-fast);
}
.range-slider::-webkit-slider-thumb:hover { transform: scale(1.2); }
.slider-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.7rem;
    color: var(--text-tertiary);
    margin-top: 0.25rem;
}
.cost-number-input {
    width: 60px;
    height: 40px;
    background: var(--accent-primary);
    color: var(--text-inverse);
    border-radius: var(--radius-sm);
    border: none;
    font-weight: 700;
    font-size: 1rem;
    font-family: var(--font-mono);
    text-align: center;
    padding: 0 4px;
    box-sizing: border-box;
    -moz-appearance: textfield;
    outline: none;
    flex-shrink: 0;
}
.cost-number-input:focus {
    outline: 2px solid var(--border-focus);
    outline-offset: 2px;
}
.cost-number-input::-webkit-outer-spin-button,
.cost-number-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.btn-primary {
    width: 100%;
    border: none;
    background: var(--accent-primary);
    color: var(--text-inverse);
    border-radius: var(--radius-md);
    padding: 0.8rem 1.2rem;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-base);
    position: relative;
    font-family: 'Inter', sans-serif;
    min-height: 48px;
}
.btn-content { display: flex; align-items: center; justify-content: center; gap: 0.5rem; }
.btn-loader { display: none; align-items: center; justify-content: center; gap: 0.5rem; }
.btn-primary.loading .btn-content { display: none; }
.btn-primary.loading .btn-loader { display: flex; }
.btn-primary:hover:not(:disabled) {
    background: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}
.btn-primary:active:not(:disabled) { transform: translateY(0); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }
.btn-secondary-mod {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-primary);
}
.btn-secondary-mod:hover:not(:disabled) {
    background: var(--bg-hover);
    color: var(--text-primary);
}
.spinner {
    width: 18px; height: 18px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
.spinner-dark {
    border-color: rgba(0,0,0,0.15);
    border-top-color: var(--text-primary);
}
@keyframes spin { to { transform: rotate(360deg); } }

.btn-copy {
    display: inline-flex; align-items: center; gap: 0.35rem;
    background: none; border: 1px solid var(--border-primary);
    padding: 0.4rem 0.7rem; border-radius: var(--radius-sm);
    font-size: 0.8rem; font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-base);
    font-family: 'Inter', sans-serif;
}
.btn-copy:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--border-secondary);
}

.output-panel {
    margin-top: 1.25rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg);
    overflow: hidden;
    animation: slideUp var(--transition-slow) ease-out;
}
.output-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 0.7rem 1rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-primary);
    font-size: 0.8rem; font-weight: 600;
    color: var(--text-secondary);
}
.output-label { display: flex; align-items: center; gap: 0.4rem; }
.output-label i { color: #22c55e; }
.output-hash-container { padding: 0.8rem 1rem; }
.hash-code {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--text-primary);
    word-break: break-all;
    line-height: 1.5;
}

.result-panel {
    margin-top: 1.25rem;
    padding: 1rem 1.2rem;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 0.9rem;
    display: flex; align-items: center; gap: 0.5rem;
    animation: slideUp var(--transition-slow) ease-out;
}
.result-panel.match {
    background: var(--success-bg);
    color: var(--success-text);
    border: 1px solid var(--success-border);
}
.result-panel.no-match {
    background: var(--error-bg);
    color: var(--error-text);
    border: 1px solid var(--error-border);
}

.history-panel {
    position: fixed;
    top: 0; right: 0; bottom: 0;
    width: 380px; max-width: 90vw;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border-primary);
    z-index: 1000;
    transform: translateX(100%);
    transition: transform var(--transition-slow) ease;
    display: flex; flex-direction: column;
    box-shadow: var(--shadow-lg);
}
.history-panel.open { transform: translateX(0); }
.history-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 999;
}
.history-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-primary);
}
.history-header h3 { font-size: 1rem; display: flex; align-items: center; gap: 0.5rem; }
.btn-close-panel {
    background: none; border: none; font-size: 1.2rem; cursor: pointer;
    color: var(--text-tertiary); padding: 4px; border-radius: var(--radius-sm);
}
.btn-close-panel:hover { color: var(--text-primary); background: var(--bg-hover); }
.history-list {
    flex: 1; overflow-y: auto; padding: 1rem 1.5rem;
    display: flex; flex-direction: column; gap: 0.6rem;
}
.history-empty { text-align: center; color: var(--text-tertiary); padding: 2rem 0; font-size: 0.85rem; }
.history-item {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    padding: 0.7rem 0.8rem;
    display: flex; justify-content: space-between; align-items: center;
    gap: 0.5rem;
}
.history-item-hash {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    color: var(--text-secondary);
    word-break: break-all;
    flex: 1;
}
.history-item-cost {
    font-size: 0.65rem; color: var(--text-tertiary);
    background: var(--bg-secondary);
    padding: 0.2rem 0.5rem;
    border-radius: var(--radius-sm);
    white-space: nowrap;
}
.history-item-actions { display: flex; gap: 0.3rem; }
.history-item-actions button {
    background: none; border: none; cursor: pointer;
    color: var(--text-tertiary); font-size: 0.8rem;
    padding: 0.3rem; border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}
.history-item-actions button:hover { color: var(--text-primary); background: var(--bg-hover); }
.btn-clear-history {
    margin: 1rem 1.5rem;
    padding: 0.6rem;
    background: none; border: 1px solid var(--border-primary);
    border-radius: var(--radius-sm);
    color: var(--text-tertiary);
    cursor: pointer; font-size: 0.8rem;
    font-family: 'Inter', sans-serif;
}
.btn-clear-history:hover {
    color: var(--error-text);
    border-color: var(--error-border);
    background: var(--error-bg);
}

.toast-container {
    position: fixed; top: 1.5rem; right: 1.5rem;
    z-index: 2000;
    display: flex; flex-direction: column; gap: 0.5rem;
    max-width: 380px;
}
.toast {
    padding: 0.8rem 1.2rem;
    border-radius: var(--radius-md);
    font-size: 0.85rem; font-weight: 500;
    display: flex; align-items: center; gap: 0.5rem;
    box-shadow: var(--shadow-lg);
    animation: toastIn 0.3s ease-out, toastOut 0.3s ease-out 2.7s forwards;
    border: 1px solid var(--border-primary);
    background: var(--bg-secondary);
    color: var(--text-primary);
}
.toast-success { border-color: var(--success-border); background: var(--success-bg); color: var(--success-text); }
.toast-error { border-color: var(--error-border); background: var(--error-bg); color: var(--error-text); }
.toast-info { border-color: var(--info-border); background: var(--info-bg); color: var(--info-text); }

@keyframes slideUp {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes toastIn {
    from { opacity: 0; transform: translateX(50px); }
    to { opacity: 1; transform: translateX(0); }
}
@keyframes toastOut {
    from { opacity: 1; transform: translateX(0); }
    to { opacity: 0; transform: translateX(50px); }
}

@media (max-width: 600px) {
    .app-container { padding: 1rem; }
    .app-header { flex-direction: column; align-items: flex-start; }
    .header-right { align-self: flex-end; }
    .card { padding: 1.25rem; border-radius: var(--radius-lg); }
    .history-panel { width: 100%; max-width: 100%; }
}