/* ============================================================================
   Bedienelemente: Stellenreihe, Lampenbalken, Drehschalter, Kippschalter,
   Summenzeile, Zähler und Ausgabeblöcke.
   ========================================================================== */

/* --------------------------------------------------------- Stellenreihe */

.place-scroll {
    overflow-x: auto;
    overflow-y: hidden;
    padding: 4px 0 8px;
    /* Nur diese Zeile darf waagerecht scrollen, nie die ganze Seite. */
}

.place-row {
    display: flex;
    justify-content: center;
    align-items: flex-end;
    gap: 18px;
    min-width: min-content;
    padding: 0 8px;
}

.place {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    flex: 0 0 auto;
}

/* Übertrags-Pfeil: sitzt links neben der Stelle, die den Übertrag bekommt. */
.carry-arrow {
    position: absolute;
    left: -16px;
    top: 42%;
    font-size: 1.4rem;
    line-height: 1;
    color: var(--accent-color);
    opacity: 0;
    pointer-events: none;
}

.place.carrying .carry-arrow {
    animation: carry-flash 0.7s ease-out;
}

.place.carrying .lamp-bar .lamp.on {
    animation: carry-pulse 0.7s ease-out;
}

@keyframes carry-flash {
    0% { opacity: 0; transform: translateX(10px); }
    30% { opacity: 1; transform: translateX(0); }
    100% { opacity: 0; transform: translateX(-6px); }
}

@keyframes carry-pulse {
    0%, 100% { box-shadow: 0 0 12px var(--led-on); }
    40% { box-shadow: 0 0 22px var(--accent-color), 0 0 40px var(--accent-color); }
}

/* ------------------------------------------------------------ Lampenbalken */

.lamp-bar {
    display: flex;
    flex-direction: column;
    gap: 3px;
    align-items: center;
    justify-content: flex-end;
    min-height: 44px;
}

.lamp {
    width: 26px;
    height: 7px;
    border-radius: 3px;
    background-color: var(--led-off);
    opacity: 0.35;
    transition: all 0.2s ease;
}

.lamp.on {
    background-color: var(--led-on);
    opacity: 1;
    box-shadow: 0 0 8px var(--led-on), 0 0 16px rgba(16, 185, 129, 0.5);
}

/* Bei Basis 2 bleibt eine einzelne runde Lampe - die klassische LED. */
.lamp-bar.single .lamp {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    box-shadow: inset 0 2px 4px 0 rgb(0 0 0 / 0.3);
    opacity: 1;
    background-color: var(--led-off);
}

.lamp-bar.single .lamp.on {
    background-color: var(--led-on);
    box-shadow: 0 0 20px var(--led-on), 0 0 40px var(--led-on), inset 0 2px 4px 0 rgb(0 0 0 / 0.3);
}

/* Viele Segmente bei großer Basis kompakter darstellen. */
.place-row[data-base="13"] .lamp,
.place-row[data-base="14"] .lamp,
.place-row[data-base="15"] .lamp,
.place-row[data-base="16"] .lamp {
    height: 5px;
    gap: 2px;
}

/* ------------------------------------------------------------ Drehschalter */

.place-input {
    display: flex;
    justify-content: center;
}

.dial {
    position: relative;
    width: 116px;
    height: 116px;
    cursor: pointer;
    border-radius: 50%;
    touch-action: none;              /* Drag darf die Seite nicht scrollen */
    outline: none;
    transition: filter 0.2s;
}

.dial:focus-visible {
    box-shadow: 0 0 0 3px var(--accent-color);
}

.dial:hover,
.dial.dragging {
    filter: drop-shadow(0 0 8px var(--trace-glow));
}

.dial-face {
    width: 100%;
    height: 100%;
    display: block;
}

.dial-ring {
    fill: var(--card-bg);
    stroke: var(--border-color);
    stroke-width: 3;
}

.dial-tick {
    fill: var(--led-off);
    opacity: 0.55;
    transition: all 0.2s ease;
}

.dial-tick.active {
    fill: var(--primary-color);
    opacity: 1;
    filter: drop-shadow(0 0 6px var(--primary-color)) drop-shadow(0 0 12px var(--primary-color));
}

/* Heller Keil als mechanischer Zeiger - hebt sich von den cyanfarbenen
   Rasten ab, sodass Zeiger und gewaehlte Raste unterscheidbar bleiben. */
.dial-pointer {
    fill: var(--text-primary);
    stroke: none;
    /* KEIN transform-origin setzen: das transform-Attribut bringt mit
       rotate(winkel 60 60) sein Drehzentrum schon mit. Beides zusammen
       verschiebt den Zeiger aus dem sichtbaren Bereich heraus. */
    transition: transform 0.18s ease;
    filter: drop-shadow(0 0 4px rgba(0, 0, 0, 0.6));
}

.dial-knob {
    fill: var(--surface-color);
    stroke: var(--trace-color);
    stroke-width: 2;
}

.dial-digit {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--mono);
    font-size: 1.7rem;
    font-weight: 700;
    color: var(--primary-color);
    text-shadow: 0 0 8px var(--trace-glow);
    pointer-events: none;
}

/* --------------------------------------------------------- Kippschalter */

.switch {
    position: relative;
    display: inline-block;
    width: 80px;
    height: 44px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background-color: var(--switch-off);
    transition: 0.3s;
    border-radius: 22px;
    box-shadow: var(--shadow);
}

.slider::before {
    position: absolute;
    content: "";
    height: 36px;
    width: 36px;
    left: 4px;
    bottom: 4px;
    background-color: #fff;
    transition: 0.3s;
    border-radius: 50%;
    box-shadow: 0 2px 4px 0 rgb(0 0 0 / 0.2);
}

.switch input:checked + .slider {
    background-color: var(--switch-on);
}

.switch input:checked + .slider::before {
    transform: translateX(36px);
}

.switch input:focus-visible + .slider {
    box-shadow: 0 0 0 3px var(--accent-color);
}

/* ------------------------------------------------- Beschriftung je Stelle */

.place-label {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-secondary);
    font-family: var(--mono);
}

.place.active .place-label {
    color: var(--primary-color);
}

.place-value {
    font-size: 1rem;
    font-weight: 600;
    color: var(--primary-color);
    padding: 6px 8px;
    background-color: var(--border-color);
    border-radius: 8px;
    min-width: 64px;
    text-align: center;
    font-family: var(--mono);
    transition: opacity 0.2s;
    opacity: 0.4;
}

.place.active .place-value {
    opacity: 1;
}

.place-term {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-family: var(--mono);
    white-space: nowrap;
    opacity: 0.4;
}

.place.active .place-term {
    color: var(--accent-color);
    opacity: 1;
}

.place.changed .dial-digit,
.place.changed .place-value {
    animation: place-pop 0.3s ease;
}

@keyframes place-pop {
    50% { transform: scale(1.12); }
}

/* -------------------------------------------------------------- Hinweise */

.carry-note {
    margin: 16px auto 0;
    max-width: 620px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-align: center;
    border-left: 3px solid var(--accent-color);
    padding-left: 12px;
    text-align: left;
}

/* ------------------------------------------------------------ Summenzeile */

.sum-line {
    margin-top: 22px;
    padding: 14px 16px;
    border-radius: 10px;
    background-color: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border-color);
    font-family: var(--mono);
    font-size: 1rem;
    text-align: center;
    line-height: 2.1;
    overflow-x: auto;
}

.sum-term {
    color: var(--primary-color);
    white-space: nowrap;
}

.sum-op {
    color: var(--text-secondary);
    margin: 0 8px;
}

.sum-line strong {
    color: var(--accent-color);
    font-size: 1.2rem;
}

.sum-empty {
    color: var(--text-secondary);
}

/* ----------------------------------------------------------------- Zähler */

.counter-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    margin-top: 22px;
    flex-wrap: wrap;
}

.counter-btn {
    width: 56px;
    height: 48px;
    border-radius: 10px;
    border: 1px solid var(--trace-color);
    background-color: var(--border-color);
    color: var(--primary-color);
    font-size: 1.2rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
}

.counter-btn:hover {
    background-color: var(--surface-color);
    border-color: var(--primary-color);
    box-shadow: 0 0 10px var(--trace-glow);
}

.counter-btn:active {
    transform: translateY(1px);
}

.counter-value {
    font-family: var(--mono);
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text-primary);
    min-width: 80px;
    text-align: center;
}

/* ------------------------------------------------------- Einstellungszeile */

.settings-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 18px;
    flex-wrap: wrap;
    margin-bottom: 24px;
    padding-bottom: 18px;
    border-bottom: 1px dashed var(--border-color);
}

.settings-field {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.95rem;
    font-weight: 500;
}

.settings-field select {
    background-color: var(--border-color);
    color: var(--text-primary);
    border: 1px solid var(--trace-color);
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 1rem;
    font-family: var(--mono);
    cursor: pointer;
}

.settings-field select:hover {
    border-color: var(--primary-color);
}

.settings-hint {
    flex-basis: 100%;
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-family: var(--mono);
}

/* ------------------------------------------------------------- Ausgaben */

.output-block {
    text-align: center;
    padding: 18px;
    border-radius: 12px;
    background-color: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border-color);
    margin-bottom: 18px;
}

.output-block:last-child {
    margin-bottom: 0;
}

.output-label {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.output-value {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--primary-color);
    font-family: var(--mono);
    word-break: break-all;
    transition: transform 0.3s ease, text-shadow 0.3s ease;
}

.output-value.big {
    font-size: 4.5rem;
    line-height: 1.1;
}

.output-value.changed {
    transform: scale(1.02);
    text-shadow: 0 0 20px currentColor;
}

.output-sub {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 6px;
}

.output-block.primary {
    border-color: var(--primary-color);
    box-shadow: 0 0 14px rgba(34, 211, 238, 0.15);
}

.grayscale-box {
    width: 80px;
    height: 80px;
    margin: 10px auto 0;
    border-radius: 8px;
    border: 2px solid var(--border-color);
    transition: background-color 0.3s ease;
}

/* ------------------------------------------------------------- Tabellen */

.conversion-table,
.nibble-table {
    width: 100%;
    border-collapse: collapse;
    font-family: var(--mono);
    font-size: 0.95rem;
    margin-top: 6px;
}

.conversion-table th,
.conversion-table td,
.nibble-table th,
.nibble-table td {
    border: 1px solid var(--border-color);
    padding: 6px 10px;
    text-align: center;
}

.conversion-table th,
.nibble-table th {
    background-color: var(--border-color);
    color: var(--text-secondary);
    font-weight: 600;
}

.conversion-table td {
    color: var(--text-primary);
    text-align: right;
}

.conversion-rest {
    text-align: center !important;
    color: var(--accent-color) !important;
    font-weight: 700;
}

.conversion-rest span {
    color: var(--primary-color);
    margin-left: 6px;
}

.conversion-result {
    margin-top: 10px;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.conversion-result strong {
    color: var(--accent-color);
    font-family: var(--mono);
    font-size: 1.1rem;
}

.nibble-table td {
    color: var(--primary-color);
    font-size: 1.05rem;
    font-weight: 700;
}

.nibble-table tr:last-child td {
    color: var(--accent-color);
    letter-spacing: 1px;
}

/* ---------------------------------------------- Größere Ziele für Touch */

@media (hover: none) and (pointer: coarse) {
    .dial { width: 120px; height: 120px; }
    .switch { width: 90px; height: 50px; }
    .slider::before { height: 42px; width: 42px; }
    .switch input:checked + .slider::before { transform: translateX(40px); }
    .counter-btn { width: 64px; height: 56px; }
}

@media (max-width: 768px) {
    .place-row { gap: 12px; }
    .dial { width: 88px; height: 88px; }
    .dial-digit { font-size: 1.4rem; }
    .switch { width: 60px; height: 34px; }
    .slider::before { height: 26px; width: 26px; }
    .switch input:checked + .slider::before { transform: translateX(26px); }
    .lamp-bar.single .lamp { width: 30px; height: 30px; }
    .output-value.big { font-size: 3rem; }
    .place-value { min-width: 52px; font-size: 0.85rem; }
}
