:root {
    --bg-primary: #0f0f0f;
    --bg-secondary: #1a1a1a;
    --bg-card: #252525;
    --text-primary: #ffffff;
    --text-secondary: #a0a0a0;
    --text-muted: #666666;
    --accent-primary: #6366f1;
    --accent-secondary: #8b5cf6;
    --accent-gradient: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --border-color: #333333;
    --input-bg: #2a2a2a;
    --input-focus: #3a3a3a;
    --calculated-bg: #1e293b;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.3), 0 2px 4px -2px rgb(0 0 0 / 0.3);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.5), 0 4px 6px -4px rgb(0 0 0 / 0.5);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.6), 0 8px 10px -6px rgb(0 0 0 / 0.6);
}

[data-theme="light"] {
    --bg-primary: #f9fafb;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --text-primary: #111827;
    --text-secondary: #4b5563;
    --text-muted: #9ca3af;
    --border-color: #e5e7eb;
    --input-bg: #f3f4f6;
    --input-focus: #e5e7eb;
    --calculated-bg: #dbeafe;
    --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);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    position: relative;
    overflow-x: hidden;
    transition: background-color 0.3s ease, color 0.3s ease;
    font-size: 18px;
}

/* Background Effects */
.background-effects {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
}

.gradient-orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.15;
    animation: float 20s infinite ease-in-out;
}

.orb-1 {
    width: 500px;
    height: 500px;
    background: var(--accent-gradient);
    top: -200px;
    left: -200px;
    animation-delay: 0s;
}

.orb-2 {
    width: 400px;
    height: 400px;
    background: linear-gradient(135deg, #8b5cf6 0%, #ec4899 100%);
    bottom: -150px;
    right: -150px;
    animation-delay: 7s;
}

.orb-3 {
    width: 350px;
    height: 350px;
    background: linear-gradient(135deg, #06b6d4 0%, #3b82f6 100%);
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    animation-delay: 14s;
}

@keyframes float {
    0%, 100% { transform: translate(0, 0) scale(1); }
    33% { transform: translate(50px, -50px) scale(1.1); }
    66% { transform: translate(-50px, 50px) scale(0.9); }
}

/* Header */
header {
    position: relative;
    z-index: 10;
    background: var(--bg-secondary);
    padding: 2rem;
    border-bottom: 1px solid var(--border-color);
    box-shadow: var(--shadow-md);
    animation: slideDown 0.6s ease-out;
}

@keyframes slideDown {
    from {
        transform: translateY(-100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.header-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.dice-icon {
    width: 50px;
    height: 50px;
    background: var(--accent-gradient);
    border-radius: 12px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    padding: 8px;
    gap: 4px;
    box-shadow: var(--shadow-lg);
    animation: diceRotate 3s infinite ease-in-out;
}

@keyframes diceRotate {
    0%, 100% { transform: rotate(0deg); }
    50% { transform: rotate(10deg); }
}

.dice-dot {
    width: 100%;
    height: 100%;
    background: white;
    border-radius: 50%;
}

.dice-dot:nth-child(2),
.dice-dot:nth-child(4) {
    opacity: 0.7;
}

header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    font-size: 1.25rem;
    color: var(--text-secondary);
    font-weight: 300;
    letter-spacing: 0.05em;
}

.byline {
    font-size: 0.9rem;
    font-weight: 400;
    color: var(--text-muted);
    background: none;
    -webkit-text-fill-color: var(--text-muted);
    vertical-align: middle;
}

.header-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

.theme-toggle,
.download-btn,
.reset-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
}

.theme-toggle:hover,
.download-btn:hover,
.reset-btn:hover {
    background: var(--input-focus);
    border-color: var(--accent-primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.theme-toggle svg,
.download-btn svg,
.reset-btn svg {
    width: 20px;
    height: 20px;
}

.theme-toggle .sun-icon {
    display: none;
}

.theme-toggle .moon-icon {
    display: block;
}

[data-theme="light"] .theme-toggle .sun-icon {
    display: block;
}

[data-theme="light"] .theme-toggle .moon-icon {
    display: none;
}

/* Wake Lock Toggle (mobile only, see @media 768px below) */
.wakelock-bar {
    display: none;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 0.5rem 1rem;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    position: relative;
    z-index: 1;
}

.wakelock-label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-primary);
}

.wakelock-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
}

.wakelock-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.wakelock-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background-color: var(--border-color);
    border-radius: 999px;
    transition: background-color 0.25s ease;
}

.wakelock-slider::before {
    content: "";
    position: absolute;
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: #ffffff;
    border-radius: 50%;
    transition: transform 0.25s ease;
    box-shadow: var(--shadow-sm);
}

.wakelock-switch input:checked + .wakelock-slider {
    background: var(--accent-gradient);
}

.wakelock-switch input:checked + .wakelock-slider::before {
    transform: translateX(20px);
}

.wakelock-switch input:focus-visible + .wakelock-slider {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

/* Main Content */
main {
    position: relative;
    z-index: 1;
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
    animation: fadeIn 0.8s ease-out 0.2s backwards;
}

/* Tab Navigation */
.tab-nav {
    position: relative;
    z-index: 1;
    max-width: 1400px;
    margin: 0 auto;
    padding: 1rem 2rem 0;
    display: flex;
    gap: 0.75rem;
}

.tab-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.85rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: var(--bg-card);
    color: var(--text-secondary);
    font-size: 1rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.25s ease;
}

.tab-btn .tab-icon {
    font-size: 1.1rem;
}

.tab-btn:hover {
    border-color: var(--accent-primary);
    color: var(--text-primary);
}

.tab-btn.active {
    background: var(--accent-gradient);
    border-color: transparent;
    color: #ffffff;
    box-shadow: var(--shadow-md);
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
    animation: fadeIn 0.4s ease-out;
}

/* Würfeln Tab */
.dice-container {
    background: var(--bg-secondary);
    border-radius: 20px;
    padding: 2rem;
    box-shadow: var(--shadow-xl);
    border: 1px solid var(--border-color);
    text-align: center;
}

.dice-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 2rem;
    text-align: left;
}

.dice-header h2 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
}

.rolls-indicator {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--accent-primary);
    background: var(--calculated-bg);
    border-radius: 999px;
    padding: 0.4rem 1rem;
}

.dice-tray {
    display: flex;
    justify-content: center;
    gap: clamp(0.5rem, 2vw, 1.25rem);
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
}

.die {
    width: clamp(56px, 16vw, 80px);
    height: clamp(56px, 16vw, 80px);
    border: 2px solid var(--border-color);
    border-radius: 14px;
    background: var(--input-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    padding: 0;
}

.die .die-face {
    font-size: clamp(2rem, 8vw, 3rem);
    line-height: 1;
    color: var(--text-primary);
    user-select: none;
}

.die:disabled {
    cursor: default;
}

.die.pending {
    opacity: 0.5;
}

.die:not(:disabled):hover {
    border-color: var(--accent-primary);
    transform: translateY(-2px);
}

.die.held {
    background: var(--accent-gradient);
    border-color: transparent;
    box-shadow: var(--shadow-md);
}

.die.held .die-face {
    color: #ffffff;
}

.die.rolling .die-face {
    animation: diceShake 0.1s linear infinite;
}

@keyframes diceShake {
    0% { transform: rotate(-8deg) scale(0.95); }
    50% { transform: rotate(8deg) scale(1.05); }
    100% { transform: rotate(-8deg) scale(0.95); }
}

.dice-hint {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-bottom: 1.5rem;
}

.dice-actions {
    display: flex;
    justify-content: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.roll-btn,
.new-round-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.85rem 1.75rem;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.25s ease;
}

.roll-btn svg,
.new-round-btn svg {
    width: 20px;
    height: 20px;
}

.roll-btn {
    background: var(--accent-gradient);
    border-color: transparent;
    color: #ffffff;
}

.roll-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.roll-btn:disabled {
    opacity: 0.5;
    cursor: default;
    transform: none;
}

.new-round-btn {
    background: var(--bg-card);
    color: var(--text-primary);
}

.new-round-btn:hover {
    border-color: var(--accent-primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

/* ============================
   Party Animation (Full House, Poker, Straße, 5 Gleiche)
   Aufsteigend beeindruckender: tier-1 -> tier-4
   ============================ */
.party-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    pointer-events: none;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease;
}

.party-overlay.active {
    opacity: 1;
    visibility: visible;
}

.party-confetti {
    position: absolute;
    inset: 0;
}

.confetti-piece {
    position: absolute;
    top: -20px;
    opacity: 0.95;
    animation-name: confettiFall;
    animation-timing-function: cubic-bezier(0.35, 0, 0.65, 1);
    animation-fill-mode: forwards;
    will-change: transform, opacity;
}

@keyframes confettiFall {
    0% {
        transform: translateY(0) rotate(0deg);
        opacity: 1;
    }
    100% {
        transform: translateY(115vh) rotate(720deg);
        opacity: 0;
    }
}

.party-banner {
    position: absolute;
    top: 42%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.5);
    text-align: center;
    opacity: 0;
}

.party-overlay.active .party-banner {
    animation: partyBannerPop 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes partyBannerPop {
    0% {
        transform: translate(-50%, -50%) scale(0.3) rotate(-8deg);
        opacity: 0;
    }
    60% {
        transform: translate(-50%, -50%) scale(1.15) rotate(3deg);
        opacity: 1;
    }
    100% {
        transform: translate(-50%, -50%) scale(1) rotate(0deg);
        opacity: 1;
    }
}

.party-banner-text {
    display: inline-block;
    font-family: inherit;
    font-weight: 800;
    padding: 0.75rem 2rem;
    border-radius: 16px;
    color: #ffffff;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
    box-shadow: var(--shadow-xl);
    white-space: nowrap;
}

/* Tier 1: Full House */
.party-overlay.tier-1 .party-banner-text {
    font-size: clamp(1.4rem, 6vw, 2.1rem);
    background: linear-gradient(135deg, #22c55e, #16a34a);
}

/* Tier 2: Poker (4 Gleiche) */
.party-overlay.tier-2 .party-banner-text {
    font-size: clamp(1.6rem, 6.5vw, 2.5rem);
    background: linear-gradient(135deg, #3b82f6, #8b5cf6);
}

/* Tier 3: Straße */
.party-overlay.tier-3 .party-banner-text {
    font-size: clamp(1.8rem, 7.5vw, 2.9rem);
    background: linear-gradient(135deg, #f97316, #ef4444);
}

.party-overlay.tier-3 .party-banner {
    animation: partyBannerPop 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) forwards,
               partyBannerShake 0.5s ease 0.6s;
}

/* Tier 4: 5 Gleiche - das Maximum */
.party-overlay.tier-4 .party-banner-text {
    font-size: clamp(2rem, 9vw, 3.5rem);
    background: linear-gradient(135deg, #fbbf24, #f472b6, #a855f7, #3b82f6);
    background-size: 300% 300%;
    animation: partyRainbow 1.4s ease infinite;
}

.party-overlay.tier-4 .party-banner {
    animation: partyBannerPop 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) forwards,
               partyBannerShake 0.6s ease 0.6s 2;
}

.party-overlay.tier-4::before {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.18);
    animation: partyFlash 0.5s ease 2;
}

@keyframes partyRainbow {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

@keyframes partyBannerShake {
    0%, 100% { transform: translate(-50%, -50%) rotate(0deg); }
    20% { transform: translate(-52%, -50%) rotate(-3deg); }
    40% { transform: translate(-48%, -50%) rotate(3deg); }
    60% { transform: translate(-52%, -50%) rotate(-2deg); }
    80% { transform: translate(-48%, -50%) rotate(2deg); }
}

@keyframes partyFlash {
    0%, 100% { opacity: 0; }
    50% { opacity: 1; }
}

@keyframes screenShake {
    0%, 100% { transform: translate(0, 0); }
    20% { transform: translate(-6px, 3px); }
    40% { transform: translate(6px, -3px); }
    60% { transform: translate(-4px, 2px); }
    80% { transform: translate(4px, -2px); }
}

body.party-shake {
    animation: screenShake 0.4s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.game-container {
    background: var(--bg-secondary);
    border-radius: 20px;
    padding: 2rem;
    box-shadow: var(--shadow-xl);
    margin-bottom: 3rem;
    border: 1px solid var(--border-color);
}

.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.game-header h2 {
    font-size: 1.75rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* Game Board Table */
.game-board {
    overflow-x: auto;
    border-radius: 12px;
    margin-bottom: 2rem;
}

table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    background: var(--bg-card);
    border-radius: 12px;
    overflow: hidden;
}

thead {
    background: var(--accent-gradient);
}

thead th {
    padding: 1rem;
    color: white;
    font-weight: 600;
    text-align: center;
    font-size: 0.95rem;
    letter-spacing: 0.025em;
}

thead th:first-child {
    text-align: left;
    padding-left: 1.5rem;
}

tbody tr {
    border-bottom: 1px solid var(--border-color);
    transition: background-color 0.2s ease;
}

tbody tr:hover {
    background: var(--input-bg);
}

tbody tr:last-child {
    border-bottom: none;
}

.category-cell {
    padding: 1rem 1.5rem;
    font-weight: 500;
    vertical-align: middle;
}

.category-cell-inner {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.dice-preview {
    font-size: 1.5rem;
    line-height: 1;
}

.category-name {
    font-size: 1rem;
    color: var(--text-primary);
}

.score-hint,
.bonus-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 400;
}

.bonus-label {
    font-weight: 700;
    color: var(--accent-primary);
    font-size: 1.1rem;
}

.score-input {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    background: var(--input-bg);
    color: var(--text-primary);
    font-size: 1rem;
    font-weight: 600;
    text-align: center;
    transition: all 0.3s ease;
    font-family: 'Inter', sans-serif;
}

.score-input:focus {
    outline: none;
    border-color: var(--accent-primary);
    background: var(--input-focus);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
    transform: scale(1.02);
}

.score-input.has-value {
    background: var(--accent-gradient);
    color: white;
    border-color: transparent;
}

.score-input.has-x {
    background: var(--danger);
    color: white;
    border-color: transparent;
}

/* Special Buttons for Full, Poker, Straße */
.special-buttons {
    display: flex;
    gap: 0.25rem;
    justify-content: center;
    align-items: center;
    padding: 0.25rem;
}

.special-btn {
    flex: 1;
    min-width: 0;
    padding: 0.5rem;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    background: var(--input-bg);
    color: var(--text-secondary);
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: 'Inter', sans-serif;
    display: flex;
    align-items: center;
    justify-content: center;
}

.special-btn:hover {
    transform: scale(1.05);
    border-color: var(--accent-primary);
}

.special-btn.check {
    color: var(--success);
}

.special-btn.check:hover {
    background: var(--success);
    color: white;
}

.special-btn.check.active {
    background: var(--success);
    color: white;
    border-color: var(--success);
    transform: scale(1.1);
    box-shadow: 0 0 15px rgba(16, 185, 129, 0.5);
}

.special-btn.serviert {
    color: #f59e0b;
}

.special-btn.serviert:hover {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    color: white;
}

.special-btn.serviert.active {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    color: white;
    border-color: #f59e0b;
    transform: scale(1.1);
    box-shadow: 0 0 15px rgba(245, 158, 11, 0.5);
}

.special-btn.fail {
    color: var(--danger);
}

.special-btn.fail:hover {
    background: var(--danger);
    color: white;
}

.special-btn.fail.active {
    background: var(--danger);
    color: white;
    border-color: var(--danger);
    transform: scale(1.1);
    box-shadow: 0 0 15px rgba(239, 68, 68, 0.5);
}

.number-row td:not(.category-cell) {
    padding: 0.5rem 0.25rem;
}

.number-buttons {
    display: flex;
    gap: 0.2rem;
    justify-content: center;
    flex-wrap: wrap;
}

.num-btn {
    width: 42px;
    height: 42px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    background: var(--input-bg);
    color: var(--text-secondary);
    font-size: 1.1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: 'Inter', sans-serif;
    display: flex;
    align-items: center;
    justify-content: center;
}

.num-btn:hover {
    transform: scale(1.1);
    background: var(--accent-primary);
    color: white;
    border-color: var(--accent-primary);
}

.num-btn.fail-btn {
    color: var(--danger);
}

.num-btn.fail-btn:hover {
    background: var(--danger);
    color: white;
    border-color: var(--danger);
}

.number-result {
    width: 100%;
    padding: 0.5rem;
    border-radius: 6px;
    font-size: 1rem;
    font-weight: 700;
    text-align: center;
    transition: all 0.3s ease;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.number-result.check {
    background: var(--accent-gradient);
    color: white;
    box-shadow: 0 0 10px rgba(99, 102, 241, 0.3);
}

.number-result.fail {
    background: var(--danger);
    color: white;
    box-shadow: 0 0 10px rgba(239, 68, 68, 0.3);
}

.special-row td:not(.category-cell) {
    padding: 0.5rem 0.25rem;
}

.special-result {
    width: 100%;
    padding: 0.75rem;
    border-radius: 8px;
    font-size: 1.1rem;
    font-weight: 700;
    text-align: center;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.special-result:hover {
    transform: scale(1.05);
    box-shadow: var(--shadow-md);
}

.special-result.check {
    background: var(--success);
    color: white;
    border: 2px solid var(--success);
    box-shadow: 0 0 15px rgba(16, 185, 129, 0.3);
}

.special-result.serviert {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    color: white;
    border: 2px solid #f59e0b;
    box-shadow: 0 0 15px rgba(245, 158, 11, 0.3);
}

.special-result.fail {
    background: var(--danger);
    color: white;
    border: 2px solid var(--danger);
    box-shadow: 0 0 15px rgba(239, 68, 68, 0.3);
    font-size: 1.3rem;
}

tbody td:not(.category-cell) {
    padding: 0.5rem;
    text-align: center;
}

.calculated-cell {
    padding: 1rem;
    text-align: center;
    font-weight: 700;
    font-size: 1.1rem;
    background: var(--calculated-bg);
    color: var(--text-primary);
    position: relative;
}

.calculated-cell::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 2px;
    background: var(--accent-primary);
    transition: width 0.3s ease;
}

.calculated-cell.updated::after {
    width: 80%;
}

.bonus-row {
    background: var(--calculated-bg);
    font-weight: 600;
}

.section-divider {
    border-top: 3px solid var(--accent-primary);
}

.subtotal-row {
    background: var(--calculated-bg);
    font-weight: 700;
}

.total-row {
    background: var(--accent-gradient);
    font-weight: 700;
}

.total-row .category-cell {
    color: white;
}

.total-row .grand-total {
    background: transparent;
    color: white;
    font-size: 1.5rem;
}

/* Legend */
.legend {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 1.5rem;
    border: 1px solid var(--border-color);
}

.legend h3 {
    font-size: 1.1rem;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.legend ul {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.legend li {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.legend-color {
    width: 30px;
    height: 20px;
    border-radius: 4px;
    border: 1px solid var(--border-color);
}

.input-color {
    background: var(--input-bg);
}

.calc-color {
    background: var(--calculated-bg);
}

.legend-x {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 20px;
    background: var(--danger);
    color: white;
    font-weight: 700;
    border-radius: 4px;
    font-size: 0.85rem;
}

/* Rules Section */
.history-container {
    background: var(--bg-secondary);
    border-radius: 20px;
    padding: 2rem;
    box-shadow: var(--shadow-xl);
    margin-bottom: 3rem;
    border: 1px solid var(--border-color);
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.history-header h2 {
    font-size: 1.75rem;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: baseline;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.history-subtitle {
    font-size: 0.9rem;
    font-weight: 400;
    color: var(--text-secondary);
}

.history-clear-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    border-radius: 10px;
    border: 2px solid var(--border-color);
    background: var(--input-bg);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.history-clear-btn svg {
    width: 20px;
    height: 20px;
}

.history-clear-btn:hover {
    border-color: var(--danger);
    color: var(--danger);
}

.history-empty {
    color: var(--text-muted);
    text-align: center;
    padding: 1.5rem 1rem;
}

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

.history-item {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-left: 4px solid var(--border-color);
    border-radius: 12px;
    padding: 1rem 1.25rem;
    animation: fadeIn 0.4s ease-out;
    transition: border-color 0.2s ease, background 0.2s ease;
}

.history-item.result-win {
    border-left-color: #22c55e;
    background: var(--bg-card);
    background: color-mix(in srgb, #22c55e 8%, var(--bg-card));
}

.history-item.result-loss {
    border-left-color: #ef4444;
    background: var(--bg-card);
    background: color-mix(in srgb, #ef4444 8%, var(--bg-card));
}

.history-item-main {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.history-item-date {
    color: var(--text-muted);
    font-size: 0.85rem;
    min-width: 90px;
}

.history-item-columns {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.history-column-badge {
    background: var(--input-bg);
    color: var(--text-secondary);
    border-radius: 8px;
    padding: 0.3rem 0.65rem;
    font-size: 0.85rem;
    font-weight: 500;
}

.history-item-total {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--accent-primary);
    background: var(--calculated-bg);
    border-radius: 10px;
    padding: 0.4rem 0.9rem;
}

.history-result-buttons {
    display: flex;
    gap: 0.5rem;
}

.history-result-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 9px;
    background: var(--input-bg);
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s ease;
}

.history-result-btn:hover {
    border-color: var(--accent-primary);
    color: var(--text-primary);
}

.history-result-btn.win.active {
    background: linear-gradient(135deg, #22c55e, #16a34a);
    border-color: transparent;
    color: #ffffff;
}

.history-result-btn.loss.active {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    border-color: transparent;
    color: #ffffff;
}

@media (max-width: 640px) {
    .history-item-main {
        flex-direction: column;
        align-items: flex-start;
    }

    .history-item-total {
        align-self: stretch;
        text-align: center;
    }
}

.rules-section {
    background: var(--bg-secondary);
    border-radius: 20px;
    padding: 2rem;
    box-shadow: var(--shadow-xl);
    border: 1px solid var(--border-color);
    animation: fadeIn 0.8s ease-out 0.4s backwards;
}

.rules-section h2 {
    font-size: 1.75rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
    text-align: center;
    color: var(--text-primary);
}

.rules-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
}

.rule-card {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 1.5rem;
    border: 1px solid var(--border-color);
    transition: all 0.3s ease;
}

.rule-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
    border-color: var(--accent-primary);
}

.rule-card h3 {
    font-size: 1.2rem;
    margin-bottom: 1rem;
    color: var(--accent-primary);
    font-weight: 600;
}

.rule-card p {
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
    line-height: 1.6;
}

.rule-card ul {
    list-style: none;
    padding-left: 0;
}

.rule-card li {
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    padding-left: 1.5rem;
    position: relative;
}

.rule-card li::before {
    content: '•';
    position: absolute;
    left: 0;
    color: var(--accent-primary);
    font-weight: 700;
    font-size: 1.2rem;
}

.bonus-note {
    background: var(--accent-gradient);
    color: white;
    padding: 0.75rem;
    border-radius: 8px;
    font-weight: 500;
    margin-top: 0.75rem;
}

/* Footer */
footer {
    position: relative;
    z-index: 10;
    text-align: center;
    padding: 2rem;
    color: var(--text-muted);
    font-size: 0.9rem;
    border-top: 1px solid var(--border-color);
    background: var(--bg-secondary);
}

/* Animations */
@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.score-input:focus {
    animation: pulse 0.5s ease-in-out;
}

/* Custom Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.modal {
    background: var(--bg-card);
    border-radius: 20px;
    padding: 2.5rem;
    max-width: 450px;
    width: 90%;
    box-shadow: var(--shadow-xl);
    border: 1px solid var(--border-color);
    transform: scale(0.9);
    transition: transform 0.3s ease;
}

.modal-overlay.active .modal {
    transform: scale(1);
}

.modal-icon {
    width: 60px;
    height: 60px;
    margin: 0 auto 1.5rem;
    background: var(--accent-gradient);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: pulse 2s infinite;
}

.modal-icon svg {
    width: 30px;
    height: 30px;
    stroke: white;
}

.modal-title {
    font-size: 1.5rem;
    font-weight: 700;
    text-align: center;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.modal-text {
    font-size: 1rem;
    text-align: center;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    line-height: 1.6;
}

.modal-warning {
    font-size: 0.875rem;
    text-align: center;
    color: var(--danger);
    margin-bottom: 2rem;
    font-weight: 500;
}

.modal-buttons {
    display: flex;
    gap: 1rem;
}

.modal-btn {
    flex: 1;
    padding: 0.875rem 1.5rem;
    border: none;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: 'Inter', sans-serif;
}

.modal-btn.cancel {
    background: var(--input-bg);
    color: var(--text-primary);
    border: 2px solid var(--border-color);
}

.modal-btn.cancel:hover {
    background: var(--input-focus);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.modal-btn.confirm {
    background: var(--danger);
    color: white;
    border: 2px solid var(--danger);
}

.modal-btn.confirm:hover {
    background: #dc2626;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4);
}

/* ============================================
   Mobile Optimization
   Goal: the Spielblock (game board) fits fully
   on a phone screen with no zooming/scrolling.
   Rules, legend and footer may still require
   scrolling — that's fine.
   ============================================ */
@media (max-width: 768px) {
    html {
        font-size: 13px; /* scales nearly all rem-based spacing/typography down together */
    }

    body {
        font-size: 14px;
    }

    /* --- Compact app-bar style header --- */
    header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        flex-wrap: wrap;
        gap: 0.4rem;
        padding: 0.5rem 0.75rem;
    }

    .header-content {
        flex-direction: row;
        align-items: center;
        gap: 0.5rem;
        margin-bottom: 0;
    }

    .logo-container {
        gap: 0.4rem;
    }

    .dice-icon {
        width: 26px;
        height: 26px;
        padding: 4px;
        gap: 2px;
        border-radius: 7px;
    }

    header h1 {
        font-size: 1.05rem;
    }

    .byline {
        font-size: 0.6rem;
    }

    .subtitle {
        display: none;
    }

    .header-actions {
        gap: 0.4rem;
    }

    .theme-toggle span,
    .download-btn span,
    .reset-btn span {
        display: none; /* icon-only buttons to save space */
    }

    .theme-toggle,
    .download-btn {
        padding: 0.5rem;
        border-radius: 9px;
    }

    /* Wake Lock toggle only shows up on mobile */
    .wakelock-bar {
        display: flex;
    }

    .theme-toggle svg,
    .download-btn svg,
    .reset-btn svg {
        width: 16px;
        height: 16px;
    }

    /* --- Tighten main/container spacing --- */
    main {
        padding: 0.5rem;
    }

    .tab-nav {
        padding: 0.5rem 0.5rem 0;
        gap: 0.5rem;
    }

    .tab-btn {
        font-size: 0.8rem;
        padding: 0.6rem 0.5rem;
    }

    .dice-container {
        padding: 0.6rem;
        border-radius: 14px;
    }

    .dice-header h2 {
        font-size: 1.1rem;
    }

    .game-container {
        padding: 0.6rem;
        border-radius: 14px;
        margin-bottom: 1.25rem;
    }

    .game-header {
        margin-bottom: 0.5rem;
        gap: 0.4rem;
    }

    .game-header h2 {
        font-size: 1rem;
    }

    .reset-btn {
        padding: 0.5rem;
    }

    /* --- Compact table --- */
    .game-board {
        border-radius: 8px;
        margin-bottom: 1rem;
    }

    table {
        table-layout: fixed;
        width: 100%;
    }

    .category-col {
        width: 24%;
    }

    .score-col {
        width: 25.33%;
    }

    thead th {
        padding: 0.4rem 0.25rem;
        font-size: 0.62rem;
    }

    thead th:first-child {
        padding-left: 0.5rem;
    }

    .category-cell {
        padding: 0.35rem 0.4rem;
    }

    .category-cell-inner {
        gap: 0.3rem;
    }

    .dice-preview {
        font-size: 1.15rem;
        line-height: 1;
    }

    .category-name {
        font-size: 0.75rem;
    }

    .score-hint,
    .bonus-hint {
        font-size: 0.55rem;
    }

    .bonus-label {
        font-size: 0.8rem;
    }

    tbody td:not(.category-cell) {
        padding: 0.2rem 0.15rem;
    }

    .number-row td:not(.category-cell),
    .special-row td:not(.category-cell) {
        padding: 0.2rem 0.15rem;
    }

    /* Number buttons (1-6 rows): wrap into two rows of three instead of one row of six */
    .number-buttons {
        gap: 2px;
    }

    .num-btn {
        width: auto;
        height: 24px;
        min-width: 0;
        flex: 1 1 29%;
        padding: 0;
        font-size: 0.65rem;
        border-width: 1px;
        border-radius: 5px;
    }

    .number-result {
        padding: 0.3rem;
        font-size: 0.78rem;
        border-radius: 5px;
    }

    /* Special buttons (Full/Poker/Straße/Grande) */
    .special-buttons {
        gap: 0.15rem;
        padding: 0.1rem;
    }

    .special-btn {
        padding: 0.3rem 0.1rem;
        font-size: 0.7rem;
        border-width: 1px;
        border-radius: 5px;
    }

    .special-result {
        padding: 0.32rem;
        font-size: 0.78rem;
        border-radius: 6px;
    }

    .special-result.fail {
        font-size: 0.9rem;
    }

    .score-input {
        padding: 0.35rem;
        font-size: 0.78rem;
        border-width: 1px;
        border-radius: 6px;
    }

    .calculated-cell {
        padding: 0.4rem;
        font-size: 0.82rem;
    }

    .total-row .grand-total {
        font-size: 1.05rem;
    }

    .legend {
        padding: 1rem;
    }
}

/* Extra-small phones: squeeze a little further */
@media (max-width: 380px) {
    html {
        font-size: 12px;
    }

    .num-btn {
        height: 22px;
        font-size: 0.6rem;
    }

    .dice-icon {
        display: none; /* header gets even tighter */
    }

    header h1 {
        font-size: 0.95rem;
    }
}

/* Print Styles */
@media print {
    .background-effects,
    .header-actions,
    .wakelock-bar,
    .tab-nav,
    .reset-btn,
    .rules-section,
    .history-container,
    #tab-dice,
    .modal-overlay,
    .party-overlay,
    footer {
        display: none;
    }

    body {
        background: white;
        color: black;
    }

    #tab-scoreboard {
        display: block !important;
    }

    .game-container {
        box-shadow: none;
        border: 1px solid #ddd;
    }
}
