:root {
    /* Base Colors - Clean Medical Theme */
    --bg-color: #f8fafc;
    /* Slate 50 */
    --card-bg: #ffffff;
    --text-main: #0f172a;
    /* Slate 900 */
    --text-muted: #64748b;
    /* Slate 500 */
    --border-color: #e2e8f0;
    /* Slate 200 */

    /* Blue Theme (製剤量 g 用) */
    --blue-main: #0284c7;
    /* Sky 600 */
    --blue-dark: #0369a1;
    /* Sky 700 */
    --blue-light: #e0f2fe;
    /* Sky 100 */
    --blue-border: #7dd3fc;
    /* Sky 300 */

    /* Orange Theme (成分量 mg 用) */
    --orange-main: #ea580c;
    /* Orange 600 */
    --orange-dark: #c2410c;
    /* Orange 700 */
    --orange-light: #ffedd5;
    /* Orange 100 */
    --orange-border: #fdba74;
    /* Orange 300 */

    /* Standard Accents */
    --primary-color: #475569;
    /* Slate 600 */
    --primary-light: #f1f5f9;
    /* Slate 100 */
    --danger-color: #ef4444;
    /* Red 500 */
    --danger-light: #fef2f2;

    /* Structural */
    --radius-sm: 8px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);

    --font-family: 'Inter', 'Noto Sans JP', sans-serif;
}

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

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-main);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    padding: 16px;
    padding-bottom: 40px;
}

.app-container {
    max-width: 600px;
    margin: 0 auto;
}

/* Header */
.app-header {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 16px;
    margin-top: 10px;
    margin-bottom: 24px;
    padding: 0 4px;
}

.app-header .header-icon img {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
}

.header-title-box {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex: 1;
}

.app-header h1 {
    font-size: 1.35rem;
    font-weight: 800;
    color: var(--text-main);
    letter-spacing: -0.01em;
}

/* Clear Button */
.clear-btn {
    background: var(--card-bg);
    border: 2px solid var(--border-color);
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 700;
    padding: 6px 12px;
    cursor: pointer;
    border-radius: 20px;
    transition: all 0.2s;
    box-shadow: var(--shadow-sm);
}

.clear-btn:active {
    background: #f1f5f9;
    transform: scale(0.95);
}

/* Cards */
.card {
    background-color: var(--card-bg);
    border-radius: var(--radius-md);
    padding: 24px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
}

.setup-card {
    padding-top: 20px;
}

.divider {
    border: 0;
    height: 1px;
    background: var(--border-color);
    margin: 24px 0;
}

/* Labels & Typography */
.section-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1rem;
    font-weight: 700;
    color: var(--primary-color);
}

.step-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background-color: var(--text-muted);
    color: #fff;
    font-size: 0.85rem;
    font-weight: 800;
}

.mb-2 {
    margin-bottom: 8px;
}

.mb-3 {
    margin-bottom: 12px;
}

.mb-4 {
    margin-bottom: 20px;
}

.mt-2 {
    margin-top: 8px;
}

label {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text-muted);
    display: block;
    margin-bottom: 6px;
}

/* Inputs Wrapper */
.input-wrapper {
    display: flex;
    align-items: center;
    position: relative;
    width: 100%;
}

.input-wrapper input {
    width: 100%;
    padding: 14px 16px;
    font-size: 1.3rem;
    font-family: inherit;
    font-weight: 700;
    color: var(--text-main);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    outline: none;
    transition: all 0.2s ease;
    text-align: right;
    background-color: #f8fafc;
    padding-right: 48px;
    /* space for unit */
}

.input-wrapper.has-select input {
    padding-right: 62px;
    /* space for select */
}

.input-wrapper input:focus {
    background-color: #ffffff;
    border-color: var(--primary-color);
}

.input-wrapper .unit-append {
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-muted);
    pointer-events: none;
}

.input-wrapper .unit-select {
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-muted);
    cursor: pointer;
    pointer-events: auto;
    padding-right: 14px;
    appearance: none;
    border: none;
    background: transparent;
    outline: none;
    background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%23ea580c%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E");
    background-repeat: no-repeat;
    background-position: right center;
    background-size: 10px auto;
}

.unit-select:focus {
    text-decoration: underline;
}

.theme-orange .input-wrapper .unit-select {
    color: var(--orange-main);
}

/* Quick Buttons Array */
.quick-btn-group {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.qbtn {
    flex: 1;
    min-width: 44px;
    min-height: 44px;
    /* 親指で押しやすい */
    padding: 10px 0;
    font-size: 1rem;
    font-weight: 700;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.15s ease;
    user-select: none;
    border: 2px solid transparent;
    background-color: var(--primary-light);
    color: var(--primary-color);
}

.qbtn:active {
    transform: scale(0.95);
}

.qbtn.active-btn {
    background-color: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.percent-btns .qbtn {
    font-size: 0.95rem;
}

.percent-wrapper {
    margin-bottom: 4px;
}

.percent-guide {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-muted);
    margin-left: 4px;
    height: 1.25em;
    display: flex;
    align-items: center;
}

/* Dual Row and Sync Layout */
.dual-input-row {
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

.align-end {
    align-items: flex-end;
}

.flex-1 {
    flex: 1;
}

.flex-shorter {
    width: 120px;
}

.sync-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    margin-top: 36px;
    width: 24px;
    height: 24px;
    opacity: 0.6;
}

@media (max-width: 480px) {
    .dual-input-row {
        flex-direction: column;
        gap: 16px;
        align-items: stretch;
    }

    .sync-icon {
        transform: rotate(90deg);
        margin: -4px auto;
        height: 16px;
    }

    .flex-shorter {
        width: 100%;
    }
}

/* Thematic Coloring */
/* Blue Theme (g) */
.theme-blue .input-wrapper input:focus,
.theme-blue.is-active .input-wrapper input {
    border-color: var(--blue-main);
    box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.15);
}

.theme-blue label {
    color: var(--blue-dark);
}

.theme-blue .unit-append {
    color: var(--blue-main);
}

.theme-blue .val {
    color: var(--blue-dark);
    text-shadow: 0 1px 1px rgba(2, 132, 199, 0.1);
}

/* Orange Theme (mg) */
.theme-orange .input-wrapper input:focus,
.theme-orange.is-active .input-wrapper input {
    border-color: var(--orange-main);
    box-shadow: 0 0 0 3px rgba(234, 88, 12, 0.15);
}

.theme-orange label {
    color: var(--orange-dark);
}

.theme-orange .unit-append {
    color: var(--orange-main);
}

.theme-orange .val {
    color: var(--orange-dark);
    text-shadow: 0 1px 1px rgba(234, 88, 12, 0.1);
}


/* Results Section */
.results-card {
    padding: 24px;
}

.result-title {
    font-size: 0.95rem;
    font-weight: 800;
    color: var(--text-muted);
    margin-bottom: 12px;
}

/* 1回量 (最も目立たせる) */
.highlight-card {
    border: 2px solid var(--blue-border);
    background-color: #fafafa;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    margin-bottom: 0;
    border-bottom: none;
}

.dose-numbers {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 16px;
    margin: 16px 0;
    flex-wrap: wrap;
    text-align: center;
}

.dose-primary .val {
    font-size: 3.5rem;
    font-weight: 800;
    line-height: 1;
    letter-spacing: -0.02em;
}

.dose-primary .unit {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--blue-main);
}

.dose-secondary .val {
    font-size: 2rem;
    font-weight: 700;
    line-height: 1;
}

.dose-secondary .unit {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--orange-main);
}

.dose-divider {
    font-size: 2rem;
    color: var(--border-color);
    font-weight: 300;
}

@media (max-width: 480px) {
    .dose-numbers {
        flex-direction: column;
        align-items: center;
        gap: 8px;
        margin: 8px 0;
    }

    .dose-divider {
        display: none;
    }

    .dose-primary .val {
        font-size: 3.2rem;
    }

    .dose-secondary {
        margin-top: -8px;
        padding-bottom: 8px;
        border-bottom: 1px dashed var(--border-color);
        width: 80%;
    }
}

/* Alert Box */
.alert-box {
    margin-top: 16px;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    background-color: var(--danger-light);
    border: 1px solid #fca5a5;
    display: flex;
    align-items: center;
    gap: 8px;
    animation: fadeIn 0.3s ease;
}

.alert-icon {
    font-size: 1.2rem;
}

.alert-text {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--danger-dark);
}

.has-error .val {
    color: var(--danger-color) !important;
    text-shadow: none !important;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-4px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* 全量・計算式カード */
.total-card {
    border: 2px solid var(--blue-border);
    background-color: var(--blue-light);
    border-top-left-radius: 0;
    border-top-right-radius: 0;
}

.total-flex {
    display: flex;
    justify-content: space-between;
    align-items: stretch;
    gap: 16px;
}

.total-info {
    flex: 1;
}

.total-number .val {
    font-size: 2rem;
    font-weight: 800;
    line-height: 1;
}

.total-number .unit {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--blue-main);
}

.total-sub-number {
    margin-top: 6px;
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text-muted);
    display: flex;
    align-items: baseline;
    gap: 2px;
}

.total-sub-number .val {
    color: var(--orange-main);
    font-size: 1.1rem;
}

.total-sub-number .unit {
    color: var(--orange-main);
    font-size: 0.85rem;
}

.formula-box {
    flex: 1.2;
    background-color: rgba(255, 255, 255, 0.7);
    border-radius: var(--radius-sm);
    padding: 12px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.formula-label {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.formula-text {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-main);
    font-family: monospace;
}

@media (max-width: 480px) {
    .total-flex {
        flex-direction: column;
        gap: 16px;
    }
}

/* Back Button */
.back-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: var(--card-bg);
    border: 2px solid var(--border-color);
    text-decoration: none;
    font-size: 1.3rem;
    margin-right: 8px;
    flex-shrink: 0;
    transition: transform 0.2s;
    box-shadow: var(--shadow-sm);
}

.back-btn:active {
    transform: scale(0.95);
    background: #f1f5f9;
}