:root {
    /* Color Palette */
    --bg-dark: #0f172a;
    --bg-panel: #1e293b;
    --bg-panel-hover: #334155;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --accent: #10b981;
    
    --border-color: rgba(255, 255, 255, 0.1);
    
    /* Spacing & Sizes */
    --radius-md: 12px;
    --radius-lg: 16px;
    --shadow-base: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
    --shadow-glow: 0 0 20px rgba(59, 130, 246, 0.3);
}

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

html {
    overflow-x: hidden;
    background-color: var(--bg-dark);
}

body {
    overflow-x: hidden;
    position: relative;
    font-family: 'Inter', 'Noto Sans JP', sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    line-height: 1.6;
    min-height: 100vh;
    padding: 2rem 1rem;
    background: radial-gradient(circle at top left, #1e293b, #0f172a);
}

.app-container {
    max-width: 1200px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: 1fr 380px;
    grid-template-areas:
        "header   header"
        "ad-top   ad-top"
        "main     sidebar"
        "cars     sidebar"
        "referral referral"
        "about    about"
        "footer   footer";
    gap: 2rem;
    align-items: start;
}

@media (max-width: 900px) {
    .app-container {
        display: flex;
        flex-direction: column;
        gap: 2rem;
        align-items: stretch;
    }
    
    .result-sidebar {
        display: contents; /* unwrap aside */
    }
    
    .ad-container-sidebar {
        margin-top: 0 !important;
    }
    
    .app-header { order: 1; }
    .ad-container-top { order: 2; }
    .main-content { order: 3; }
    .result-card { order: 4; }
    .cars-section { order: 5; }
    .referral-section { order: 6; }
    .about-section { order: 7; }
    .ad-container-sidebar { order: 8; }
    .app-footer { order: 9; }
}

@media (min-width: 901px) {
    .app-header { grid-area: header; }
    .ad-container-top { grid-area: ad-top; }
    .main-content { grid-area: main; }
    .result-sidebar { grid-area: sidebar; }
    .cars-section { grid-area: cars; }
    .referral-section { grid-area: referral; }
    .about-section { grid-area: about; }
    .app-footer { grid-area: footer; }
}

/* Header */
.app-header {
    text-align: left;
    margin-bottom: 1rem;
}

.header-title {
    font-size: 2.5rem;
    font-weight: 700;
    color: #ffffff; /* Requested by user */
    margin-bottom: 0.5rem;
}

/* Main Cards */
.card {
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow-base);
}

.card h2 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 1.25rem;
    color: var(--text-main);
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.5rem;
}

/* Forms & Inputs */
.input-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 1rem;
}

@media (max-width: 600px) {
    .card {
        padding: 1.25rem 1rem; /* Reduce horizontal padding to 1rem to give inputs more space */
    }

    .input-grid {
        grid-template-columns: minmax(0, 1fr);
        gap: 0.75rem;
    }
    
    .input-group {
        width: 100%;
        max-width: 280px;
        margin-left: auto;
        margin-right: auto;
        margin-bottom: 1rem;
    }
    
    .header-title {
        font-size: 1.4rem;
    }
    
    .app-header p {
        font-size: 0.75rem;
    }
    
    input[type="datetime-local"],
    input[type="text"],
    input[type="number"] {
        padding: 0.75rem 0.5rem !important; /* Reduce padding inside input */
        font-size: 16px !important; /* Explicit 16px to prevent iOS zoom */
    }
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.input-group label {
    font-size: 0.85rem;
    color: var(--text-muted);
}

input[type="datetime-local"],
input[type="text"],
input[type="number"] {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-color);
    color: white;
    padding: 0.75rem 1rem;
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 1rem;
    transition: border-color 0.2s ease;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
    margin: 0;
}

input:focus {
    outline: none;
    border-color: var(--primary);
}

.duration-display {
    text-align: right;
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-top: 0.5rem;
}
.duration-display span {
    color: white;
    font-weight: 600;
}

/* Tabs */
.tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.tab-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    padding: 0.5rem 1rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.85rem;
}

.tab-btn.active {
    background: var(--bg-panel-hover);
    color: white;
    border-color: var(--primary);
}

.tab-content {
    display: none;
}
.tab-content.active {
    display: block;
}

/* Buttons */
.action-btn, .calculate-btn {
    border: none;
    border-radius: var(--radius-md);
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.action-btn {
    background: rgba(255,255,255,0.1);
    color: white;
    padding: 0.75rem;
    width: 100%;
}
.action-btn:hover { background: rgba(255,255,255,0.2); }

.calculate-btn {
    background: var(--primary);
    color: white;
    padding: 1rem;
    width: 100%;
    font-size: 1.1rem;
    margin-top: 1rem;
    box-shadow: 0 4px 15px rgba(59, 130, 246, 0.4);
}
.calculate-btn:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
}

/* dカーシェア Toggle */
.d-carshare-label {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-top: 0.75rem;
    padding: 0.6rem 1rem;
    background: rgba(175, 82, 222, 0.08);
    border: 1px solid rgba(175, 82, 222, 0.3);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background 0.2s;
    flex-wrap: wrap;
}

.d-carshare-label:hover {
    background: rgba(175, 82, 222, 0.14);
}

.d-carshare-label input[type="checkbox"] {
    width: 1.1rem;
    height: 1.1rem;
    accent-color: #af52de;
    cursor: pointer;
    min-width: 0;
    max-width: none;
    padding: 0;
    margin: 0;
    flex-shrink: 0;
}

.d-carshare-text {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.9rem;
    font-weight: 600;
    color: #d088f5;
}

.d-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #af52de;
    color: white;
    font-size: 0.75rem;
    font-weight: 700;
    width: 1.3rem;
    height: 1.3rem;
    border-radius: 50%;
    line-height: 1;
}

.d-carshare-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-left: auto;
}

/* Service Discount Toggle */
.service-discount-label {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-top: 0.75rem;
    padding: 0.6rem 1rem;
    background: rgba(59, 130, 246, 0.08);
    border: 1px solid rgba(59, 130, 246, 0.3);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background 0.2s;
    flex-wrap: wrap;
}

.service-discount-label:hover {
    background: rgba(59, 130, 246, 0.14);
}

.service-discount-label input[type="checkbox"] {
    width: 1.1rem;
    height: 1.1rem;
    accent-color: var(--primary);
    cursor: pointer;
    min-width: 0;
    max-width: none;
    padding: 0;
    margin: 0;
    flex-shrink: 0;
}

.service-discount-text {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.9rem;
    font-weight: 600;
    color: #93c5fd;
}

.error-msg {
    color: #ef4444;
    font-size: 0.85rem;
    margin-top: 0.5rem;
    min-height: 1.2rem;
}

/* Round-trip Checkbox */
.round-trip-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    margin-top: 0.25rem;
    margin-bottom: 0.5rem;
}

.round-trip-label input[type="checkbox"] {
    width: 1.1rem;
    height: 1.1rem;
    accent-color: var(--primary);
    cursor: pointer;
    min-width: 0;
    max-width: none;
    padding: 0;
    margin: 0;
    flex-shrink: 0;
}

.round-trip-text {
    font-size: 0.85rem;
    color: var(--text-muted);
    user-select: none;
}

/* Sidebar Result & Comparison */
.result-sidebar {
    position: sticky;
    top: 2rem;
}

.result-card {
    background: linear-gradient(180deg, rgba(30,41,59,0.8), rgba(30,41,59,0.4));
    backdrop-filter: blur(10px);
    border: 1px solid rgba(59, 130, 246, 0.3);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-glow);
}

.result-card h2 {
    font-size: 1.1rem;
    margin-bottom: 1.5rem;
    color: var(--text-muted);
}

.comparison-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.compare-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1rem;
    transition: transform 0.2s;
}

.compare-card.cheapest {
    border-color: var(--accent);
    background: rgba(16, 185, 129, 0.05);
    box-shadow: 0 0 10px rgba(16, 185, 129, 0.2);
}

.compare-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.compare-name {
    font-weight: 600;
    font-size: 0.95rem;
}

.pack-badge {
    background: rgba(16, 185, 129, 0.2);
    color: var(--accent);
    padding: 0.15rem 0.6rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
}

.night-badge {
    background: rgba(139, 92, 246, 0.25);
    color: #a78bfa;
    padding: 0.15rem 0.6rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
}

.deal-badge {
    background: rgba(251, 191, 36, 0.2);
    color: #fbbf24;
    padding: 0.15rem 0.6rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
}

.badge-group {
    display: flex;
    gap: 0.4rem;
    align-items: center;
    flex-wrap: wrap;
}

.compare-price {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 0.5rem;
}

.cheapest .compare-price {
    color: var(--accent);
}

.compare-details {
    font-size: 0.85rem;
    color: var(--text-muted);
    line-height: 1.4;
}

.price-note {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-align: center;
}

/* Ads */
.ad-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-align: center;
    margin-bottom: 0.25rem;
}

.ad-placeholder {
    width: 100%;
    min-height: 90px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px dashed rgba(255, 255, 255, 0.2);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 0.85rem;
    padding: 1rem;
    text-align: center;
    word-break: break-all;
}

.sidebar-placeholder {
    min-height: 250px;
}

/* Info Note & Cars Grid */
.info-note {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 1rem;
    opacity: 0.9;
}

.cars-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.75rem;
}

.car-item {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    padding: 0.75rem 1rem;
    border-radius: var(--radius-md);
}

.car-provider {
    font-size: 0.85rem;
    color: var(--primary);
    font-weight: 600;
    display: block;
    margin-bottom: 0.25rem;
}

.provider-link {
    color: var(--primary);
    text-decoration: none;
    border-bottom: 1px dashed rgba(59, 130, 246, 0.4);
    transition: all 0.2s;
}

.provider-link:hover {
    color: #60a5fa;
    border-bottom-style: solid;
}

.car-list {
    font-size: 0.9rem;
    color: var(--text-main);
}

.section-subtitle {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 0.2rem;
}

.section-note {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 1rem;
    font-style: italic;
}

/* Selectable Provider Items */
.car-item.selectable {
    display: flex;
    align-items: center;
    gap: 1rem;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
}

.car-item.selectable:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(59, 130, 246, 0.4);
}

.provider-check {
    width: 1.25rem;
    height: 1.25rem;
    accent-color: var(--primary);
    cursor: pointer;
    flex-shrink: 0;
}

.car-info {
    flex: 1;
}

/* Cars Toggle List for Mobile */
.cars-toggle {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.toggle-icon {
    display: none;
    font-size: 0.8rem;
    transition: transform 0.3s ease;
}

@media (max-width: 600px) {
    .cars-toggle {
        cursor: pointer;
    }
    
    .toggle-icon {
        display: block;
    }

    .cars-toggle.active .toggle-icon {
        transform: rotate(180deg);
    }
    
    #cars-content {
        display: none;
    }
    
    #cars-content.open {
        display: grid;
    }
}

/* Referral Section Styles */
.referral-section {
    margin-top: 1rem;
}

.referral-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
    margin-top: 1.5rem;
}

.referral-card-inner {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    transition: all 0.2s;
}

.referral-card-inner:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: var(--primary);
}

.referral-card-inner h3 {
    font-size: 1rem;
    color: var(--primary);
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.referral-code-box {
    background: var(--bg-dark);
    border: 1px dashed var(--primary);
    padding: 0.75rem;
    border-radius: 8px;
    text-align: center;
    font-family: monospace;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: 1px;
}

.referral-note {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.75rem;
}

.referral-link {
    display: inline-block;
    margin-top: 0.75rem;
    color: var(--primary);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 600;
    transition: color 0.2s, text-decoration 0.2s;
}

.referral-link:hover {
    color: var(--accent);
    text-decoration: underline;
}

/* Footer & SEO Content */
.about-section h3 {
    font-size: 1rem;
    color: var(--primary);
    margin-bottom: 0.5rem;
}

.about-section p {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.share-btn {
    transition: transform 0.2s, filter 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 120px;
}

.share-btn:hover {
    transform: translateY(-2px);
    filter: brightness(1.1);
}

.app-footer a:hover {
    color: var(--primary) !important;
}

@media (max-width: 600px) {
    .share-buttons {
        flex-direction: column;
        width: 100%;
    }
    .share-btn {
        width: 100%;
        text-align: center;
    }
}
