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

body {
    font-family: 'Arial', 'Hiragino Kaku Gothic Pro', 'Meiryo', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
    color: #333;
    transition: background 0.5s ease;
}

/* Daily theme - Pink/Red gradient */
body.daily-theme {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}

/* Random theme - Green/Teal gradient */
body.random-theme {
    background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
}

.container {
    max-width: 900px;
    margin: 0 auto;
    background: white;
    border-radius: 15px;
    padding: 30px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.3);
}

h1 {
    text-align: center;
    color: #f5576c;
    margin-bottom: 10px;
    font-size: 2.5em;
    transition: color 0.3s ease;
    position: relative;
}

body.daily-theme h1 {
    color: #f5576c;
}

body.random-theme h1 {
    color: #11998e;
}

.help-button {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #667eea;
    color: white;
    border: none;
    font-size: 1.5em;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
    z-index: 100;
}

.help-button:hover {
    background: #5568d3;
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.5);
}

.help-button:active {
    transform: scale(0.95);
}

body.daily-theme .help-button {
    background: #f5576c;
    box-shadow: 0 2px 8px rgba(245, 87, 108, 0.3);
}

body.daily-theme .help-button:hover {
    background: #e04656;
    box-shadow: 0 4px 12px rgba(245, 87, 108, 0.5);
}

body.random-theme .help-button {
    background: #11998e;
    box-shadow: 0 2px 8px rgba(17, 153, 142, 0.3);
}

body.random-theme .help-button:hover {
    background: #0d7a6f;
    box-shadow: 0 4px 12px rgba(17, 153, 142, 0.5);
}

.subtitle {
    text-align: center;
    color: #666;
    margin-bottom: 25px;
    font-size: clamp(0.45em, 3vw, 1.1em);
}

.subtitle-main::after {
    content: '';
}

@media (max-width: 500px) {
    .subtitle-main::after {
        content: '\A';
        white-space: pre;
    }
}

.mode-selection {
    display: flex;
    gap: clamp(10px, 3vw, 20px);
    justify-content: center;
    flex-wrap: wrap;
    margin-bottom: 25px;
    padding-bottom: 20px;
    border-bottom: 2px solid #e0e0e0;
}

.mode-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.mode-button {
    padding: clamp(6px, 1.5vw, 10px) clamp(10px, 3vw, 20px);
    border: 2px solid #f5576c;
    background: white;
    color: #f5576c;
    border-radius: 8px;
    cursor: pointer;
    font-size: clamp(0.7em, 2.5vw, 1em);
    font-weight: bold;
    transition: all 0.3s;
}

.mode-description {
    font-size: clamp(0.65em, 2vw, 0.85em);
    color: #999;
    text-align: center;
}

.mode-button:hover {
    background: #f5576c;
    color: white;
    transform: translateY(-2px);
}

.mode-button.active {
    background: #f5576c;
    color: white;
}

body.random-theme .mode-button {
    border-color: #11998e;
    color: #11998e;
}

body.random-theme .mode-button:hover {
    background: #11998e;
    color: white;
}

body.random-theme .mode-button.active {
    background: #11998e;
    color: white;
}

.game-info {
    display: flex;
    justify-content: space-between;
    margin-bottom: 25px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 10px;
}

.info-item {
    text-align: center;
}

.info-label {
    font-size: 0.9em;
    color: #666;
    margin-bottom: 5px;
}

.info-value {
    font-size: 1.8em;
    font-weight: bold;
    color: #f5576c;
    font-family: 'Courier New', monospace;
    transition: color 0.3s ease;
}

body.random-theme .info-value {
    color: #11998e;
}

.problem-display {
    text-align: center;
    font-size: 2em;
    font-weight: bold;
    color: #333;
    padding: 25px;
    background: #f0f4ff;
    border-radius: 10px;
    margin-bottom: 25px;
    font-family: 'Courier New', monospace;
    letter-spacing: 5px;
    word-break: keep-all;
    white-space: nowrap;
    min-height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.problem-display .operator {
    font-size: 1.2em;
    vertical-align: middle;
    margin: 0 0.3em;
}

.input-area {
    background: #f8f9fa;
    padding: 25px;
    border-radius: 10px;
    margin-bottom: 20px;
}

.input-row {
    display: flex;
    gap: clamp(2px, 1.5vw, 10px);
    align-items: center;
    justify-content: center;
    margin-bottom: 15px;
    flex-wrap: nowrap;
}

.row-label {
    font-weight: bold;
    color: #f5576c;
    min-width: clamp(32px, 12vw, 80px);
    text-align: right;
    font-size: clamp(0.7em, 2.5vw, 1.1em);
    transition: color 0.3s ease;
}

body.random-theme .row-label {
    color: #11998e;
}

.operator-button, .paren-button {
    border: 2px solid;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
    font-family: 'Courier New', monospace;
}

.operator-button {
    width: clamp(40px, 10vw, 60px);
    height: clamp(40px, 10vw, 60px);
    font-size: clamp(1.8em, 5vw, 2.6em);
    border-radius: 50%;
    background: #f3e5f5;
    border-color: #9c27b0;
    color: #333;
    display: flex;
    align-items: center;
    justify-content: center;
}

.operator-button:hover {
    background: #e1bee7;
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(156, 39, 176, 0.3);
}

.paren-button {
    padding: clamp(4px, 2vw, 15px) clamp(3px, 3vw, 25px);
    border-radius: 8px;
    min-width: clamp(18px, 12vw, 80px);
    font-size: clamp(0.9em, 3.75vw, 1.95em);
}

@media (max-width: 768px) {
    .paren-button {
        flex: 1;
    }
}

.paren-button {
    background: #e8f5e9;
    border-color: #4caf50;
    color: #333;
}

.paren-button:hover {
    background: #c8e6c9;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(76, 175, 80, 0.3);
}

.paren-button.selected {
    background: #4caf50;
    color: white;
    border-width: 3px;
}

.keyboard-hints {
    text-align: center;
    padding: 15px;
    background: #fff;
    border: 2px dashed #ddd;
    border-radius: 8px;
    margin-top: 30px;
    margin-bottom: 20px;
}

.hint-line {
    margin: 5px 0;
    font-size: 0.95em;
    color: #666;
}

.hint-key {
    display: inline-block;
    padding: 2px 8px;
    background: #f0f0f0;
    border: 1px solid #ccc;
    border-radius: 4px;
    margin: 0 3px;
    font-family: 'Courier New', monospace;
    font-weight: bold;
}

.result-display {
    text-align: center;
    padding: clamp(10px, 3vw, 20px);
    border-radius: 10px;
    margin-bottom: 20px;
    font-size: clamp(0.65em, 3vw, 1.2em);
    font-weight: bold;
    min-height: clamp(50px, 10vw, 70px);
    display: flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
    overflow: hidden;
}

.result-display.correct {
    background: #c8e6c9;
    color: #2e7d32;
    border: 3px solid #4caf50;
}

.result-display.incorrect {
    background: #ffcdd2;
    color: #c62828;
    border: 3px solid #f44336;
}

.result-display.empty {
    background: #f5f5f5;
    color: #999;
    border: 2px dashed #ddd;
}

.action-buttons {
    display: flex;
    gap: clamp(5px, 2vw, 15px);
    justify-content: center;
    margin-top: 20px;
}

.action-button {
    padding: clamp(6px, 2vw, 12px) clamp(12px, 4vw, 30px);
    border: none;
    border-radius: 8px;
    font-size: clamp(0.65em, 2.5vw, 1.1em);
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s;
}

.action-button.primary {
    background: #4caf50;
    color: white;
}

.action-button.primary:hover {
    background: #45a049;
    transform: scale(1.05);
}

.action-button.secondary {
    background: #ff9800;
    color: white;
}

.action-button.secondary:hover {
    background: #fb8c00;
    transform: scale(1.05);
}

.action-button.danger {
    background: #f44336;
    color: white;
}

.action-button.danger:hover {
    background: #e53935;
    transform: scale(1.05);
}

.action-button:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
}

.history-section {
    margin-top: 30px;
    padding-top: 20px;
    border-top: 2px solid #e0e0e0;
}

.history-title {
    font-size: 1.3em;
    font-weight: bold;
    color: #667eea;
    margin-bottom: 15px;
    text-align: center;
}

.history-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 10px;
}

.history-item {
    padding: 10px;
    background: #f5f5f5;
    border-radius: 5px;
    text-align: center;
    font-size: 0.9em;
}

.history-item.correct {
    background: #c8e6c9;
    border-left: 4px solid #4caf50;
}

.history-item.incorrect {
    background: #ffcdd2;
    border-left: 4px solid #f44336;
}

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.7);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: white;
    padding: 40px;
    border-radius: 15px;
    text-align: center;
    max-width: 500px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.4);
}

.modal-content h2 {
    font-size: 2.5em;
    margin-bottom: 20px;
    color: #667eea;
    transition: color 0.3s ease;
}

body.daily-theme .modal-content h2 {
    color: #f5576c;
}

body.random-theme .modal-content h2 {
    color: #11998e;
}

.modal-content p {
    font-size: 1.3em;
    margin-bottom: 30px;
    color: #333;
}

.modal-button {
    padding: 15px 40px;
    font-size: 1.2em;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
    transition: all 0.3s;
}

body.daily-theme .modal-button {
    background: #f5576c;
}

body.daily-theme .modal-button:hover {
    background: #e04656;
}

body.random-theme .modal-button {
    background: #11998e;
}

body.random-theme .modal-button:hover {
    background: #0d7a6f;
}

.modal-button:hover {
    background: #5568d3;
    transform: scale(1.05);
}

@media (max-width: 768px) {
    h1 {
        font-size: 2em;
    }

    .problem-display {
        font-size: 2em;
        padding: 20px;
    }

    .input-cell {
        width: 40px;
        height: 50px;
        font-size: 1.5em;
    }

    .input-cell.operator {
        width: 35px;
    }

    .input-cell.paren {
        width: 25px;
    }

    .modal-button {
        padding: 10px 20px;
        font-size: 0.9em;
    }
}

/* Toast notification */
.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    background-color: #333;
    color: white;
    padding: 12px 24px;
    border-radius: 5px;
    font-size: 14px;
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 10000;
    pointer-events: none;
}

.toast.show {
    opacity: 1;
}

/* Flick picker */
.flick-picker {
    position: absolute;
    width: 200px;
    height: 200px;
    z-index: 10001;
    pointer-events: none;
}

.flick-picker.active {
    pointer-events: auto;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 50%;
}

.flick-option {
    position: absolute;
    width: 60px;
    height: 60px;
    background: #f3e5f5;
    border: 3px solid #9c27b0;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8em;
    font-weight: bold;
    font-family: 'Courier New', monospace;
    color: #333;
    cursor: pointer;
    transition: background 0.2s, box-shadow 0.2s;
}

.flick-option:hover {
    background: #e1bee7;
    box-shadow: 0 4px 12px rgba(156, 39, 176, 0.4);
}

.flick-top {
    left: 50%;
    top: 0;
    transform: translateX(-50%);
}

.flick-right {
    right: 0;
    top: 50%;
    transform: translateY(-50%);
}

.flick-bottom {
    left: 50%;
    bottom: 0;
    transform: translateX(-50%);
}

.flick-left {
    left: 0;
    top: 50%;
    transform: translateY(-50%);
}

/* Start game button */
.start-game-section {
    text-align: center;
    margin: 30px 0;
}

.start-game-button {
    padding: clamp(12px, 3vw, 20px) clamp(30px, 8vw, 60px);
    background: #4caf50;
    color: white;
    border: none;
    border-radius: 12px;
    font-size: clamp(1em, 4vw, 1.8em);
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 4px 12px rgba(76, 175, 80, 0.3);
}

.start-game-button:hover {
    background: #45a049;
    transform: scale(1.05);
    box-shadow: 0 6px 16px rgba(76, 175, 80, 0.4);
}

.start-game-button:active {
    transform: scale(0.98);
}

.start-game-section.hidden {
    display: none;
}

/* Tutorial overlay */
.tutorial-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 10000;
    pointer-events: none;
}

.tutorial-message {
    background: white;
    padding: 15px 25px;
    border-radius: 12px;
    font-size: clamp(0.85em, 2.5vw, 1.1em);
    font-weight: bold;
    color: #333;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
    max-width: 95%;
    width: fit-content;
    text-align: center;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, calc(-50% - 25vh));
    pointer-events: none;
    z-index: 10002;
}

.tutorial-highlight {
    animation: buttonPulse 1.5s ease-in-out infinite;
    position: relative;
    z-index: 10001;
}

@keyframes buttonPulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(76, 175, 80, 0.7);
    }
    50% {
        box-shadow: 0 0 0 10px rgba(76, 175, 80, 0);
    }
}
