:root {
    --accent-light: #FFF0E6;
    --accent-pink: #EA5B6F;
    --accent-primary: #FF5C00;
    --border-color: #E5E7EB;
    --fg-inverse: #FFFFFF;
    --fg-muted: #888888;
    --fg-primary: #1A1A1A;
    --fg-secondary: #666666;
    --surface-primary: #FFFFFF;
    --surface-secondary: #F7F8FA;
    --radius-2xl: 16px;
    --radius-xl: 12px;
    --radius-full: 9999px;
    --color-error: #ff6b6b;
    --color-error-bg: #ffe0e0;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #E8E8ED;
    min-height: 100vh;
    display: flex;
    justify-content: center;
}

/* ==================== APP SHELL ==================== */
.app {
    width: 100%;
    max-width: 480px;
    min-height: 100vh;
    background: var(--surface-primary);
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
    border-radius: var(--radius-2xl);
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.12);
}

/* ==================== MAIN VIEW ==================== */
#main-view {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.app-header {
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-pink));
    padding: 40px 24px 24px;
    color: var(--fg-inverse);
}

.app-header h1 {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 6px;
}

.app-header p {
    font-size: 13px;
    opacity: 0.85;
}

/* Search */
.search-area {
    padding: 16px 16px 8px;
}

.search-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    height: 44px;
    padding: 0 14px;
    background: var(--surface-secondary);
    border-radius: var(--radius-full);
    border: 1px solid var(--border-color);
}

.search-bar i {
    color: var(--fg-muted);
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.search-bar input {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    font-size: 14px;
    color: var(--fg-primary);
    font-family: inherit;
}

.search-bar input::placeholder {
    color: var(--fg-muted);
}

/* Category Pills */
.pills-area {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    flex-shrink: 0;
}

.pills-area::-webkit-scrollbar { display: none; }

.pill {
    flex-shrink: 0;
    padding: 6px 14px;
    border-radius: var(--radius-full);
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.pill--active {
    background: var(--accent-primary);
    color: var(--fg-inverse);
}

.pill:not(.pill--active) {
    border: 1px solid var(--border-color);
    color: var(--fg-secondary);
    background: transparent;
}

/* Calculator Cards */
.cards-list {
    flex: 1;
    padding: 4px 16px 32px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.cards-category-header {
    font-size: 12px;
    font-weight: 600;
    color: var(--fg-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 12px 4px 4px;
}

.cards-category-header:first-child {
    padding-top: 4px;
}

.calc-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px;
    background: var(--surface-secondary);
    border-radius: var(--radius-2xl);
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.calc-card:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.calc-card:active {
    transform: scale(0.98);
}

.calc-card__icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-xl);
    background: var(--accent-light);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.calc-card__icon svg {
    color: var(--accent-primary);
    width: 20px;
    height: 20px;
}

.calc-card__content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.calc-card__title {
    font-size: 15px;
    font-weight: 600;
    color: var(--fg-primary);
}

.calc-card__example {
    font-size: 12px;
    color: var(--fg-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.calc-card__arrow {
    color: var(--fg-muted);
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.no-results {
    text-align: center;
    padding: 40px 20px;
    color: var(--fg-muted);
    font-size: 15px;
}

/* ==================== DETAIL VIEW ==================== */
#detail-view {
    flex-direction: column;
    min-height: 100vh;
}

.nav-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    height: 56px;
    padding: 0 16px;
    flex-shrink: 0;
    border-bottom: 1px solid var(--border-color);
}

.nav-btn {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    background: var(--surface-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s;
    color: var(--fg-primary);
    -webkit-tap-highlight-color: transparent;
}

.nav-btn:hover {
    background: #EEEFF2;
}

.nav-btn i {
    width: 20px;
    height: 20px;
}

.nav-bar__title {
    font-size: 17px;
    font-weight: 600;
    color: var(--fg-primary);
}

.nav-bar__spacer { flex: 1; }

/* Calc Content */
.calc-content {
    flex: 1;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    overflow-y: auto;
}

/* Calc Header (detail view) */
.calc-header {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px;
    background: var(--surface-secondary);
    border-radius: var(--radius-2xl);
}

.calc-header__emoji {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-xl);
    background: var(--accent-light);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.calc-header__emoji svg {
    color: var(--accent-primary);
    width: 24px;
    height: 24px;
}

.calc-header__text {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.calc-header__name {
    font-size: 17px;
    font-weight: 700;
    color: var(--fg-primary);
    line-height: 1.3;
}

.calc-header__desc {
    font-size: 12px;
    color: var(--fg-muted);
    line-height: 1.4;
}

/* ==================== CALC OPTIONS ==================== */
.calc-option {
    display: none;
}

.calc-option.active {
    display: block;
}

.calc-option-header {
    display: none;
}

.calc-inputs {
    display: none;
}

.calc-option.active .calc-inputs {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Category dividers - hidden in new design */
.category-divider {
    display: none;
}

/* ==================== INPUT FIELDS ==================== */
.input-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.input-group label {
    font-size: 13px;
    font-weight: 500;
    color: var(--fg-muted);
}

.input-group input,
.input-group select {
    width: 100%;
    padding: 14px 16px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    font-size: 16px;
    font-weight: 500;
    color: var(--fg-primary);
    background: var(--surface-secondary);
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
    -webkit-appearance: none;
    appearance: none;
}

.input-group select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 40px;
}

.input-group input:focus,
.input-group select:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(255, 92, 0, 0.1);
}

.input-group input::placeholder {
    color: var(--fg-muted);
    font-weight: 400;
}

/* Error states */
.input-group input.error,
.input-group select.error {
    border-color: var(--color-error);
    background-color: var(--color-error-bg);
    animation: shake 0.3s ease-in-out;
    box-shadow: 0 0 0 3px rgba(255, 107, 107, 0.15);
}

.input-group.error label {
    color: var(--color-error);
}

.error-message {
    color: var(--color-error);
    font-size: 12px;
    margin-top: 2px;
    display: none;
}

.input-group .error-message {
    display: block;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

/* ==================== RESULT CARD ==================== */
.dynamic-result {
    margin-top: 4px;
    padding: 20px;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-pink));
    color: var(--fg-inverse);
    border-radius: var(--radius-2xl);
    text-align: center;
    cursor: pointer;
    position: relative;
    z-index: 2;
}

.dynamic-result.error {
    background: var(--color-error-bg);
    color: var(--fg-primary);
    text-align: left;
    cursor: default;
}

.dynamic-result.error .error-label {
    color: var(--color-error);
    font-weight: 700;
    margin-bottom: 5px;
}

.result-number {
    font-size: 32px;
    font-weight: 700;
    margin-bottom: 4px;
    line-height: 1.2;
    word-break: break-word;
}

.result-number--medium {
    font-size: 24px;
}

.result-number--small {
    font-size: 18px;
    line-height: 1.4;
}

.result-divider {
    height: 1px;
    background: rgba(255, 255, 255, 0.2);
    margin: 12px 0;
}

.result-details {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.detail-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 12px;
}

.detail-row__label {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.8);
    text-align: left;
}

.detail-row__value {
    font-size: 14px;
    font-weight: 600;
    color: var(--fg-inverse);
    text-align: right;
    white-space: nowrap;
}

.result-text {
    font-size: 14px;
    opacity: 0.9;
    line-height: 1.5;
}

.result-chart-container {
    margin-top: 8px;
}

.copy-hint {
    font-size: 11px;
    opacity: 0.6;
    margin-top: 12px;
}

/* ==================== BMI CHART ==================== */
.bmi-chart {
    margin: 12px 0;
    padding: 14px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: var(--radius-xl);
    border: none;
}

.bmi-scale {
    display: flex;
    height: 28px;
    border-radius: var(--radius-full);
    overflow: hidden;
    margin: 10px 0;
    position: relative;
    width: 100%;
}

.bmi-zone {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--fg-inverse);
    font-weight: 600;
    font-size: 11px;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    position: relative;
}

.bmi-zone.underweight { background: #60A5FA; width: 14%; }
.bmi-zone.normal { background: #34D399; width: 26%; }
.bmi-zone.overweight { background: #FBBF24; width: 20%; }
.bmi-zone.obese { background: #F87171; width: 40%; }

.bmi-indicator {
    position: absolute;
    top: -5px;
    width: 3px;
    height: 38px;
    background: var(--fg-inverse);
    border-radius: 2px;
    z-index: 1;
    transition: left 0.3s ease;
}

.bmi-indicator::before {
    content: '';
    position: absolute;
    top: -8px;
    left: -4px;
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 8px solid var(--fg-inverse);
}

.bmi-legend {
    display: flex;
    justify-content: space-between;
    font-size: 10px;
    color: rgba(255, 255, 255, 0.7);
    margin-top: 5px;
}

.bmi-current {
    text-align: center;
    margin-top: 10px;
    font-weight: 600;
    color: var(--fg-inverse);
}

/* ==================== LEGACY / HIDDEN ==================== */
.result,
.error-block {
    display: none !important;
}

/* ==================== RESPONSIVE ==================== */
@media (max-width: 480px) {
    body {
        background: var(--surface-primary);
    }

    .app {
        box-shadow: none;
        border-radius: 0;
    }

    .app-header {
        padding-top: 48px;
    }
}

@media (min-width: 481px) {
    body {
        padding: 20px;
    }

    .app {
        min-height: auto;
    }

    #main-view,
    #detail-view {
        min-height: auto;
    }
}
