:root {
    /* Light Theme (Default) - iOS Style */
    --bg-main: #F2F2F7;
    --bg-container: #FFFFFF;
    --bg-board: #E5E5EA;
    --bg-cell: #FFFFFF;
    --bg-piece-wrapper: #F2F2F7;
    --bg-score-board: #F2F2F7;
    --bg-game-over: rgba(0, 0, 0, 0.4);

    --text-primary: #000000;
    --text-secondary: #6B6B70;
    --text-on-accent: #FFFFFF;
    --text-accent: #007AFF;
    
    --accent-color: #007AFF; /* iOS Blue */
    --accent-hover: #0056b3;
    --filled-cell-color: #007AFF;
    --filled-cell-shadow: none;
    --preview-color: rgba(0, 122, 255, 0.25);
    --invalid-color: rgba(255, 59, 48, 0.3); /* iOS Red */

    --shadow-color: rgba(0, 0, 0, 0.1);
    --container-shadow: 0 8px 32px var(--shadow-color);
    --button-shadow: 0 2px 5px var(--shadow-color);
    
    --toggle-bg-off: #E9E9EB;
    --toggle-bg-on: #34C759; /* iOS Green */
    --toggle-handle-color: #FFFFFF;
}

body.dark-theme {
    /* Dark Theme - Premium Black/White/Gray */
    --bg-main: #000000;
    --bg-container: #1C1C1E; /* iOS Dark Gray */
    --bg-board: #2C2C2E;
    --bg-cell: #3A3A3C;
    --bg-piece-wrapper: #2C2C2E;
    --bg-score-board: #2C2C2E;
    --bg-game-over: rgba(0, 0, 0, 0.7);

    --text-primary: #FFFFFF;
    --text-secondary: #8E8E93;
    --text-on-accent: #FFFFFF;
    --text-accent: #0A84FF;

    --accent-color: #0A84FF; /* iOS Blue (Dark) */
    --accent-hover: #409CFF;
    --filled-cell-color: #0A84FF;
    --filled-cell-shadow: none;
    --preview-color: rgba(10, 132, 255, 0.35);
    --invalid-color: rgba(255, 69, 58, 0.4); /* iOS Red (Dark) */

    --shadow-color: rgba(0, 0, 0, 0.5);
    --container-shadow: 0 8px 32px var(--shadow-color);
    --button-shadow: none;

    --toggle-bg-off: #2C2C2E;
    --toggle-bg-on: #30D158; /* iOS Green (Dark) */
    --toggle-handle-color: #FFFFFF;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", "Arial", sans-serif;
    background: var(--bg-main);
    color: var(--text-primary);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
    transition: background 0.3s, color 0.3s;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.game-container {
    background: var(--bg-container);
    border-radius: 24px;
    padding: 24px;
    box-shadow: var(--container-shadow);
    max-width: 420px;
    width: 100%;
    transition: background 0.3s, box-shadow 0.3s;
}

.header { text-align: center; margin-bottom: 20px; }
h1 { color: var(--text-accent); font-size: 28px; font-weight: 700; user-select: none; }

.score-board {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
    margin-bottom: 20px;
    padding: 15px;
    background: var(--bg-score-board);
    border-radius: 12px;
    transition: background 0.3s;
}
.score-item { text-align: center; }
.score-label { font-size: 13px; color: var(--text-secondary); margin-bottom: 4px; font-weight: 500; user-select: none; }
.score-value { font-size: 22px; font-weight: 600; color: var(--text-primary); transition: color 0.3s; }
#global-rank, #percentile { color: var(--accent-color); }

.game-board {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 4px;
    background: var(--bg-board);
    padding: 8px;
    border-radius: 16px;
    margin: 0 auto 24px;
    aspect-ratio: 1;
    touch-action: none;
}
.cell { background: var(--bg-cell); border-radius: 6px; transition: all 0.2s; }
.cell.filled { background: var(--filled-cell-color); box-shadow: var(--filled-cell-shadow); }
.cell.preview { background: var(--preview-color); }
.cell.invalid { background: var(--invalid-color); }
.cell.clearing { animation: clearAnimation 0.5s ease-out; }

@keyframes clearAnimation {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.2); background: #FFD60A; opacity: 0.8; }
    100% { transform: scale(0); opacity: 0; }
}

.pieces-container { display: flex; justify-content: space-around; gap: 10px; margin-bottom: 24px; min-height: 80px; align-items: center; }
.piece-wrapper {
    padding: 8px;
    border-radius: 10px;
    cursor: grab;
    transition: all 0.2s ease-out;
    user-select: none;
    touch-action: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-piece-wrapper);
}
.piece-wrapper:hover:not(.used) { transform: translateY(-5px); }
.piece-wrapper:active:not(.used) { cursor: grabbing; transform: scale(1.1); }
.piece-wrapper.dragging { opacity: 0.3; }
.piece-wrapper.used { opacity: 0.3; pointer-events: none; }
.piece { display: grid; gap: 3px; pointer-events: none; }
.piece-cell { width: 18px; height: 18px; background: transparent; border-radius: 4px; }
.piece-cell.filled { background: var(--filled-cell-color); }

.drag-ghost { position: fixed; pointer-events: none; z-index: 1000; opacity: 0.95; left: 0; top: 0; padding: 8px; border-radius: 10px; background: var(--bg-container); box-shadow: 0 10px 30px rgba(0,0,0,0.3); }

.buttons { display: flex; gap: 12px; justify-content: center; margin-bottom: 20px;}
button { padding: 14px 20px; font-size: 17px; border: none; border-radius: 12px; cursor: pointer; font-weight: 600; transition: all 0.2s; flex-grow: 1; }
.btn-new-game { background: var(--accent-color); color: var(--text-on-accent); box-shadow: var(--button-shadow); }
.btn-new-game:hover { background: var(--accent-hover); }
#sound-btn { background: var(--bg-score-board); color: var(--text-primary); }
#sound-btn.muted { background: #FF3B30; color: white;}

.settings { padding: 10px; background: var(--bg-score-board); border-radius: 12px; display: flex; flex-direction: column; gap: 10px; }
.setting-row { display: flex; justify-content: space-between; align-items: center; padding: 6px 10px; }
.setting-label { font-size: 15px; color: var(--text-primary); }
.toggle-switch { position: relative; display: inline-block; width: 51px; height: 31px; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: var(--toggle-bg-off); transition: .3s; border-radius: 34px; }
.slider:before { position: absolute; content: ""; height: 27px; width: 27px; left: 2px; bottom: 2px; background-color: var(--toggle-handle-color); transition: .3s; border-radius: 50%; box-shadow: 0 1px 3px rgba(0,0,0,0.2); }
input:checked + .slider { background-color: var(--toggle-bg-on); }
input:checked + .slider:before { transform: translateX(20px); }

.game-over { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: var(--bg-game-over); justify-content: center; align-items: center; z-index: 1000; backdrop-filter: blur(5px); }
.game-over-content { background: var(--bg-container); padding: 30px 40px; border-radius: 20px; text-align: center; animation: slideIn 0.4s cubic-bezier(0.25, 0.8, 0.25, 1); }
@keyframes slideIn { from { transform: translateY(-50px) scale(0.9); opacity: 0; } to { transform: translateY(0) scale(1); opacity: 1; } }
.game-over h2 { color: var(--text-accent); margin-bottom: 15px; font-size: 28px; }
.game-over p { font-size: 20px; margin-bottom: 15px; color: var(--text-primary); }
.rank-display { font-size: 18px; color: var(--accent-color); font-weight: 600; margin-bottom: 20px; }

.share-buttons {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    flex-wrap: wrap;
    justify-content: center;
}

.btn-share {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    font-size: 15px;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
    flex: 1;
    min-width: 160px;
    justify-content: center;
}

.btn-twitter {
    background: #1DA1F2;
    color: white;
}

.btn-twitter:hover {
    background: #1a8cd8;
    transform: translateY(-2px);
}

.btn-copy {
    background: var(--bg-score-board);
    color: var(--text-primary);
    border: 2px solid var(--accent-color);
}

.btn-copy:hover {
    background: var(--accent-color);
    color: var(--text-on-accent);
    transform: translateY(-2px);
}

.btn-copy.copied {
    background: #34C759;
    color: white;
    border-color: #34C759;
}

@media (max-width: 400px) {
    .share-buttons {
        flex-direction: column;
    }
    
    .btn-share {
        min-width: 100%;
    }
}

.combo-indicator { position: fixed; top: 25%; left: 50%; transform: translate(-50%, -50%); font-size: 48px; font-weight: bold; color: #FFD60A; text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5); pointer-events: none; animation: comboAnimation 1s ease-out; z-index: 999; display: none; }
@keyframes comboAnimation { 0% { transform: translate(-50%, -50%) scale(0); opacity: 0; } 50% { transform: translate(-50%, -50%) scale(1.2); opacity: 1; } 100% { transform: translate(-50%, -100%) scale(1); opacity: 0; } }

@media (max-width: 400px) {
    .game-container { padding: 15px; }
    .game-container h1 { font-size: 24px; }
    .piece-cell { width: 16px; height: 16px; }
    .game-board { gap: 3px; padding: 5px; border-radius: 12px;}
    .score-value { font-size: 20px; }
}

/* SEO Content Styles */
.seo-content {
    max-width: 800px;
    margin: 40px auto;
    padding: 30px;
    background: var(--bg-container);
    border-radius: 24px;
    box-shadow: var(--container-shadow);
    color: var(--text-primary);
    line-height: 1.8;
    transition: background 0.3s, box-shadow 0.3s, color 0.3s;
}

.seo-content h1 {
    color: var(--text-accent);
    font-size: 36px;
    font-weight: 700;
    margin: 30px 0;
    text-align: center;
    line-height: 1.3;
}

.seo-content h2 {
    color: var(--text-accent);
    font-size: 28px;
    font-weight: 700;
    margin: 25px 0 20px 0;
    line-height: 1.3;
}

.seo-content h3 {
    color: var(--text-accent);
    font-size: 22px;
    font-weight: 600;
    margin: 20px 0 15px 0;
}

.seo-content h4 {
    color: var(--accent-color);
    font-size: 18px;
    font-weight: 600;
    margin: 18px 0 12px 0;
}

.content-section {
    margin-bottom: 30px;
}

.content-section p {
    color: var(--text-primary);
    font-size: 16px;
    margin-bottom: 15px;
}

.intro-text {
    font-size: 17px;
    text-align: center;
    color: var(--text-secondary);
    padding: 20px 0;
}

.content-section ul,
.content-section ol {
    margin-left: 20px;
    margin-bottom: 15px;
}

.content-section li {
    color: var(--text-primary);
    font-size: 16px;
    margin-bottom: 12px;
    padding-left: 8px;
}

.content-section li strong {
    color: var(--text-accent);
}

.content-section a {
    color: var(--accent-color);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s;
}

.content-section a:hover {
    color: var(--accent-hover);
    text-decoration: underline;
}

.features-list {
    list-style: none;
    margin-left: 0;
    padding-left: 0;
}

.features-list li {
    background: var(--bg-score-board);
    padding: 15px;
    border-radius: 12px;
    margin-bottom: 15px;
    transition: transform 0.2s, background 0.3s;
}

.features-list li:hover {
    transform: translateX(5px);
}

@media (max-width: 768px) {
    .seo-content {
        margin: 20px;
        padding: 20px;
    }

    .seo-content h1 {
        font-size: 28px;
    }

    .seo-content h2 {
        font-size: 24px;
    }

    .seo-content h3 {
        font-size: 20px;
    }

    .seo-content h4 {
        font-size: 17px;
    }

    .content-section p,
    .content-section li {
        font-size: 15px;
    }
}

@media (max-width: 400px) {
    .seo-content {
        padding: 15px;
        margin: 15px;
    }

    .seo-content h1 {
        font-size: 24px;
    }

    .seo-content h2 {
        font-size: 22px;
    }

    .seo-content h3 {
        font-size: 18px;
    }

    .seo-content h4 {
        font-size: 16px;
    }
}
