* {
    box-sizing: border-box;
}

:root {
    --preview-height: 280px;
}

body {
    margin: 0;
    font-family: sans-serif;
    color: #1a1a1a;
}

body.browse-mode {
    background-color: #faf6f0;
    padding: 2rem;
    max-width: 1000px;
    margin: 0 auto;
}

body.embed-mode {
    background-color: transparent;
    padding: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

body.embed-mode #app {
    flex: 1;
    display: flex;
    min-height: 0;
}

body.embed-mode .widget {
    flex: 1;
    min-height: 0;
}

header h1 {
    color: #e63946;
    margin: 0 0 0.4rem;
}

header p {
    margin: 0;
    max-width: 65ch;
    color: #444444;
    line-height: 1.5;
}

header code {
    background-color: #ffffff;
    border: 1px solid #e0e0e0;
    padding: 0.1em 0.4em;
    border-radius: 4px;
    font-size: 0.9em;
}

.category-section {
    margin-top: 2.5rem;
}

.category-section h2 {
    color: #2a9d8f;
    border-bottom: 2px solid #e0e0e0;
    padding-bottom: 0.4rem;
}

.demo-card {
    margin-bottom: 2rem;
}

.embed-url {
    margin: 0 0 0.6rem;
    font-size: 0.8rem;
    color: #666666;
}

.embed-url code {
    background-color: #ffffff;
    border: 1px solid #e0e0e0;
    padding: 0.15em 0.5em;
    border-radius: 4px;
}

.embed-link {
    color: inherit;
    text-decoration: none;
}

.embed-link:hover code {
    border-color: #2a9d8f;
    color: #2a9d8f;
}

.action-btn {
    display: inline-block;
    margin-left: 0.5rem;
    font-family: monospace;
    font-size: 0.75rem;
    background-color: #ffffff;
    color: #1a1a1a;
    border: 1px solid #e0e0e0;
    border-radius: 999px;
    padding: 0.2rem 0.6rem;
    cursor: pointer;
    text-decoration: none;
}

.action-btn:hover {
    border-color: #2a9d8f;
    color: #2a9d8f;
}

.action-btn:disabled {
    cursor: not-allowed;
    pointer-events: none;
    opacity: 0.4;
    color: #1a1a1a;
    border-color: #e0e0e0;
}

.height-control {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 1.25rem 0 0;
    font-size: 0.8rem;
    color: #444444;
}

.height-control label {
    font-weight: bold;
}

.height-control input {
    width: 5rem;
    padding: 0.2rem 0.4rem;
    font-family: monospace;
    font-size: 0.85rem;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
}

.width-control {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-top: 0.75rem;
    font-size: 0.8rem;
    color: #444444;
}

.width-control-label {
    font-weight: bold;
}

.width-control label {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    cursor: pointer;
}

.width-control code {
    background-color: #ffffff;
    border: 1px solid #e0e0e0;
    padding: 0.1em 0.4em;
    border-radius: 4px;
    font-size: 0.9em;
}

.widget {
    display: flex;
    flex-direction: column;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    overflow: hidden;
    background-color: #ffffff;
}

.controls-pane {
    display: flex;
    flex-direction: column;
    padding: 1rem;
    background-color: #faf6f0;
    border-bottom: 1px solid #e0e0e0;
}

.controls-pane h3 {
    margin: 0 0 0.5rem;
    font-family: monospace;
    font-size: 1rem;
    color: #e63946;
}

.demo-desc {
    margin: 0 0 1.25rem;
    font-size: 0.8rem;
    line-height: 1.5;
    color: #444444;
}

.tag-options {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.tag-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-family: monospace;
    font-size: 0.75rem;
    background-color: #ffffff;
    color: #1a1a1a;
    border: 2px solid #e0e0e0;
    border-radius: 999px;
    padding: 0.3rem 0.7rem;
    cursor: pointer;
    line-height: 1.3;
    text-align: left;
}

.tag-btn:hover {
    border-color: #2a9d8f;
}

.tag-btn.active {
    border-color: #2a9d8f;
    background-color: #2a9d8f;
    color: #ffffff;
}

.preview-pane {
    min-width: 0;
    flex: 1;
    display: flex;
}

.not-found {
    padding: 2rem;
    color: #e63946;
    font-family: monospace;
}

.test-frame-mode header code {
    color: #e63946;
}

.test-frame {
    display: block;
    width: 100%;
    margin-top: 1.5rem;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    background-color: #ffffff;
}

.test-actions {
    margin-top: 1rem;
}

.test-actions .action-btn {
    margin-left: 0;
    font-size: 0.85rem;
    padding: 0.4rem 1rem;
}

.resistor-widget {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    padding: 1rem 1.25rem;
    background-color: #ffffff;
    flex: 1;
    min-width: 0;
    min-height: 0;
    overflow-y: auto;
}

.widget.resistor-shell {
    flex-direction: row;
}

.resistor-body-wrap {
    display: flex;
    justify-content: center;
}

.resistor-svg {
    display: block;
    width: 100%;
    max-width: 320px;
    height: auto;
}

.resistor-svg .lead {
    stroke: #8d8d8d;
    stroke-width: 4;
}

.resistor-svg .body {
    fill: #e3c9a3;
    stroke: #b89b6e;
    stroke-width: 2;
}

.resistor-band {
    cursor: pointer;
    stroke: rgba(0, 0, 0, 0.15);
    stroke-width: 1;
}

.resistor-band:hover {
    stroke: #1a1a1a;
    stroke-width: 2;
}

.resistor-band.tolerance-band {
    opacity: 1;
}

.band-legend-item {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.band-legend-dot {
    width: 0.8rem;
    height: 0.8rem;
    border-radius: 50%;
    flex-shrink: 0;
    border: 1px solid rgba(0, 0, 0, 0.2);
}

.band-picker {
    position: absolute;
    z-index: 20;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    padding: 8px;
    background-color: #ffffff;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
}

.band-swatch {
    width: 32px;
    height: 32px;
    padding: 0;
    border-radius: 50%;
    border: 2px solid rgba(0, 0, 0, 0.15);
    cursor: pointer;
}

.band-swatch:hover {
    border-color: #1a1a1a;
}

.band-swatch.active {
    border-color: #2a9d8f;
    border-width: 3px;
}

.legend-panel {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    width: 210px;
    background-color: #faf6f0;
    border-left: 1px solid #e0e0e0;
    overflow: hidden;
    transition: width 0.15s ease;
}

.legend-panel.collapsed {
    width: 52px;
}

.legend-toggle {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    background: none;
    border: none;
    border-bottom: 1px solid #e0e0e0;
    padding: 0.7rem 0.4rem;
    cursor: pointer;
    font-family: monospace;
    font-size: 0.72rem;
    color: #444444;
}

.legend-toggle:hover {
    color: #2a9d8f;
}

.legend-toggle-icon {
    display: inline-block;
    transition: transform 0.15s ease;
}

.legend-panel:not(.collapsed) .legend-toggle-icon {
    transform: rotate(180deg);
}

.legend-toggle-label {
    writing-mode: vertical-rl;
    white-space: nowrap;
}

.legend-panel:not(.collapsed) .legend-toggle-label {
    writing-mode: horizontal-tb;
}

.legend-content {
    padding: 0.85rem;
    overflow-y: auto;
}

.legend-panel.collapsed .legend-content {
    display: none;
}

.legend-tabs {
    display: flex;
    gap: 0.3rem;
    margin-bottom: 0.75rem;
}

.legend-tab {
    flex: 1;
    font-family: monospace;
    font-size: 0.72rem;
    background-color: #ffffff;
    color: #444444;
    border: 1px solid #e0e0e0;
    border-radius: 999px;
    padding: 0.35rem 0.4rem;
    cursor: pointer;
}

.legend-tab:hover {
    border-color: #2a9d8f;
}

.legend-tab.active {
    border-color: #2a9d8f;
    background-color: #2a9d8f;
    color: #ffffff;
}

.legend-content h4 {
    margin: 0.9rem 0 0.4rem;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #666666;
}

.legend-content h4:first-child {
    margin-top: 0;
}

.legend-list {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.35rem 0.5rem;
    font-size: 0.78rem;
    color: #444444;
}

.legend-list[data-legend="digits"] {
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: repeat(5, auto);
    grid-auto-flow: column;
}

.readout {
    text-align: center;
}

.readout-value {
    font-family: monospace;
    font-size: 2.2rem;
    font-weight: bold;
    color: #2a9d8f;
}

.readout-calc {
    margin-top: 0.4rem;
    font-family: monospace;
    font-size: 0.85rem;
    color: #444444;
}

.readout-calc-line {
    margin-top: 0.15rem;
}

.readout-calc-line:first-child {
    margin-top: 0;
}

.readout-tolerance {
    margin-top: 0.3rem;
    font-size: 0.8rem;
    color: #666666;
}

.practice-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.8rem;
    flex-wrap: wrap;
    padding: 0.7rem 1rem;
    border-radius: 8px;
    background-color: #faf6f0;
    border: 1px solid #e0e0e0;
    font-size: 0.85rem;
}

.practice-target {
    font-family: monospace;
    font-weight: bold;
}

.practice-feedback {
    font-weight: bold;
    min-width: 8ch;
}

.practice-feedback.state-correct {
    color: #2a9d8f;
}

.practice-feedback.state-pending {
    color: #999999;
}

.legend-hint {
    margin: 0;
    text-align: center;
    font-size: 0.78rem;
    color: #666666;
}


.practice-feedback.state-wrong {
    color: #e63946;
}

.tag-btn.wrong {
    border-color: #e63946;
    background-color: #e63946;
    color: #ffffff;
}

.control-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-size: 0.85rem;
    flex-wrap: wrap;
}

.control-label {
    flex: 0 0 auto;
    font-weight: bold;
    min-width: 140px;
}

.control-row input[type="range"] {
    flex: 1;
    min-width: 100px;
    accent-color: #2a9d8f;
}

.control-row select,
.control-row input[type="number"] {
    font-family: monospace;
    font-size: 0.85rem;
    padding: 0.3rem 0.5rem;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    background: #ffffff;
    color: #1a1a1a;
}

.control-readout {
    font-family: monospace;
    font-weight: bold;
    color: #2a9d8f;
    min-width: 3.5ch;
    text-align: right;
}

.divider-diagram-wrap {
    display: flex;
    justify-content: center;
}

.divider-svg {
    width: 200px;
    height: auto;
    display: block;
}

.divider-lead {
    stroke: #8d8d8d;
    stroke-width: 3;
}

.divider-zigzag {
    fill: none;
    stroke: #1a1a1a;
    stroke-width: 2;
}

.divider-zigzag.variable {
    stroke: #e9a23b;
}

.divider-tap {
    fill: #2a9d8f;
}

.divider-label {
    font-family: monospace;
    font-size: 10px;
    fill: #444444;
}

.map-bounds {
    display: flex;
    gap: 1.5rem;
    justify-content: center;
    flex-wrap: wrap;
    font-size: 0.8rem;
}

.map-bounds-group {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    align-items: center;
}

.map-bounds-title {
    font-weight: bold;
    color: #444444;
}

.map-bounds-group label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.map-bounds-group input {
    width: 5.5rem;
    font-family: monospace;
    padding: 0.2rem 0.4rem;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
}

.map-bar-wrap {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.map-bar-label {
    font-size: 0.72rem;
    color: #666666;
}

.map-bar {
    position: relative;
    height: 10px;
    background: #e0e0e0;
    border-radius: 999px;
}

.map-bar-marker {
    position: absolute;
    top: 50%;
    width: 12px;
    height: 12px;
    background: #2a9d8f;
    border-radius: 50%;
    transform: translate(-50%, -50%);
}

.pwm-led-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
}

.pwm-led-swatch {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: #e63946;
    opacity: calc(0.15 + (var(--led-glow, 0) * 0.85));
    box-shadow: 0 0 20px rgba(230, 57, 70, var(--led-glow, 0));
}

.pwm-led-caption {
    font-size: 0.85rem;
    color: #444444;
    font-family: monospace;
}

.pwm-wave-wrap {
    display: flex;
    justify-content: center;
}

.pwm-wave-svg {
    width: 100%;
    max-width: 320px;
    height: auto;
}

.pwm-wave-path {
    fill: none;
    stroke: #2a9d8f;
    stroke-width: 3;
}

.schema-symbol-svg {
    width: 200px;
    height: auto;
    display: block;
    margin: 0 auto;
}

.schema-line {
    fill: none;
    stroke: #1a1a1a;
    stroke-width: 2;
}

.schema-fill {
    fill: #1a1a1a;
}

.schema-outline {
    fill: none;
    stroke: #1a1a1a;
    stroke-width: 2;
}

.schema-module-title {
    font-family: monospace;
    font-size: 11px;
    font-weight: bold;
    fill: #1a1a1a;
}

.schema-options {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
}
