/* ===== RESET & VARIABLES ===== */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
    /* Gray-scale design system — shades of gray signal hierarchy */
    --bg: #1c1c1e;            /* deepest surface */
    --bg-elev: #2c2c2e;       /* elevated */
    --bg-card: #3a3a3c;       /* card */
    --surface: #48484a;       /* control surface */
    --surface-2: #58585a;     /* hover/active */
    --text: #f5f5f7;          /* primary text (near white) */
    --text-dim: #98989f;      /* secondary text */
    --text-faint: #6c6c70;    /* tertiary */
    --border: rgba(255,255,255,0.08);
    --border-strong: rgba(255,255,255,0.14);
    --accent: #f5f5f7;        /* active accent = light gray */
    --danger: #ff453a;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-top: env(safe-area-inset-top, 0px);
    --nav-height: 76px;
    color-scheme: dark light;
}

html.light {
    --bg: #f2f2f7;
    --bg-elev: #e8e8ed;
    --bg-card: #ffffff;
    --surface: #d8d8dd;
    --surface-2: #c8c8ce;
    --text: #1c1c1e;
    --text-dim: #6c6c70;
    --text-faint: #9a9aa0;
    --border: rgba(0,0,0,0.08);
    --border-strong: rgba(0,0,0,0.14);
    --accent: #1c1c1e;
    --danger: #d70015;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    overflow: hidden;
    height: 100vh; height: 100dvh;
    position: fixed;
    width: 100%;
}

#app { height: 100vh; height: 100dvh; display: flex; flex-direction: column; position: relative; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button:focus:not(:focus-visible), input:focus:not(:focus-visible), select:focus:not(:focus-visible) { outline: none; }

/* ===== SCREENS ===== */
.screen { display: none; flex-direction: column; flex: 1; overflow: hidden; padding-top: var(--safe-top); }
.screen.active { display: flex; }
.screen-header { padding: 18px 20px 10px; flex-shrink: 0; }
.screen-header h1 { font-size: 26px; font-weight: 700; letter-spacing: -0.5px; }
.screen-content {
    flex: 1; overflow-y: auto; padding: 0 20px 110px;
    overscroll-behavior-y: none; scrollbar-width: none;
}
.screen-content::-webkit-scrollbar { display: none; }

/* ===== COLOR WHEEL ===== */
.picker-section { margin-bottom: 20px; }
.wheel-wrap {
    position: relative; width: 100%; max-width: 320px; aspect-ratio: 1;
    margin: 8px auto 16px; touch-action: none;
}
#color-wheel { width: 100%; height: 100%; border-radius: 50%; display: block; cursor: pointer; box-shadow: 0 8px 32px rgba(0,0,0,0.3); }
.wheel-handle {
    position: absolute; width: 28px; height: 28px; border-radius: 50%;
    border: 3px solid #fff; box-shadow: 0 2px 8px rgba(0,0,0,0.5);
    transform: translate(-50%, -50%); pointer-events: none; left: 50%; top: 50%;
    background: #6c5ce7;
}

/* ===== SELECTED COLOR ROW ===== */
.selected-row { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.color-preview {
    width: 56px; height: 56px; border-radius: 14px; background: #6c5ce7; flex-shrink: 0;
    box-shadow: 0 4px 16px rgba(0,0,0,0.3); transition: background 0.12s; cursor: pointer;
}
.btn-copy {
    flex: 1; background: var(--bg-card); border: 1px solid var(--border); border-radius: 14px;
    padding: 12px 16px; text-align: left; cursor: pointer; color: var(--text);
    display: flex; flex-direction: column; gap: 2px; min-height: 56px;
}
.btn-copy span { font-size: 18px; font-weight: 700; font-family: 'SF Mono','Fira Code',monospace; letter-spacing: 0.5px; }
.btn-copy small { font-size: 11px; color: var(--text-dim); }

/* ===== SLIDERS ===== */
.picker-controls { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.picker-row { display: flex; align-items: center; gap: 12px; }
.picker-row label { width: 18px; font-weight: 600; font-size: 13px; color: var(--text-dim); }
.picker-row span { width: 32px; text-align: right; font-size: 12px; font-family: 'SF Mono',monospace; color: var(--text-dim); }
.slider { flex: 1; -webkit-appearance: none; appearance: none; height: 6px; border-radius: 3px; outline: none; background: var(--surface); }
.slider::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 22px; height: 22px; border-radius: 50%; background: var(--text); cursor: pointer; box-shadow: 0 2px 6px rgba(0,0,0,0.3); }
.slider::-moz-range-thumb { width: 22px; height: 22px; border-radius: 50%; background: var(--text); cursor: pointer; border: none; box-shadow: 0 2px 6px rgba(0,0,0,0.3); }
.slider-r { background: linear-gradient(to right, #000, #ff3b30); }
.slider-g { background: linear-gradient(to right, #000, #34c759); }
.slider-b { background: linear-gradient(to right, #000, #0a84ff); }

.native-picker-row { display: flex; align-items: center; gap: 16px; }
input[type="color"] { width: 48px; height: 38px; border: none; border-radius: 10px; cursor: pointer; background: none; padding: 0; }
input[type="color"]::-webkit-color-swatch-wrapper { padding: 2px; }
input[type="color"]::-webkit-color-swatch { border-radius: 8px; border: none; }
input[type="color"]::-moz-color-swatch { border-radius: 8px; border: none; }

.btn-small { padding: 9px 16px; border-radius: 10px; border: none; background: var(--surface); color: var(--text); font-size: 13px; font-weight: 500; cursor: pointer; min-height: 36px; transition: opacity 0.15s; }
.btn-small:active { opacity: 0.7; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-block { width: 100%; padding: 14px; border-radius: 14px; border: none; background: var(--surface); color: var(--text); font-size: 15px; font-weight: 600; cursor: pointer; min-height: 48px; }

/* ===== COMBO CARDS (compact) ===== */
.combos-section h2 { font-size: 18px; font-weight: 700; margin-bottom: 12px; }
.combo-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: 16px; padding: 12px 14px; margin-bottom: 10px; position: relative; }
.combo-card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.combo-card-head h3 { font-size: 14px; font-weight: 600; }
.like-btn {
    width: 34px; height: 34px; border-radius: 50%; border: none; background: var(--surface);
    color: var(--text-dim); cursor: pointer; display: flex; align-items: center; justify-content: center;
    font-size: 18px; transition: transform 0.15s, background 0.15s; flex-shrink: 0;
}
.like-btn:active { transform: scale(0.85); }
.like-btn.liked { background: var(--danger); color: #fff; }
.combo-swatches { display: flex; gap: 5px; height: 42px; border-radius: 10px; overflow: hidden; }
.combo-swatch { flex: 1; border-radius: 8px; cursor: pointer; position: relative; transition: transform 0.12s; display: flex; align-items: flex-end; justify-content: center; padding-bottom: 4px; }
.combo-swatch:active { transform: scale(0.95); }
.combo-swatch span { font-size: 8px; font-weight: 600; padding: 2px 4px; border-radius: 4px; background: rgba(0,0,0,0.55); color: #fff; opacity: 0; transition: opacity 0.15s; white-space: nowrap; }
.combo-swatch:hover span, .combo-swatch:active span, .combo-swatch.show-label span { opacity: 1; }

/* ===== GUIDES ===== */
.guides-list { display: flex; flex-direction: column; gap: 8px; }
.guide-card { display: flex; align-items: center; gap: 14px; padding: 14px 16px; background: var(--bg-card); border: 1px solid var(--border); border-radius: 14px; cursor: pointer; transition: transform 0.12s, opacity 0.12s; }
.guide-card:active { transform: scale(0.98); opacity: 0.8; }
.guide-icon { font-size: 28px; flex-shrink: 0; }
.guide-info { flex: 1; min-width: 0; }
.guide-info h3 { font-size: 15px; font-weight: 600; margin-bottom: 2px; }
.guide-info p { font-size: 12px; color: var(--text-dim); }
.guide-arrow { font-size: 22px; color: var(--text-faint); flex-shrink: 0; }

/* ===== GUIDE OVERLAY ===== */
.guide-overlay { position: fixed; inset: 0; background: var(--bg); z-index: 200; display: none; flex-direction: column; }
.guide-overlay.active { display: flex; }
.guide-overlay-header { display: flex; align-items: center; gap: 12px; padding: 14px 20px; padding-top: calc(var(--safe-top) + 14px); border-bottom: 1px solid var(--border); flex-shrink: 0; }
.guide-overlay-header h2 { font-size: 17px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn-back { background: none; border: none; color: var(--text); font-size: 16px; cursor: pointer; font-weight: 500; min-height: 44px; min-width: 44px; display: flex; align-items: center; }
.guide-overlay-content { flex: 1; overflow-y: auto; padding: 20px; line-height: 1.7; overscroll-behavior-y: none; scrollbar-width: none; }
.guide-overlay-content::-webkit-scrollbar { display: none; }
.guide-overlay-content h3 { font-size: 19px; font-weight: 700; margin: 18px 0 8px; }
.guide-overlay-content h3:first-child { margin-top: 0; }
.guide-overlay-content p { font-size: 15px; color: var(--text); margin-bottom: 10px; }
.guide-overlay-content .tip { background: var(--bg-elev); border-left: 3px solid var(--text-dim); padding: 12px 16px; border-radius: 0 10px 10px 0; margin: 14px 0; font-size: 14px; color: var(--text-dim); }
.guide-overlay-content .color-wheel-demo { width: 180px; height: 180px; margin: 16px auto; border-radius: 50%; display: block; }

/* ===== FAVORITES ===== */
.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 50px 20px; text-align: center; }
.empty-icon { font-size: 44px; margin-bottom: 14px; color: var(--text-faint); }
.empty-state p { font-size: 16px; font-weight: 600; margin-bottom: 4px; }
.empty-state span { font-size: 13px; color: var(--text-dim); }
.fav-list { display: flex; flex-direction: column; gap: 10px; }
.fav-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: 14px; padding: 12px; }
.fav-card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.fav-card-type { font-size: 14px; font-weight: 600; }
.fav-card-date { font-size: 11px; color: var(--text-dim); }
.fav-swatches { display: flex; gap: 4px; height: 36px; border-radius: 8px; overflow: hidden; margin-bottom: 8px; }
.fav-swatch { flex: 1; border-radius: 6px; cursor: pointer; border: none; min-width: 0; }
.fav-actions { display: flex; gap: 6px; }
.fav-actions button { flex: 1; padding: 8px; border-radius: 8px; border: none; font-size: 12px; font-weight: 500; cursor: pointer; min-height: 34px; }
.fav-btn-color { background: var(--surface); color: var(--text); }
.fav-btn-share { background: var(--bg-elev); color: var(--text-dim); }
.fav-btn-delete { background: rgba(255,69,58,0.18); color: var(--danger); }

/* ===== IMAGE SCREEN ===== */
.image-upload-wrap { margin-bottom: 16px; }
.image-upload-inner {
    background: var(--bg-card); border: 1px dashed var(--border-strong); border-radius: 18px;
    padding: 36px 20px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.upload-icon { font-size: 40px; }
.image-upload-inner p { font-size: 15px; font-weight: 600; }
.image-upload-inner span { font-size: 12px; color: var(--text-dim); margin-bottom: 8px; }
.image-result { display: flex; flex-direction: column; gap: 8px; }
.image-canvas { width: 100%; border-radius: 14px; display: block; background: var(--bg-elev); }
.image-result h3 { font-size: 15px; font-weight: 600; margin-top: 8px; }
.image-palette { display: flex; gap: 6px; height: 48px; border-radius: 10px; overflow: hidden; }
.image-palette .ip-swatch { flex: 1; border-radius: 8px; cursor: pointer; }
.image-harmony { display: flex; flex-direction: column; gap: 10px; }
.harmony-row { display: flex; flex-direction: column; gap: 6px; }
.harmony-row .hr-label { font-size: 12px; color: var(--text-dim); }
.harmony-row .hr-swatches { display: flex; gap: 5px; height: 36px; border-radius: 8px; overflow: hidden; }
.harmony-row .hr-swatches div { flex: 1; border-radius: 6px; }

/* ===== COLORING OVERLAY ===== */
.coloring-overlay { position: fixed; inset: 0; background: var(--bg); z-index: 200; display: none; flex-direction: column; }
.coloring-overlay.active { display: flex; }
.coloring-header { display: flex; align-items: center; gap: 12px; padding: 14px 20px; padding-top: calc(var(--safe-top) + 14px); border-bottom: 1px solid var(--border); flex-shrink: 0; }
.coloring-header h2 { font-size: 17px; font-weight: 600; }
.coloring-content { flex: 1; display: flex; flex-direction: column; padding: 16px 20px; gap: 12px; overflow-y: auto; overscroll-behavior-y: none; }
.coloring-palette { display: flex; gap: 6px; height: 44px; }
.coloring-palette-swatch { flex: 1; border-radius: 10px; cursor: pointer; border: 3px solid transparent; transition: border-color 0.15s, transform 0.15s; min-width: 0; }
.coloring-palette-swatch.active { border-color: var(--text); transform: scale(1.05); }
.coloring-tools { display: flex; gap: 8px; }
.btn-coloring-tool { flex: 1; padding: 10px; border-radius: 10px; border: 1px solid var(--border); background: transparent; color: var(--text); font-size: 13px; font-weight: 500; cursor: pointer; min-height: 40px; }
.btn-coloring-tool.active { background: var(--surface); border-color: var(--border-strong); }
.brush-size-row { display: flex; align-items: center; gap: 12px; }
.brush-size-row label { font-size: 13px; color: var(--text-dim); }
.brush-size-row input[type="range"] { flex: 1; -webkit-appearance: none; appearance: none; height: 4px; background: var(--surface); border-radius: 2px; outline: none; }
.brush-size-row input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 20px; height: 20px; border-radius: 50%; background: var(--text); cursor: pointer; }
.brush-size-row input[type="range"]::-moz-range-thumb { width: 20px; height: 20px; border-radius: 50%; background: var(--text); cursor: pointer; border: none; }
.coloring-canvas-wrapper { flex: 1; display: flex; align-items: center; justify-content: center; min-height: 250px; background: var(--bg-elev); border-radius: 16px; overflow: hidden; position: relative; }
#coloring-canvas { max-width: 100%; max-height: 100%; cursor: crosshair; touch-action: none; }
.coloring-actions { display: flex; gap: 10px; }
.coloring-actions .btn-small { flex: 1; text-align: center; }

/* ===== SETTINGS ===== */
.settings-group { margin-bottom: 24px; }
.settings-group h3 { font-size: 12px; font-weight: 600; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 8px; }
.setting-item { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px; margin-bottom: 4px; }
.setting-item span { font-size: 15px; }
.setting-value { color: var(--text-dim); font-size: 14px; }
.setting-note { font-size: 12px; color: var(--text-faint); margin-top: 8px; padding: 0 4px; }
.setting-item select { background: var(--surface); color: var(--text); border: none; border-radius: 8px; padding: 6px 12px; font-size: 14px; font-family: inherit; min-height: 36px; cursor: pointer; }

.toggle { position: relative; width: 50px; height: 28px; cursor: pointer; display: inline-block; }
.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle-slider { position: absolute; inset: 0; background: var(--surface-2); border-radius: 14px; transition: background 0.3s; }
.toggle-slider::before { content: ''; position: absolute; width: 22px; height: 22px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: transform 0.3s; }
.toggle input:checked + .toggle-slider { background: var(--text); }
.toggle input:checked + .toggle-slider::before { transform: translateX(22px); }

/* ===== COLOR DETAIL SHEET ===== */
.detail-overlay { position: fixed; inset: 0; z-index: 250; display: none; background: rgba(0,0,0,0.4); backdrop-filter: blur(4px); }
.detail-overlay.active { display: flex; align-items: flex-end; }
.detail-sheet { width: 100%; background: var(--bg-elev); border-radius: 22px 22px 0 0; padding: 10px 20px calc(24px + var(--safe-bottom)); box-shadow: 0 -8px 32px rgba(0,0,0,0.4); }
.detail-grabber { width: 38px; height: 4px; background: var(--surface-2); border-radius: 2px; margin: 6px auto 14px; }
.detail-preview { width: 100%; height: 90px; border-radius: 16px; background: #6c5ce7; margin-bottom: 16px; }
.detail-values { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.detail-val { display: flex; justify-content: space-between; align-items: center; background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px; padding: 12px 16px; cursor: pointer; color: var(--text); }
.detail-val label { font-size: 12px; color: var(--text-dim); font-weight: 600; }
.detail-val span { font-size: 15px; font-weight: 600; font-family: 'SF Mono',monospace; }
.detail-slider-row { margin-bottom: 16px; }
.detail-slider-row label { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 10px; }
#detail-lightness { width: 100%; -webkit-appearance: none; appearance: none; height: 8px; border-radius: 4px; outline: none; background: linear-gradient(to right, #000, #6c5ce7, #fff); }
#detail-lightness::-webkit-slider-thumb { -webkit-appearance: none; width: 24px; height: 24px; border-radius: 50%; background: #fff; cursor: pointer; box-shadow: 0 2px 8px rgba(0,0,0,0.4); }
#detail-lightness::-moz-range-thumb { width: 24px; height: 24px; border-radius: 50%; background: #fff; cursor: pointer; border: none; box-shadow: 0 2px 8px rgba(0,0,0,0.4); }

/* ===== CONFIRM DIALOG ===== */
.confirm-dialog { position: fixed; inset: 0; z-index: 300; display: none; align-items: center; justify-content: center; padding: 20px; }
.confirm-dialog.active { display: flex; }
.confirm-dialog-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.5); backdrop-filter: blur(4px); }
.confirm-dialog-box { position: relative; background: var(--bg-elev); border-radius: 16px; padding: 24px; max-width: 320px; width: 100%; text-align: center; box-shadow: 0 8px 32px rgba(0,0,0,0.3); }
.confirm-dialog-box p { font-size: 16px; font-weight: 500; margin-bottom: 20px; line-height: 1.5; }
.confirm-dialog-actions { display: flex; gap: 10px; }
.confirm-dialog-actions button { flex: 1; padding: 12px; border-radius: 10px; border: none; font-size: 15px; font-weight: 600; cursor: pointer; min-height: 44px; }
.btn-confirm-cancel { background: var(--surface); color: var(--text); }
.btn-confirm-ok { background: var(--danger); color: #fff; }

/* ===== FLOATING BOTTOM NAV ===== */
.bottom-nav {
    position: fixed; left: 12px; right: 12px; bottom: calc(12px + var(--safe-bottom));
    height: 64px; background: rgba(44,44,46,0.82); backdrop-filter: blur(24px); -webkit-backdrop-filter: blur(24px);
    display: flex; justify-content: space-around; align-items: center;
    border-radius: 22px; border: 1px solid var(--border); box-shadow: 0 8px 32px rgba(0,0,0,0.35);
    z-index: 100; padding: 0 4px;
}
html.light .bottom-nav { background: rgba(255,255,255,0.82); }
.nav-btn { background: none; border: none; color: var(--text-dim); display: flex; flex-direction: column; align-items: center; gap: 3px; cursor: pointer; padding: 4px 10px; transition: color 0.2s; font-size: 10px; font-weight: 500; min-width: 52px; min-height: 52px; justify-content: center; }
.nav-btn.active { color: var(--accent); }
.nav-icon { width: 22px; height: 22px; flex-shrink: 0; }

/* ===== TOAST ===== */
.toast {
    position: fixed; bottom: calc(96px + var(--safe-bottom)); left: 50%; transform: translateX(-50%) translateY(20px);
    background: var(--surface-2); color: var(--text); padding: 12px 22px; border-radius: 14px;
    font-size: 14px; font-weight: 500; z-index: 400; transition: opacity 0.25s, transform 0.25s;
    pointer-events: none; max-width: calc(100vw - 40px); text-align: center; opacity: 0;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ===== REDUCED MOTION ===== */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
