:root {
    --primary-color: #01894d;
    --accent-color: #f39800;
    --bg-color: #f8fafb;
    --card-bg: #ffffff;
    --text-primary: #333333;
    --text-secondary: #666666;
    --border-color: #e5e7eb;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
    --font-family: 'Noto Sans JP', 'Inter', sans-serif;
    --radius: 8px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.main-header {
    background-color: var(--primary-color);
    border-bottom: 2px solid var(--accent-color);
    padding: 12px 0;
    color: #ffffff;
    margin-bottom: 24px;
}

.main-header-inner {
    max-width: 800px;
    margin: 0 auto;
    padding: 0 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo-area {
    display: flex;
    align-items: center;
    gap: 10px;
}

.app-title {
    font-weight: 700;
    font-size: 1.2rem;
    color: #ffffff;
}

.header-nav {
    display: flex;
    gap: 8px;
}

.nav-btn {
    background-color: rgba(255, 255, 255, 0.15);
    color: #fff;
    text-decoration: none;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
    border: 1px solid rgba(255, 255, 255, 0.4);
    transition: all 0.2s;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.nav-btn:hover {
    background-color: rgba(255, 255, 255, 0.3);
    border-color: #fff;
}

/* Main Container */
.container {
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    padding: 0 16px 40px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* Info Section (Collapsible) */
.info-section {
    background-color: #fff;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 0;
    margin-bottom: 10px;
    box-shadow: var(--shadow);
    overflow: hidden;
}

.info-header {
    padding: 15px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    background-color: #fff;
    border-bottom: 1px solid transparent;
    transition: all 0.2s;
}

.info-header:hover {
    background-color: #f8fafb;
}

.info-header h2 {
    font-size: 1.1rem;
    color: var(--primary-color);
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
}

.toggle-icon {
    width: 20px;
    height: 20px;
    transition: transform 0.3s;
    fill: #999;
}

.info-content {
    padding: 24px;
    border-top: 1px solid var(--border-color);
    display: block;
}

.info-content p {
    font-size: 0.95rem;
    line-height: 1.6;
    color: var(--text-primary);
    margin-bottom: 16px;
}

.usage-steps {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

.usage-step {
    background-color: #f8fafb;
    padding: 15px;
    border-radius: 6px;
    position: relative;
    padding-left: 45px;
    font-size: 0.9rem;
    line-height: 1.5;
}

.usage-step::before {
    content: attr(data-step);
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 24px;
    height: 24px;
    background-color: var(--primary-color);
    color: #fff;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 0.8rem;
    font-weight: 700;
}

.info-section.collapsed .info-content {
    display: none;
}

.info-section.collapsed .toggle-icon {
    transform: rotate(-180deg);
}


/* Cards */
.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow);
    padding: 24px;
    overflow: hidden;
}

.card-header {
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 8px;
}

.card-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.section-number {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    width: 24px;
    height: 24px;
    background-color: var(--primary-color);
    color: #fff;
    border-radius: 50%;
    font-size: 0.85rem;
    font-weight: 700;
}

/* Result Area */
.result-container {
    text-align: center;
    padding: 10px 0;
}

.result-label {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.result-value-wrapper {
    display: flex;
    justify-content: center;
    align-items: baseline;
    gap: 12px;
    flex-wrap: wrap;
}

#resistance-value {
    font-size: 2.5rem;
    font-weight: 800;
    color: var(--primary-color);
}

#tolerance-value {
    font-size: 1.5rem;
    color: var(--text-secondary);
}

#ppm-value {
    font-size: 1rem;
    color: var(--text-secondary);
    display: block;
    margin-top: 4px;
}

/* Resistor Visualization */
.resistor-display-wrapper {
    background: linear-gradient(to bottom, #f8fafb 0%, #eef1f5 100%);
    border-radius: 8px;
    border: 1px solid var(--border-color);
    padding: 24px 0;
    margin-bottom: 24px;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    overflow: hidden;
}

.resistor-wrapper {
    position: relative;
    padding: 0 40px;
    /* Space for wires */
    display: flex;
    align-items: center;
}

.wire-left,
.wire-right {
    position: absolute;
    height: 4px;
    width: 40px;
    background: #9ca3af;
    top: 50%;
    transform: translateY(-50%);
}

.wire-left {
    left: 0;
}

.wire-right {
    right: 0;
}

.resistor-body {
    width: 240px;
    height: 70px;
    background: radial-gradient(circle at 30% 30%, #fde68a, #d4a76a, #92400e);
    background-color: #e5cb9e;
    /* Fallback */
    border-radius: 35px;
    position: relative;
    z-index: 2;
    box-shadow:
        inset 0 -8px 16px rgba(0, 0, 0, 0.2),
        inset 0 8px 16px rgba(255, 255, 255, 0.4),
        0 8px 16px rgba(0, 0, 0, 0.15);
    overflow: hidden;
}

.band {
    width: 14px;
    height: 100%;
    position: absolute;
    /* FIX: Visibility improvement */
    box-shadow:
        inset 0 0 2px rgba(0, 0, 0, 0.5),
        0 0 1px rgba(0, 0, 0, 0.3);
    /* Outer faint border */
}

/* Controls */
.controls-area {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.input-label {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.help-btn {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    width: 18px;
    height: 18px;
    background-color: #9ca3af;
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 12px;
    font-weight: bold;
    cursor: pointer;
    transition: background-color 0.2s;
}

.help-btn:hover {
    background-color: var(--primary-color);
}

/* Tabs */
.mode-tabs {
    display: flex;
    background: #f1f5f9;
    padding: 4px;
    border-radius: 8px;
    margin-bottom: 16px;
    gap: 4px;
}

.tab-btn {
    flex: 1;
    padding: 10px 4px;
    border: none;
    background: transparent;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-secondary);
    border-radius: 6px;
    transition: all 0.2s;
    font-family: inherit;
    white-space: nowrap;
}

.tab-btn:hover {
    color: var(--primary-color);
}

.tab-btn.active {
    background-color: #ffffff;
    color: var(--primary-color);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* Grid */
.grid-header {
    display: grid;
    /* Grid columns set by JS */
    gap: 6px;
    margin-bottom: 8px;
}

.col-header {
    text-align: center;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    white-space: nowrap;
}

.color-grid {
    display: grid;
    gap: 8px;
}

.grid-cell {
    height: 48px;
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    /* Stack text */
    justify-content: center;
    align-items: center;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 700;
    color: #fff;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    transition: all 0.1s;
    border: 1px solid transparent;
    position: relative;
    line-height: 1.1;
}

.grid-cell.white-cell {
    background-color: #ffffff !important;
    border: 1px solid #d1d5db !important;
    /* Visible border */
    color: #333 !important;
    text-shadow: none !important;
}

.grid-cell.light-text {
    color: #333;
    text-shadow: none;
}

/* Special styling for None/Gold/Silver */
.grid-cell.none-cell {
    background: repeating-linear-gradient(45deg,
            #f3f4f6,
            #f3f4f6 10px,
            #e5e7eb 10px,
            #e5e7eb 20px) !important;
    color: #666 !important;
    text-shadow: none !important;
    border: 1px solid #d1d5db !important;
}

.sub-label {
    font-size: 0.65rem;
    font-weight: 400;
    margin-top: 2px;
    opacity: 0.9;
}

.grid-cell:hover {
    transform: scale(1.02);
}

.grid-cell.selected {
    border-color: var(--accent-color) !important;
    border-width: 3px !important;
    box-shadow:
        0 0 0 2px #fff inset,
        /* Inner white gap */
        0 4px 8px rgba(0, 0, 0, 0.3);
    /* Stronger drop shadow */
    transform: scale(0.95);
    z-index: 10;
}

.grid-cell.empty {
    background: transparent !important;
    cursor: default;
    border: none !important;
    box-shadow: none !important;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 100;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.4);
}

.modal-content {
    background-color: white;
    margin: 15% auto;
    padding: 24px;
    border-radius: 12px;
    width: 90%;
    max-width: 450px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    position: relative;
    line-height: 1.6;
}

.close-btn {
    position: absolute;
    top: 10px;
    right: 15px;
    color: #aaa;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}

.close-btn:hover {
    color: black;
}

#modal-title {
    font-size: 1.2rem;
    color: var(--primary-color);
    margin-bottom: 12px;
    border-bottom: 2px solid var(--accent-color);
    padding-bottom: 5px;
}

/* Responsive */
@media (max-width: 600px) {
    .container {
        padding: 0 12px 40px;
    }

    .card {
        padding: 16px;
    }

    #resistance-value {
        font-size: 2rem;
    }

    .grid-cell {
        height: 44px;
        font-size: 0.75rem;
    }

    .resistor-body {
        width: 200px;
        height: 60px;
    }

    .usage-steps {
        grid-template-columns: 1fr;
    }
}

@media print {
    body {
        background-color: #fff;
    }

    .main-header,
    .info-section,
    .help-btn,
    .toggle-icon,
    .nav-btn {
        display: none !important;
    }

    .container {
        max-width: 100%;
        padding: 0;
        box-shadow: none;
    }

    .card {
        border: none;
        box-shadow: none;
        padding: 0;
        margin-bottom: 20px;
    }

    .card-header {
        border-bottom: 2px solid #333;
    }

    .resistor-display-wrapper {
        border: 1px solid #ccc;
        break-inside: avoid;
    }

    #resistance-value {
        color: #000;
    }
}