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

html {
    height: 100%;
}

body {
    background: #0f172a;
    color: #ffffff;
    font-family: 'Roboto', sans-serif;
    padding: 0;
    margin: 0;
    min-height: 100%;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* Option Selector Modal (Pregame) */
.option-selector-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #0f172a;
    z-index: 2000;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 2rem 1rem 1rem 1rem;
    overflow: visible;
    box-sizing: border-box;
}

.option-selector-overlay.hidden {
    display: none;
}

.option-selector {
    text-align: center;
    padding: 2rem 2.5rem;
    background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
    border-radius: 1.5rem;
    border: 2px solid #334155;
    max-width: 450px;
    width: 90%;
    max-height: calc(100vh - 2rem);
    overflow: visible;
    box-sizing: border-box;
    box-shadow: none;
    backdrop-filter: blur(10px);
    margin: auto;
}

.modal-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 2rem;
}

.modal-logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.modal-logo img {
    height: 32px;
    width: auto;
    filter: brightness(0) invert(1);
}

.modal-logo h2 {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 700;
    color: #ffffff;
    font-family: 'Roboto', sans-serif;
}

.modal-logo .boxtext {
    color: #ffffff;
    font-weight: 300;
}

.modal-logo .logintext {
    color: #ffffff;
    font-weight: 300;
    font-size: 0.9em;
    margin-left: 0.25rem;
}

.modal-title {
    color: #ffffff;
    font-size: 2rem;
    font-weight: 700;
    margin: 0;
    font-family: 'Roboto', sans-serif;
}

.option-selector h3 {
    color: #ffffff;
    margin-bottom: 1.75rem;
    font-size: 1.25rem;
    font-weight: 400;
    letter-spacing: -0.025em;
}

.modal-form {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.form-group {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.75rem;
}

.step-number {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    background-color: #3b82f6;
    color: #ffffff;
    border-radius: 50%;
    font-size: 0.875rem;
    font-weight: 700;
    flex-shrink: 0;
}

.form-select {
    padding: 0.875rem 2.5rem 0.875rem 1rem;
    background-color: rgba(15, 23, 42, 0.7);
    border: 2px solid rgba(51, 65, 85, 0.5);
    border-radius: 0.5rem;
    color: #ffffff;
    font-size: 1rem;
    font-family: 'Roboto', sans-serif;
    cursor: pointer;
    transition: all 0.2s ease;
    flex: 1;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23ffffff' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    background-size: 12px;
}

.form-select:hover {
    border-color: rgba(59, 130, 246, 0.5);
    background-color: rgba(30, 41, 59, 0.8);
}

.form-select:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: none;
}

.form-select option {
    background-color: #1e293b;
    color: #e2e8f0;
    padding: 2rem 1.25rem;
    font-size: 1rem;
    font-family: 'Roboto', sans-serif;
}

.operations-toggle-group {
    display: flex;
    gap: 0.75rem;
    flex: 1;
}

.operation-toggle-btn {
    flex: 1;
    padding: 0.375rem 1rem;
    background-color: rgba(15, 23, 42, 0.7);
    border: 2px solid rgba(51, 65, 85, 0.5);
    border-radius: 0.5rem;
    color: #ffffff;
    font-size: 2rem;
    font-weight: 600;
    font-family: 'Roboto', sans-serif;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
    line-height: 1;
}

.operation-toggle-btn:hover {
    border-color: rgba(59, 130, 246, 0.5);
    background-color: rgba(30, 41, 59, 0.8);
}

.operation-toggle-btn.active {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    border-color: #3b82f6;
    color: #ffffff;
    box-shadow: none;
}

.timer-toggle-group {
    display: flex;
    gap: 0.75rem;
    flex: 1;
}

.timer-toggle-btn {
    flex: 1;
    padding: 0.875rem 1rem;
    background-color: rgba(15, 23, 42, 0.7);
    border: 2px solid rgba(51, 65, 85, 0.5);
    border-radius: 0.5rem;
    color: #ffffff;
    font-size: 1rem;
    font-weight: 600;
    font-family: 'Roboto', sans-serif;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
}

.timer-toggle-btn:hover {
    border-color: rgba(59, 130, 246, 0.5);
    background-color: rgba(30, 41, 59, 0.8);
}

.timer-toggle-btn.active {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    border-color: #3b82f6;
    color: #ffffff;
    box-shadow: none;
}

.start-button {
    width: 100%;
    padding: 1rem 2rem;
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    color: #ffffff;
    border: none;
    border-radius: 0.75rem;
    font-size: 1.125rem;
    font-weight: 600;
    font-family: 'Roboto', sans-serif;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-top: 0;
    box-shadow: none;
}

.start-button:hover {
    transform: translateY(-2px);
    box-shadow: none;
}

.start-button:active {
    transform: translateY(0);
}

.how-to-use-link {
    display: block;
    text-align: center;
    color: #9ca3af;
    font-size: 0.875rem;
    font-weight: 400;
    text-decoration: none;
    margin-top: 8px;
    transition: color 0.2s ease;
    cursor: pointer;
}

.how-to-use-link:hover {
    color: #6b7280;
    text-decoration: underline;
}

/* Game Container - exact viewport height so content fits on screen */
.game-container {
    margin: 0 auto;
    position: relative;
    height: 100vh;
    height: 100dvh;
    max-height: 100vh;
    max-height: 100dvh;
    display: none;
    flex-direction: column;
    padding: 1rem 1.5rem;
    box-sizing: border-box;
    overflow: hidden;
    width: 100%;
    max-width: none;
}

.game-container.active {
    display: flex;
}

/* Header */
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    flex-shrink: 0;
}

.game-header-actions {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

.logo-section {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    transition: opacity 0.2s;
}

.logo-section:hover {
    opacity: 0.8;
}

.logo-section img {
    height: 32px;
    width: auto;
    display: block;
    flex-shrink: 0;
    filter: brightness(0) invert(1);
}

.logo-section span {
    font-size: 1.5rem;
    font-weight: 700;
    color: #ffffff;
}

.logo-section .boxtext {
    font-weight: 300;
}

.settings-btn {
    background: transparent;
    border: 2px solid rgba(255, 255, 255, 0.3);
    color: #ffffff;
    padding: 0.5rem 0.75rem;
    border-radius: 0.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: all 0.2s;
    font-size: 0.875rem;
    font-weight: 500;
    text-decoration: none;
}

.change-settings-btn {
    background: transparent;
    border: 2px solid rgba(255, 255, 255, 0.3);
    color: #ffffff;
    padding: 0.75rem;
    border-radius: 0.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    width: 44px;
    height: 44px;
}

.change-settings-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.5);
}

.change-settings-btn img {
    width: 22px;
    height: 22px;
}

.new-question-top-btn {
    background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
    color: #000000;
    border: none;
    border-radius: 0.5rem;
    padding: 0.75rem 1.25rem;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-family: 'Roboto', sans-serif;
}

.new-question-top-btn:hover {
    transform: translateY(-2px);
}

.toggle-timer-btn {
    background: transparent;
    border: 2px solid rgba(255, 255, 255, 0.3);
    color: #ffffff;
    padding: 0.75rem 1.25rem;
    border-radius: 0.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    font-size: 1rem;
    font-weight: 500;
    font-family: 'Roboto', sans-serif;
    width: 122.84px;
    text-align: center;
}

.toggle-timer-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.5);
}

.toggle-timer-btn.active {
    background: rgba(59, 130, 246, 0.3);
    border-color: #3b82f6;
    color: #93c5fd;
}

.info-icon-btn {
    background: transparent;
    border: 2px solid rgba(255, 255, 255, 0.3);
    color: #ffffff;
    padding: 0.75rem;
    border-radius: 0.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    font-size: 1.5rem;
    font-weight: 600;
    font-family: 'Roboto', sans-serif;
    width: 44px;
    height: 44px;
    line-height: 1;
}

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

/* Rules Popup */
.rules-popup {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.rules-popup.active {
    display: flex;
}

.rules-content {
    background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
    border-radius: 1.5rem;
    padding: 2rem 2.5rem;
    max-width: 600px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    border: 2px solid #334155;
    position: relative;
}

.rules-header {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 1.5rem;
    position: relative;
}

.rules-title {
    font-size: 1.75rem;
    font-weight: 700;
    color: #ffffff;
    font-family: 'Roboto', sans-serif;
    text-align: center;
    margin: 0;
}

.rules-close-btn {
    position: absolute;
    right: 0;
}

.rules-close-btn {
    background: transparent;
    border: none;
    font-size: 2rem;
    color: #cbd5e1;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    transition: all 0.2s;
    line-height: 1;
}

.rules-close-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #ffffff;
}

.rules-text {
    color: #e2e8f0;
    font-size: 1.5rem;
    line-height: 1.8;
    font-family: 'Roboto', sans-serif;
    text-align: center;
}

.rules-text p {
    margin-bottom: 2rem;
}

.rules-text p:last-child {
    margin-bottom: 0;
}

.rules-text strong {
    font-size: 1.75rem;
    display: block;
    margin-bottom: 0.5rem;
    color: #3b82f6;
}

.operation-in-text {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    border: 2px solid #2563eb;
    border-radius: 0.5rem;
    font-size: 1.5rem;
    font-weight: 700;
    color: #ffffff;
    margin: 0 0.25rem;
    box-shadow: 0 2px 4px rgba(59, 130, 246, 0.3);
}

.settings-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.5);
}

.settings-btn svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    display: block;
    stroke: currentColor;
}

/* Main Game Area - fits viewport, uniform gap between all sections */
.game-area {
    display: flex;
    flex-direction: column;
    flex: 1 1 0;
    min-height: 0;
    max-height: calc(100vh - 6rem);
    max-height: calc(100dvh - 6rem);
    overflow: hidden;
    gap: clamp(0.75rem, 2.5vh, 2rem);
    align-items: center;
    width: 100%;
}

/* Target Number Section - never shrink so it always shows (fixes iPad) */
.target-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    flex-shrink: 0;
    min-height: 0;
    width: 100%;
    gap: 0.5rem;
}

.target-label {
    font-size: clamp(0.85rem, 1.8vw, 1.35rem);
    color: #ffffff;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-weight: 600;
    text-align: center;
}

.target-card {
    background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
    border-radius: clamp(0.6rem, 1.5vw, 1.5rem);
    padding: clamp(0.75rem, 2vw, 2rem) clamp(1.25rem, 3vw, 3rem);
    text-align: center;
    box-shadow: none;
    border: 2px solid rgba(255, 255, 255, 0.2);
}

.target-number {
    font-size: clamp(2.5rem, 8vw, 7rem);
    font-weight: 700;
    color: #111827;
    line-height: 1;
}

/* Source Numbers Section - proportional flex */
.source-numbers {
    display: flex;
    justify-content: center;
    gap: 0.75rem;
    flex-wrap: wrap;
    flex: 1.2 1 0;
    min-height: 0;
    width: 100%;
    max-width: 800px;
    align-content: center;
}

.source-card {
    background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
    border-radius: clamp(0.6rem, 1.2vw, 1rem);
    padding: clamp(0.6rem, 1.5vw, 1.5rem) clamp(0.9rem, 2vw, 2rem);
    text-align: center;
    box-shadow: none;
    border: 2px solid rgba(255, 255, 255, 0.2);
    transition: transform 0.2s, box-shadow 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    width: clamp(72px, 14vw, 140px);
    height: clamp(72px, 14vw, 140px);
    flex-shrink: 0;
}

.source-card:hover {
    transform: translateY(-4px);
    box-shadow: none;
}

.source-card.used {
    opacity: 0.4;
    filter: grayscale(100%);
}

.source-number {
    font-size: clamp(1.5rem, 4vw, 3.5rem);
    font-weight: 700;
    color: #111827;
    line-height: 1;
}

/* Working Grid Area - Whiteboard Style, proportional flex */
.working-grid {
    background: #ffffff;
    border-radius: clamp(0.5rem, 1vh, 1rem);
    flex: 4 1 0;
    min-height: 0;
    padding: 0 clamp(0.75rem, 2vh, 2rem);
    box-shadow: none;
    position: relative;
    overflow: hidden;
    border: 2px solid rgba(255, 255, 255, 0.2);
    max-width: 900px;
    margin: 0 auto;
    width: 100%;
    display: flex;
    gap: 0;
}

.grid-pattern {
    width: 100%;
    height: 100%;
    background-image: 
        repeating-linear-gradient(0deg, #e5e7eb 0px, #e5e7eb 1px, transparent 1px, transparent 50px),
        repeating-linear-gradient(90deg, #e5e7eb 0px, #e5e7eb 1px, transparent 1px, transparent 50px);
    background-size: 50px 50px;
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
    opacity: 0.6;
}

.working-area-main {
    flex: 0 0 65%;
    position: relative;
    z-index: 1;
    overflow: visible;
    padding: 0;
    min-height: 0;
}

.solutions-area {
    flex: 0 0 35%;
    background: transparent;
    border-left: none;
    position: relative;
    z-index: 1;
    padding: clamp(0.5rem, 1vh, 1rem) 0 0 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

.solutions-area-label {
    display: none;
}

.expression-display {
    position: relative;
    z-index: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: flex-start;
    gap: clamp(0.5rem, 1vh, 1rem);
    font-size: clamp(0.875rem, 2.2vh, 2.5rem);
    font-weight: 600;
    color: #111827;
    padding: clamp(0.5rem, 1.5vh, 2rem);
    padding-bottom: clamp(3rem, 6vh, 6rem);
}

.solutions-area .expression-display {
    min-height: 0;
    padding: 0;
    padding-bottom: 0;
    gap: clamp(0.25rem, 0.5vh, 0.5rem);
    width: 100%;
    flex: 1;
    overflow: auto;
    font-size: clamp(0.7rem, 1.5vh, 1.25rem);
}

.solutions-area .expression-display > div {
    margin-bottom: 0;
    width: 100%;
    line-height: 1.4;
    flex-shrink: 0;
}

.operations-display {
    position: absolute;
    bottom: clamp(0.25rem, 0.5vh, 0.5rem);
    left: clamp(0.75rem, 2vh, 2rem);
    display: flex;
    gap: clamp(0.5rem, 1vh, 1rem);
    z-index: 10;
    justify-content: flex-start;
    align-items: center;
    pointer-events: none;
}

.operations-display .operation-square {
    pointer-events: auto;
}

.operation-square {
    width: clamp(36px, 7vh, 70px);
    height: clamp(36px, 7vh, 70px);
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    border: 2px solid #2563eb;
    border-radius: clamp(0.375rem, 0.75vh, 0.75rem);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(1rem, 2.25vh, 2.25rem);
    font-weight: 700;
    color: #ffffff;
    box-shadow: 0 2px 4px rgba(59, 130, 246, 0.3);
    transition: all 0.2s ease;
}

.operation-square:hover {
    box-shadow: 0 4px 8px rgba(59, 130, 246, 0.4);
    background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
}

/* Bottom Actions - bigger buttons, less vertical gap */
.bottom-actions {
    display: flex;
    justify-content: center;
    gap: clamp(0.5rem, 1.5vw, 1rem);
    flex-wrap: wrap;
    flex: 0 0 auto;
    min-height: 0;
    margin: 0;
    padding: 0.2rem 0;
    align-items: center;
}

.action-btn {
    background: #ffffff;
    color: #111827;
    border: 2px solid #e5e7eb;
    border-radius: 0.6rem;
    padding: clamp(0.65rem, 1.5vw, 1.25rem) clamp(1.25rem, 2.5vw, 2.5rem);
    font-size: clamp(0.9rem, 1.8vw, 1.15rem);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: 'Roboto', sans-serif;
    white-space: nowrap;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
}

.action-btn.new-question {
    background: #ffffff;
    color: #111827;
    border: 2px solid #e5e7eb;
}

.action-btn.new-question:hover {
    background: #f9fafb;
    border-color: #d1d5db;
}

.action-btn:hover {
    background: #f9fafb;
    border-color: #d1d5db;
    transform: translateY(-1px);
}

.action-btn:active {
    transform: translateY(0);
}

.action-btn.secondary {
    background: #ffffff;
    color: #111827;
    border: 2px solid #e5e7eb;
}

.action-btn.secondary:hover {
    background: #f9fafb;
    border-color: #d1d5db;
}

.action-btn.operations {
    background: transparent;
    color: #ffffff;
    border: 2px solid #9ca3af;
    min-width: clamp(140px, 22vw, 200px);
}

.action-btn.operations:hover {
    background: rgba(156, 163, 175, 0.2);
    border-color: #6b7280;
    color: #ffffff;
}

.action-btn.hint {
    background: transparent;
    color: #ffffff;
    border: 2px solid #9ca3af;
}

.action-btn.hint:hover:not(:disabled) {
    background: rgba(156, 163, 175, 0.2);
    border-color: #6b7280;
    color: #ffffff;
}

.action-btn.hint:disabled {
    background: transparent;
    border-color: #6b7280;
    color: #9ca3af;
    opacity: 0.5;
    cursor: not-allowed;
}

.action-btn.solution {
    background: #3b82f6;
    color: #ffffff;
    border: 2px solid #3b82f6;
    min-width: clamp(120px, 18vw, 170px);
}

.action-btn.solution:hover:not(:disabled) {
    background: #2563eb;
    border-color: #2563eb;
}

.action-btn.solution.new-question {
    background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
    color: #000000;
    border: 2px solid #f59e0b;
    min-width: clamp(120px, 18vw, 170px);
}

.action-btn.solution.new-question:hover {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    border-color: #d97706;
}

/* Timer Display */
.timer-container {
    position: absolute;
    top: 5rem;
    right: 1rem;
    background: rgba(15, 23, 42, 0.95);
    padding: 1.5rem;
    border-radius: 0.75rem;
    display: none;
    border: 2px solid rgba(59, 130, 246, 0.3);
    box-shadow: none;
    min-width: 240px;
    z-index: 10;
}

.timer-container.active {
    display: block;
}

.timer-display-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 0;
    cursor: pointer;
    position: relative;
}

.timer-display {
    text-align: center;
    font-size: 4.5rem;
    font-weight: 700;
    color: #ffffff;
    font-variant-numeric: tabular-nums;
    min-width: 180px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.timer-play-icon {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 72px;
    height: 72px;
    background: rgba(34, 197, 94, 0.95);
    border: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s, transform 0.2s, background 0.2s;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.timer-play-icon.paused {
    background: rgba(34, 197, 94, 0.95); /* Green for play */
}

.timer-play-icon.playing {
    background: rgba(239, 68, 68, 0.95); /* Red for pause */
}

.timer-display:hover .timer-play-icon {
    opacity: 1;
}

.timer-play-icon svg {
    width: 36px;
    height: 36px;
    fill: #ffffff;
}

.timer-reset-link {
    display: block;
    text-align: center;
    color: #9ca3af;
    font-size: 0.875rem;
    text-decoration: none;
    margin-top: 0;
    transition: color 0.2s, opacity 0.2s;
    cursor: pointer;
    opacity: 0;
    pointer-events: none;
}

.timer-container:hover .timer-reset-link {
    opacity: 1;
    pointer-events: auto;
}

.timer-reset-link:hover {
    color: #ffffff;
    text-decoration: underline;
}

.timer-display.flash-red {
    animation: flashRed 0.5s infinite;
}

@keyframes flashRed {
    0%, 100% {
        color: #ef4444;
    }
    50% {
        color: #ffffff;
    }
}

.timer-adjust-btn {
    background: rgba(59, 130, 246, 0.2);
    border: 1px solid rgba(59, 130, 246, 0.4);
    color: #ffffff;
    padding: 0.5rem;
    border-radius: 0.5rem;
    font-size: 1.5rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
}

.timer-container:hover .timer-adjust-btn,
.timer-container.show-controls .timer-adjust-btn {
    opacity: 1;
    pointer-events: auto;
}

.timer-adjust-btn:hover {
    background: rgba(59, 130, 246, 0.4);
    border-color: rgba(59, 130, 246, 0.6);
}

.timer-controls {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
    max-height: 0;
    overflow: hidden;
}

.timer-container:hover .timer-controls,
.timer-container.show-controls .timer-controls {
    opacity: 1;
    pointer-events: auto;
    max-height: 100px;
    margin-top: 0.5rem;
}

.timer-btn {
    background: rgba(59, 130, 246, 0.2);
    border: 1px solid rgba(59, 130, 246, 0.4);
    color: #ffffff;
    padding: 0.5rem 0.75rem;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    flex: 1;
}

.timer-btn:hover {
    background: rgba(59, 130, 246, 0.4);
    border-color: rgba(59, 130, 246, 0.6);
}

.timer-btn:active {
    transform: scale(0.95);
}

.mobile-view-message {
    display: none;
}

/* Small screens: game stays visible, layout scales with viewport */
@media (max-width: 600px) {
    .game-container.active {
        padding: 0.5rem 0.75rem;
    }

    .game-area {
        gap: 0.4rem;
    }

    .target-label {
        font-size: clamp(0.7rem, 3.5vw, 1rem);
    }

    .target-card {
        padding: clamp(0.5rem, 2.5vw, 1rem) clamp(0.75rem, 4vw, 1.5rem);
    }

    .target-number {
        font-size: clamp(2rem, 12vw, 4rem);
    }

    .source-numbers {
        gap: 0.4rem;
        max-width: 100%;
    }

    .source-card {
        width: clamp(56px, 18vw, 90px);
        height: clamp(56px, 18vw, 90px);
        padding: clamp(0.4rem, 2vw, 0.75rem);
    }

    .source-number {
        font-size: clamp(1.25rem, 5vw, 2.25rem);
    }

    .working-grid {
        padding: 0 0.5rem;
    }

    .expression-display {
        font-size: clamp(0.75rem, 3.5vw, 1rem);
        padding: 0.5rem;
    }

    .bottom-actions {
        padding: 0.15rem 0;
        gap: 0.4rem;
    }

    .action-btn {
        padding: clamp(0.5rem, 2vw, 0.85rem) clamp(0.85rem, 4vw, 1.5rem);
        font-size: clamp(0.8rem, 3.2vw, 1rem);
    }

    .action-btn.operations {
        min-width: clamp(110px, 35vw, 160px);
    }

    .action-btn.solution,
    .action-btn.solution.new-question {
        min-width: clamp(100px, 30vw, 140px);
    }
}

/* Screens with height < 1000px: target-card proportional but readable */
@media (max-height: 1000px) {
    .target-card {
        width: clamp(72px, 14vw, 130px);
        min-width: clamp(72px, 14vw, 130px);
        height: clamp(72px, 14vw, 130px);
        min-height: clamp(72px, 14vw, 130px);
        padding: clamp(0.5rem, 1.5vw, 1rem) clamp(0.9rem, 2vw, 1.5rem);
        display: flex;
        align-items: center;
        justify-content: center;
        box-sizing: border-box;
    }

    .target-number {
        font-size: clamp(1.75rem, 5vw, 4.5rem);
    }
}

@media (max-width: 768px) {
    .game-container {
        padding: 0.75rem;
    }

    .timer-container {
        top: 3rem;
        min-width: 180px;
        padding: 1rem;
    }

    .timer-display {
        font-size: 3rem;
        min-width: 140px;
    }

    .timer-play-icon {
        width: 56px;
        height: 56px;
    }

    .timer-play-icon svg {
        width: 28px;
        height: 28px;
    }

    .target-number {
        font-size: clamp(2rem, 6vh, 5rem);
    }

    .target-card {
        padding: clamp(0.5rem, 1.5vh, 2rem) clamp(1rem, 2.5vh, 2.5rem);
    }

    /* Tablet: larger source number cards and font; target-card same height */
    .source-card {
        width: clamp(90px, 16vh, 130px);
        height: clamp(90px, 16vh, 130px);
        padding: clamp(0.75rem, 1.5vh, 1.5rem);
    }

    .target-card {
        width: clamp(90px, 16vh, 130px);
        min-width: clamp(90px, 16vh, 130px);
        height: clamp(90px, 16vh, 130px);
        min-height: clamp(90px, 16vh, 130px);
        padding: clamp(0.4rem, 1vh, 1rem) clamp(0.75rem, 2vh, 1.5rem);
    }

    .source-number {
        font-size: clamp(2.25rem, 4.5vh, 3.5rem);
    }

    /* Tablet: same uniform gap */
    .game-area {
        gap: 0.75rem;
    }

    .working-grid {
        flex: 2 1 0;
    }

    .expression-display {
        font-size: clamp(0.875rem, 2.2vh, 2rem);
        padding: clamp(0.5rem, 1.5vh, 1.5rem);
    }

    .expression-display.hints-3 {
        grid-template-columns: 1fr;
    }

    .expression-display.hints-5,
    .expression-display.hints-6-or-more {
        grid-template-columns: 1fr;
    }

    /* Tablet: bottom-actions bigger buttons, less vertical gap */
    .bottom-actions {
        flex: 0 0 auto;
        min-height: 0;
        margin: 0;
        gap: 0.5rem;
        padding: 0.2rem 0;
    }

    .action-btn {
        padding: clamp(0.6rem, 1.2vw, 1rem) clamp(1rem, 2vw, 2rem);
        font-size: clamp(0.85rem, 1.6vw, 1.05rem);
    }

    .action-btn.operations {
        min-width: clamp(130px, 22vw, 180px);
    }

    .action-btn.solution,
    .action-btn.solution.new-question {
        min-width: clamp(110px, 18vw, 150px);
    }

    .option-selector {
        padding: 1.5rem 1.5rem;
    }
}

/* iPad / tablet landscape: short viewport – taller working-grid, smaller gaps above it */
@media (max-height: 820px) {
    .game-area {
        gap: 0.35rem;
    }

    .target-section {
        flex: 0 0 auto;
        flex-shrink: 0;
        margin: 0;
        padding: 0;
    }

    .target-card {
        padding: clamp(0.4rem, 1.2vh, 1.25rem) clamp(0.75rem, 2vh, 2rem);
    }

    .target-number {
        font-size: clamp(1.75rem, 5vh, 5rem);
    }

    .source-numbers {
        flex: 0 0 auto;
        flex-shrink: 0;
        margin: 0;
        padding: 0;
        gap: 0.35rem;
    }

    .source-card {
        width: clamp(85px, 14vh, 120px);
        height: clamp(85px, 14vh, 120px);
    }

    .target-card {
        width: clamp(85px, 14vh, 120px);
        min-width: clamp(85px, 14vh, 120px);
        height: clamp(85px, 14vh, 120px);
        min-height: clamp(85px, 14vh, 120px);
        padding: clamp(0.35rem, 1vh, 0.9rem) clamp(0.6rem, 1.5vh, 1.25rem);
    }

    .source-number {
        font-size: clamp(2rem, 4.2vh, 3.5rem);
    }

    .working-grid {
        flex: 3 1 0;
        margin: 0;
        padding: 0 clamp(0.75rem, 2vh, 2rem);
        padding-bottom: 0;
    }

    .expression-display {
        padding: clamp(0.4rem, 1.2vh, 1.25rem);
        padding-bottom: clamp(0.75rem, 2vh, 2rem);
    }

    .bottom-actions {
        flex: 0 0 auto;
        margin: 0;
        padding: 0.15rem 0;
        gap: 0.35rem;
    }

    .action-btn {
        padding: clamp(0.5rem, 1.2vw, 0.75rem) clamp(0.85rem, 2vw, 1.25rem);
        font-size: clamp(0.8rem, 1.5vw, 0.95rem);
    }

    .action-btn.operations {
        min-width: clamp(120px, 20vw, 150px);
    }

    .action-btn.solution,
    .action-btn.solution.new-question {
        min-width: clamp(100px, 16vw, 130px);
    }
}

/* iPad landscape (768px height): pull bottom-actions up – same uniform gap */
@media (max-height: 768px) {
    .game-area {
        gap: 0.75rem;
    }

    .target-section {
        flex: 0 0 auto;
        flex-shrink: 0;
    }

    .working-grid {
        flex: 1.8 1 0;
        padding-bottom: 0;
    }

    .expression-display {
        padding: clamp(0.35rem, 1vh, 1rem);
        padding-bottom: clamp(0.75rem, 2vh, 2rem);
    }

    .operations-display {
        bottom: 0.2rem;
    }

    .bottom-actions {
        margin: 0;
        gap: 0.3rem;
        padding: 0.15rem 0;
    }

    .action-btn {
        padding: clamp(0.45rem, 1vw, 0.65rem) clamp(0.75rem, 1.8vw, 1.1rem);
        font-size: clamp(0.75rem, 1.4vw, 0.9rem);
    }

    .action-btn.operations {
        min-width: clamp(110px, 18vw, 130px);
    }

    .action-btn.solution,
    .action-btn.solution.new-question {
        min-width: clamp(90px, 14vw, 110px);
    }
}