:root {
    /* Dark Theme (Default) */
    --bg-color: #0f172a;
    --text-color: #e2e8f0;
    --primary-color: #3b82f6;
    --primary-hover: #2563eb;
    --secondary-color: #94a3b8;
    --accent-color: #ef4444;
    /* Alert color - bright red for high visibility */
    --accent-bright: #dc2626;
    --surface-color: #1e293b;
    --border-color: #334155;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.3);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.3), 0 2px 4px -2px rgb(0 0 0 / 0.2);
    --radius: 12px;

    /* Input backgrounds for dark theme */
    --input-bg: #0f172a;
    --input-text: #e2e8f0;
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: background-color 0.3s ease;
    overflow: hidden;
}

/* Alert State - bright red for high visibility in dark mode */
body.alert-active {
    background-color: var(--accent-bright);
}

body.alert-active .app-container {
    box-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.4), 0 8px 10px -6px rgb(0 0 0 / 0.3);
    border: 3px solid #fca5a5;
}

.app-container {
    background-color: var(--surface-color);
    width: 90%;
    max-width: 900px;
    height: 90vh;
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    transition: transform 0.2s ease;
}

/* Header */
header {
    padding: 1.5rem 2rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(30, 41, 59, 0.9);
    backdrop-filter: blur(10px);
    z-index: 10;
}

header h1 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-color);
}

.timer-display {
    font-variant-numeric: tabular-nums;
    font-weight: 700;
    color: var(--primary-color);
    font-size: 1.5rem;
    padding: 0.25rem 0.75rem;
    background: rgba(59, 130, 246, 0.15);
    border-radius: 8px;
}

/* Home Button */
.home-btn {
    font-size: 1.5rem;
    text-decoration: none;
    padding: 0.25rem 0.5rem;
    border-radius: 8px;
    transition: background 0.2s, transform 0.2s;
    display: inline-block;
}

.home-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: scale(1.1);
}

/* Debug Console - positioned on right side */
.debug-console {
    position: fixed;
    top: 50%;
    right: 0;
    transform: translateY(-50%);
    background: #1e293b;
    color: #e2e8f0;
    border-left: 2px solid var(--primary-color);
    border-radius: 8px 0 0 8px;
    width: 350px;
    max-height: 400px;
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: width 0.3s ease, opacity 0.3s ease;
    box-shadow: -4px 0 15px rgba(0, 0, 0, 0.2);
}

.debug-console.collapsed {
    width: 40px;
}

.debug-console.collapsed .debug-content {
    display: none;
}

.debug-console.collapsed .debug-header span {
    display: none;
}

.debug-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0.75rem;
    background: #0f172a;
    font-size: 0.8rem;
    font-weight: 600;
    border-bottom: 1px solid #334155;
    border-radius: 8px 0 0 0;
    min-height: 36px;
}

.debug-header .icon-button {
    color: #e2e8f0;
    font-size: 0.875rem;
    transition: transform 0.3s;
}

.debug-console.collapsed .debug-header .icon-button {
    transform: rotate(180deg);
}

.debug-content {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

.debug-messages {
    font-family: 'Courier New', monospace;
    font-size: 0.75rem;
    line-height: 1.4;
}

.debug-message {
    padding: 0.25rem 0.5rem;
    margin-bottom: 0.25rem;
    border-left: 3px solid transparent;
    border-radius: 2px;
}

.debug-message.debug {
    background: #1e3a5f;
    border-left-color: #3b82f6;
}

.debug-message.info {
    background: #1e3a2f;
    border-left-color: #10b981;
}

.debug-message.warn {
    background: #3a2e1e;
    border-left-color: #f59e0b;
}

.debug-message.error {
    background: #3a1e1e;
    border-left-color: #ef4444;
}

.debug-message .timestamp {
    color: #94a3b8;
    margin-right: 0.5rem;
}

.debug-message .tag {
    color: #60a5fa;
    font-weight: 600;
    margin-right: 0.5rem;
}


/* Main Game Area */
.game-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: relative;
    padding: 2rem;
    background: radial-gradient(circle at center, rgba(59, 130, 246, 0.05) 0%, transparent 70%);
}

.dice-container {
    display: flex;
    flex-wrap: wrap;
    gap: 2rem;
    justify-content: center;
    align-items: center;
    perspective: 1000px;
}

.die {
    width: 100px;
    height: 100px;
    background-color: var(--surface-color);
    border: 3px solid var(--border-color);
    border-radius: 16px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--text-color);
    box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.3);
    transition: transform 0.2s cubic-bezier(0.18, 0.89, 0.32, 1.28);
    position: relative;
}

.die.rolling {
    animation: shake 0.3s ease-in-out;
    color: var(--secondary-color);
}

@keyframes shake {
    0% {
        transform: rotate(0deg) scale(1);
    }

    25% {
        transform: rotate(5deg) scale(0.95);
    }

    50% {
        transform: rotate(-5deg) scale(1.05);
    }

    75% {
        transform: rotate(5deg) scale(0.95);
    }

    100% {
        transform: rotate(0deg) scale(1);
    }
}

.die.match {
    border-color: var(--accent-color);
    color: var(--accent-color);
    box-shadow: 0 0 0 6px rgba(239, 68, 68, 0.2);
    /* Override colors if specific ones set */
}

/* Alert Message - positioned below dice */
.alert-message {
    position: relative;
    margin-top: 1.5rem;
    background-color: var(--accent-color);
    color: white;
    padding: 0.5rem 1.5rem;
    border-radius: 20px;
    font-weight: 600;
    box-shadow: var(--shadow-md);
    transform: translateY(0);
    opacity: 1;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 5;
}

.alert-message.hidden {
    opacity: 0;
    transform: translateY(20px);
    pointer-events: none;
}

/* Rolls Counter */
.rolls-counter {
    margin-top: 1rem;
    font-size: 0.9rem;
    color: var(--secondary-color);
    font-weight: 500;
}

.rolls-counter span {
    font-weight: 700;
    color: var(--primary-color);
}

/* Extend Button */
.extend-btn {
    margin-top: 1.5rem;
    animation: pulse 2s infinite;
}

.extend-btn.hidden {
    display: none;
}

@keyframes pulse {

    0%,
    100% {
        box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.4);
    }

    50% {
        box-shadow: 0 0 0 10px rgba(59, 130, 246, 0);
    }
}

/* JSON Controls in Modal */
.json-controls {
    display: flex;
    gap: 0.5rem;
    margin-right: auto;
}

/* Controls Panel */
.controls-panel {
    background-color: var(--surface-color);
    border-top: 1px solid var(--border-color);
    padding: 1.5rem 2rem;
    transition: transform 0.3s ease;
    overflow-y: auto;
    max-height: 50vh;
}

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

.controls-header h2 {
    font-size: 1rem;
    font-weight: 600;
}

.icon-button {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--secondary-color);
    padding: 0.25rem;
    border-radius: 4px;
    transition: background 0.2s;
}

.icon-button:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-color);
}

.settings-content {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1.5rem;
    margin-bottom: 1.5rem;
    transition: max-height 0.3s ease, opacity 0.3s ease;
}

.settings-content.collapsed {
    max-height: 0;
    opacity: 0;
    margin-bottom: 0;
    overflow: hidden;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.control-group label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--secondary-color);
}

.control-group input[type="number"],
.control-group select {
    padding: 0.625rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-family: inherit;
    font-size: 1rem;
    transition: border-color 0.2s;
    outline: none;
    width: 100%;
    background-color: var(--input-bg);
    color: var(--input-text);
}

.control-group input[type="range"] {
    width: 100%;
}

.control-group input[type="number"]:focus,
.control-group select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.1);
}

.checkbox-group {
    flex-direction: row;
    align-items: center;
    padding-top: 1.5rem;
    cursor: pointer;
}

.checkbox-group input {
    width: 1.25rem;
    height: 1.25rem;
    cursor: pointer;
}

.checkbox-group label {
    cursor: pointer;
}

/* Action Buttons */
.action-buttons {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
}

.primary-btn,
.secondary-btn {
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.9375rem;
    cursor: pointer;
    border: none;
    transition: all 0.2s ease;
}

.primary-btn {
    background-color: var(--primary-color);
    color: white;
}

.primary-btn:hover {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 6px -1px rgba(59, 130, 246, 0.3);
}

.primary-btn.paused {
    background-color: #f59e0b;
}

.primary-btn.paused:hover {
    background-color: #d97706;
    box-shadow: 0 4px 6px -1px rgba(245, 158, 11, 0.3);
}

.secondary-btn {
    background-color: rgba(255, 255, 255, 0.1);
    color: var(--text-color);
    border: 1px solid var(--border-color);
}

.secondary-btn:hover {
    background-color: rgba(255, 255, 255, 0.15);
}

.secondary-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.secondary-btn.dashed {
    border: 2px dashed var(--border-color);
    background: transparent;
}

.secondary-btn.dashed:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    opacity: 1;
    pointer-events: auto;
    transition: opacity 0.2s;
}

.modal.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-content {
    background: var(--surface-color);
    width: 90%;
    max-width: 850px;
    max-height: 85vh;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 25px 50px -12px rgb(0 0 0 / 0.5);
    overflow: hidden;
}

.modal-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(15, 23, 42, 0.8);
}

.modal-header h2 {
    font-size: 1.1em;
}

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    flex: 1;
}

/* Side-by-side layout for player config and event definitions */
.modal-body-columns {
    display: flex;
    gap: 1.5rem;
}

.player-config-section,
.event-definitions-section {
    flex: 1;
    min-width: 0;
    max-height: 55vh;
    overflow-y: auto;
    padding-right: 0.5rem;
}

.player-config-section {
    border-right: 1px solid var(--border-color);
    padding-right: 1.5rem;
}

.player-list {
    max-height: 40vh;
    overflow-y: auto;
}

.modal-intro {
    font-size: 0.9em;
    color: var(--secondary-color);
    margin-bottom: 1rem;
}

.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(15, 23, 42, 0.8);
}

/* Import section with icon button */
.import-section {
    display: flex;
    align-items: center;
}

.icon-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.5rem 0.75rem;
    font-size: 1.25rem;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--primary-color);
}

/* Split button group for Save & Export / Save */
.save-button-group {
    display: flex;
}

.primary-btn.split-left {
    border-radius: 8px 0 0 8px;
    border-right: 1px solid rgba(255, 255, 255, 0.2);
}

.primary-btn.split-right {
    border-radius: 0 8px 8px 0;
}

/* Advanced Logic UI */
.event-def {
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1rem;
    position: relative;
    background: rgba(15, 23, 42, 0.5);
}

.event-def-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.5rem;
    font-size: 0.85em;
    font-weight: 700;
    color: var(--secondary-color);
}

.remove-event-btn {
    color: var(--accent-color);
    cursor: pointer;
    font-size: 0.9em;
}

.rule-group {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
    margin-top: 0.5rem;
}

.rule-item {
    background: rgba(59, 130, 246, 0.15);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.9em;
    border: 1px solid rgba(59, 130, 246, 0.3);
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.logic-operator {
    font-weight: bold;
    color: var(--secondary-color);
    font-size: 0.8em;
    background: rgba(255, 255, 255, 0.1);
    padding: 0.1rem 0.3rem;
    border-radius: 4px;
}

/* ============================================
   Analytics Dashboard Panel
   ============================================ */

.analytics-panel {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: 320px;
    /* Default, controlled by JS */
    min-width: 280px;
    max-width: 600px;
    background: var(--surface-color);
    border-right: 2px solid var(--primary-color);
    z-index: 90;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
    overflow: hidden;
}

.analytics-panel.hidden {
    transform: translateX(-100%);
}

.analytics-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background: rgba(15, 23, 42, 0.8);
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
    font-size: 0.9rem;
}

.analytics-content {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    padding-bottom: 3rem;
    /* Extra padding for mobile scroll */
}

.mobile-warning {
    margin-top: 2rem;
    text-align: center;
    color: #fef08a;
    /* Light yellow */
    opacity: 0.8;
    font-size: 0.85rem;
    padding: 0 1rem;
}

.spacer-bottom {
    height: 100px;
    /* Substantial whitespace */
}

.analytics-section {
    margin-bottom: 1.5rem;
}

.analytics-section h3 {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--secondary-color);
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Current Turn Info */
.current-turn-info {
    background: rgba(59, 130, 246, 0.15);
    border: 1px solid rgba(59, 130, 246, 0.3);
    border-radius: 8px;
    padding: 0.75rem;
}

.current-turn-info .player-name {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: 0.25rem;
}

.current-turn-info .turn-stats {
    display: flex;
    gap: 1rem;
    font-size: 0.85rem;
    color: var(--secondary-color);
}

.current-turn-info .turn-stats strong {
    color: var(--text-color);
}

/* Leaderboard */
.leaderboard {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.leaderboard-item {
    display: flex;
    align-items: center;
    padding: 0.5rem;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 6px;
    font-size: 0.85rem;
}

.leaderboard-item.current {
    background: rgba(59, 130, 246, 0.2);
    border: 1px solid rgba(59, 130, 246, 0.3);
}

.leaderboard-item .rank {
    width: 24px;
    font-weight: 700;
    color: var(--secondary-color);
}

.leaderboard-item .rank.gold {
    color: #fbbf24;
}

.leaderboard-item .rank.silver {
    color: #9ca3af;
}

.leaderboard-item .rank.bronze {
    color: #cd7f32;
}

.leaderboard-item .player-info {
    flex: 1;
}

.leaderboard-item .player-stats {
    text-align: right;
    font-size: 0.75rem;
    color: var(--secondary-color);
}

.leaderboard-placeholder,
.timeline-placeholder,
.heatmap-placeholder {
    color: var(--secondary-color);
    font-size: 0.85rem;
    font-style: italic;
    padding: 0.5rem;
    text-align: center;
}

/* Heatmap Legend */
.heatmap-legend {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 0.5rem;
    font-size: 0.8rem;
    color: var(--secondary-color);
}

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

.color-box {
    width: 12px;
    height: 12px;
    border-radius: 2px;
}

.color-box.cold {
    background-color: #3b82f6;
}

.color-box.expected {
    background-color: #10b981;
}

.color-box.hot {
    background-color: #ef4444;
}

/* Timeline Graph */
.timeline-visual {
    height: 100px;
    width: 100%;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
    margin-bottom: 0.5rem;
    position: relative;
}

#timeline-canvas {
    width: 100%;
    height: 100%;
}

/* Timeline */
.timeline {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    max-height: 200px;
    overflow-y: auto;
}

.timeline-item {
    display: flex;
    align-items: center;
    padding: 0.4rem 0.5rem;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 4px;
    font-size: 0.8rem;
}

.timeline-item .turn-number {
    width: 30px;
    font-weight: 600;
    color: var(--secondary-color);
}

.timeline-item .turn-player {
    flex: 1;
    font-weight: 500;
}

.timeline-item .turn-details {
    text-align: right;
    font-size: 0.75rem;
    color: var(--secondary-color);
}

/* Heatmap */
.heatmap-container {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-width: 240px;
    /* Fits within 280px panel with 40px padding */
}

.heatmap-grid {
    display: grid;
    grid-template-columns: 24px repeat(6, 28px);
    /* Fixed sizes to fit in container */
    gap: 2px;
    font-size: 0.65rem;
    justify-content: start;
}

.heatmap-cell {
    aspect-ratio: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 4px;
    font-weight: 500;
    transition: background-color 0.3s;
}

.heatmap-cell.header {
    background: transparent;
    color: var(--secondary-color);
    font-weight: 600;
}

.heatmap-cell.label {
    background: transparent;
    color: var(--secondary-color);
    font-weight: 600;
}

.heatmap-cell.data {
    background: rgba(59, 130, 246, 0.1);
    color: var(--text-color);
}

/* Heatmap color scale: blue (cold) to red (hot) */
.heatmap-cell.heat-0 {
    background: rgba(59, 130, 246, 0.1);
}

.heatmap-cell.heat-1 {
    background: rgba(59, 130, 246, 0.3);
}

.heatmap-cell.heat-2 {
    background: rgba(59, 130, 246, 0.5);
}

.heatmap-cell.heat-3 {
    background: rgba(16, 185, 129, 0.4);
}

.heatmap-cell.heat-4 {
    background: rgba(245, 158, 11, 0.4);
}

.heatmap-cell.heat-5 {
    background: rgba(239, 68, 68, 0.4);
    color: white;
}

.heatmap-cell.heat-6 {
    background: rgba(239, 68, 68, 0.7);
    color: white;
}

.heatmap-legend {
    display: flex;
    justify-content: space-between;
    font-size: 0.7rem;
    color: var(--secondary-color);
    padding: 0 0.25rem;
}

/* Analytics Actions */
.analytics-actions {
    padding: 0.5rem 0;
    border-top: 1px solid var(--border-color);
    margin-top: 1rem;
}

.analytics-actions button {
    width: 100%;
}

/* Analytics Toggle Button */
.analytics-toggle-btn {
    position: fixed;
    top: 50%;
    left: 0;
    transform: translateY(-50%);
    background: var(--surface-color);
    border: 2px solid var(--primary-color);
    border-left: none;
    border-radius: 0 8px 8px 0;
    padding: 0.75rem 0.5rem;
    font-size: 1.25rem;
    cursor: pointer;
    z-index: 85;
    transition: background 0.2s, transform 0.2s;
}

.analytics-toggle-btn:hover {
    background: rgba(59, 130, 246, 0.2);
    transform: translateY(-50%) scale(1.05);
}

.analytics-toggle-btn.hidden {
    display: none;
}

/* Analytics panel flash on event */
.analytics-panel.event-flash {
    animation: analyticsFlash 0.5s ease-out;
}

@keyframes analyticsFlash {

    0%,
    100% {
        background: var(--surface-color);
    }

    50% {
        background: rgba(239, 68, 68, 0.3);
    }
}

/* ============================================
   Mobile Responsive Styles
   ============================================ */

/* Tablet and below */
@media (max-width: 768px) {
    .app-container {
        width: 100%;
        height: 100vh;
        border-radius: 0;
    }

    header {
        padding: 1rem;
    }

    header h1 {
        font-size: 1rem;
    }

    .timer-display {
        font-size: 1.25rem;
        padding: 0.2rem 0.5rem;
    }

    .game-area {
        padding: 1rem;
    }

    .die {
        width: 70px;
        height: 70px;
        font-size: 2rem;
    }

    .dice-container {
        gap: 1rem;
    }

    .controls-panel {
        padding: 1rem;
        max-height: 45vh;
    }

    .settings-content {
        grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
        gap: 1rem;
    }

    /* Analytics panel becomes full-width overlay on mobile */
    .analytics-panel {
        width: 100vw !important;
        max-width: 100vw;
        min-width: unset;
    }

    .analytics-content {
        padding: 0.75rem;
    }

    .leaderboard-item .player-stats {
        font-size: 0.65rem;
    }

    /* Debug console smaller on mobile */
    .debug-console {
        width: 280px;
        max-height: 300px;
    }

    .debug-console.collapsed {
        width: 36px;
    }

    /* Modal full-width on mobile */
    .modal-content {
        width: 95%;
        max-width: 95%;
        max-height: 90vh;
    }

    /* Stack modal columns vertically on tablet */
    .modal-body-columns {
        flex-direction: column;
        gap: 1rem;
    }

    .player-config-section {
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        padding-right: 0.5rem;
        padding-bottom: 1rem;
        max-height: 35vh;
    }

    .event-definitions-section {
        max-height: 35vh;
    }

    /* Stack footer buttons on mobile */
    .modal-footer {
        flex-direction: column;
        gap: 0.75rem;
    }

    .save-button-group {
        width: 100%;
    }

    .save-button-group .primary-btn {
        flex: 1;
    }
}

/* Mobile phones */
@media (max-width: 480px) {
    header {
        padding: 0.75rem;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    header h1 {
        font-size: 0.9rem;
        flex: 1;
    }

    .home-btn {
        font-size: 1.25rem;
    }

    .die {
        width: 55px;
        height: 55px;
        font-size: 1.5rem;
        border-radius: 12px;
    }

    .dice-container {
        gap: 0.75rem;
    }

    .controls-panel {
        padding: 0.75rem;
    }

    .settings-content {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }

    .action-buttons {
        flex-direction: column;
        gap: 0.5rem;
    }

    .primary-btn,
    .secondary-btn {
        width: 100%;
        padding: 0.625rem 1rem;
    }

    .alert-message {
        font-size: 1rem;
        padding: 0.4rem 1rem;
    }

    /* Heatmap smaller on mobile */
    .heatmap-container {
        max-width: 220px;
    }

    .heatmap-grid {
        grid-template-columns: 24px repeat(6, 28px);
        font-size: 0.65rem;
    }

    .heatmap-cell {
        border-radius: 3px;
    }

    .timeline-item {
        font-size: 0.75rem;
        padding: 0.3rem 0.4rem;
    }

    .leaderboard-item {
        font-size: 0.8rem;
        padding: 0.4rem;
    }

    /* Hide debug toggle on very small screens */
    .debug-console {
        display: none;
    }
}

/* Timer Visibility Toggle */
.timer-container {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

#toggle-timer-visibility {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--secondary-color);
    padding: 0.25rem;
    transition: transform 0.2s ease, color 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

#toggle-timer-visibility:hover {
    transform: scale(1.1);
    color: var(--text-color);
}

.timer-display.hidden-text {
    visibility: hidden; /* Use visibility to keep layout space if desired, or display: none to collapse */
}

/* Ensure the container keeps its size/shape even when text is hidden to avoid layout jumping */
.timer-display {
    min-width: 80px;
    text-align: center;
    transition: opacity 0.3s ease;
}

.timer-display.hidden-text {
    visibility: visible;
    color: transparent;
    background: transparent;
    box-shadow: none;
}

/* Footer Styling */
.app-footer {
    text-align: center;
    padding: 1.5rem;
    margin-top: 2rem;
    color: var(--secondary-color);
    font-size: 0.85rem;
    border-top: 1px solid var(--border-color);
    width: 100%;
}