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

body {
    background: #0f0f1a;
    color: #fff;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    min-height: 100vh;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 24px 16px;
}

.page-wrapper {
    display: flex;
    gap: 20px;
    align-items: flex-start;
}

/* ── Game container ────────────────────────── */
.game-container {
    position: relative;
    background: #16213e;
    border-radius: 16px;
    padding: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
    flex-shrink: 0;
}

/* ── Header ────────────────────────────────── */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    gap: 16px;
}

h1 {
    font-size: 1.6rem;
    color: #ff6b6b;
}

.subtitle {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.45);
    margin-top: 2px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.stat-box {
    background: #0f3460;
    border-radius: 10px;
    padding: 8px 16px;
    text-align: center;
    min-width: 80px;
    border: 1px solid rgba(255, 255, 255, 0.06);
}

.stat-label {
    font-size: 0.65rem;
    color: rgba(255, 255, 255, 0.55);
    display: block;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: #fff;
    display: block;
    line-height: 1.2;
}

#timer-box.danger .stat-value {
    color: #ff6b6b;
    animation: blink 0.6s infinite alternate;
}

@keyframes blink {
    from { opacity: 1; }
    to   { opacity: 0.4; }
}

.btn-new-game {
    background: #ff6b6b;
    color: #fff;
    border: none;
    border-radius: 10px;
    padding: 10px 18px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, transform 0.15s;
    white-space: nowrap;
}

.btn-new-game:hover {
    background: #ee5a24;
    transform: translateY(-1px);
}

/* ── Game area & grid ───────────────────────── */
.game-area {
    position: relative;
    display: inline-block;
    line-height: 0;
}

#game-grid {
    display: grid;
    grid-template-columns: repeat(17, 44px);
    grid-template-rows: repeat(10, 44px);
    gap: 5px;
    user-select: none;
}

/* ── Apple cells ────────────────────────────── */
.apple-cell {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 21px;
    font-weight: 900;
    cursor: crosshair;
    user-select: none;
    color: #fff;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
    position: relative;
    transition: transform 0.1s;
    overflow: visible;
}

/* Stem */
.apple-cell:not(.empty)::before {
    content: '';
    position: absolute;
    top: -9px;
    left: 50%;
    transform: translateX(-50%) rotate(10deg);
    width: 3px;
    height: 9px;
    background: #6d4c41;
    border-radius: 3px 3px 1px 1px;
    z-index: 2;
}

/* Leaf */
.apple-cell:not(.empty)::after {
    content: '';
    position: absolute;
    top: -12px;
    left: calc(50% + 2px);
    width: 12px;
    height: 7px;
    background: #4caf50;
    border-radius: 50%;
    transform: rotate(-40deg);
    transform-origin: left center;
    z-index: 1;
}

.apple-cell:not(.empty) {
    box-shadow: 0 3px 0 rgba(0, 0, 0, 0.3), 0 4px 8px rgba(0, 0, 0, 0.25);
}

.apple-cell.empty {
    background: transparent !important;
    box-shadow: none !important;
    cursor: default;
}

.apple-cell.selected {
    outline: 3px solid rgba(80, 160, 255, 0.9);
    outline-offset: 1px;
}

.apple-cell.valid {
    outline: 3px solid rgba(255, 60, 60, 0.95);
    outline-offset: 1px;
}

/* ── Selection overlay box ──────────────────── */
.selection-box {
    position: absolute;
    pointer-events: none;
    border-radius: 6px;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    font-weight: 800;
    transition: border-color 0.05s, background 0.05s;
}

.selection-box.hidden {
    display: none;
}

.selection-box.selecting {
    border: 3px solid rgba(80, 160, 255, 0.85);
    background: rgba(80, 160, 255, 0.08);
    color: rgba(100, 180, 255, 0.9);
}

.selection-box.valid {
    border: 3px solid rgba(255, 60, 60, 0.9);
    background: rgba(255, 60, 60, 0.12);
    color: rgba(255, 80, 80, 0.95);
}

/* ── Overlay (start / game over) ────────────── */
.overlay {
    position: absolute;
    inset: 0;
    background: rgba(10, 10, 22, 0.88);
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
    backdrop-filter: blur(6px);
}

.overlay.hidden {
    display: none;
}

.overlay-card {
    text-align: center;
    padding: 40px 48px;
}

.overlay-icon {
    font-size: 3.5rem;
    margin-bottom: 12px;
    line-height: 1;
}

#overlay-title {
    font-size: 2rem;
    margin-bottom: 8px;
    color: #ff6b6b;
}

#overlay-subtitle {
    color: rgba(255, 255, 255, 0.55);
    font-size: 0.9rem;
    margin-bottom: 28px;
}

.overlay-score {
    background: #0f3460;
    border-radius: 14px;
    padding: 20px 48px;
    margin-bottom: 28px;
    border: 1px solid rgba(255, 255, 255, 0.07);
}

.overlay-score.hidden {
    display: none;
}

.overlay-score-label {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.55);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 4px;
}

.overlay-score-value {
    font-size: 3.5rem;
    font-weight: 800;
    color: #ffd93d;
    line-height: 1;
}

.overlay-score-unit {
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.45);
    margin-top: 4px;
}

.btn-start {
    background: linear-gradient(135deg, #ff6b6b, #ee5a24);
    color: #fff;
    border: none;
    border-radius: 12px;
    padding: 14px 44px;
    font-size: 1.05rem;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
    box-shadow: 0 4px 18px rgba(238, 90, 36, 0.45);
}

.btn-start:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 24px rgba(238, 90, 36, 0.65);
}

/* ── Leaderboard panel ──────────────────────── */
.leaderboard-panel {
    background: #16213e;
    border-radius: 16px;
    padding: 20px;
    min-width: 220px;
    max-width: 260px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
    flex-shrink: 0;
}

.leaderboard-panel h2 {
    font-size: 1.1rem;
    color: #ffd93d;
    margin-bottom: 14px;
}

.score-entry {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: 8px;
    margin-bottom: 5px;
    background: rgba(255, 255, 255, 0.04);
    font-size: 0.9rem;
}

.score-entry.gold   { border-left: 3px solid gold;   background: rgba(255, 215, 0, 0.08); }
.score-entry.silver { border-left: 3px solid silver; background: rgba(192, 192, 192, 0.08); }
.score-entry.bronze { border-left: 3px solid #cd7f32; background: rgba(205, 127, 50, 0.08); }

.rank  { width: 22px; text-align: center; font-weight: 700; }
.name  { flex: 1; color: rgba(255, 255, 255, 0.8); }
.points { font-weight: 700; color: #ffd93d; }

.no-scores {
    color: rgba(255, 255, 255, 0.3);
    text-align: center;
    padding: 16px 0;
    font-size: 0.85rem;
}

/* ── Rules section ──────────────────────────── */
.rules {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.07);
}

.rules h3 {
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.55);
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.rules ul {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.rules li {
    font-size: 0.78rem;
    color: rgba(255, 255, 255, 0.45);
    padding-left: 14px;
    position: relative;
    line-height: 1.4;
}

.rules li::before {
    content: '▸';
    position: absolute;
    left: 0;
    color: #ff6b6b;
}

.rules strong {
    color: rgba(255, 255, 255, 0.75);
}

/* ── Home button ────────────────────────────── */
.btn-home {
    display: inline-block;
    color: rgba(255, 255, 255, 0.4);
    text-decoration: none;
    font-size: 0.8rem;
    padding: 2px 0;
    margin-bottom: 2px;
    transition: color 0.2s;
}

.btn-home:hover { color: rgba(255, 255, 255, 0.85); }

.header-left {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0;
}

/* ── Landing page ───────────────────────────── */
.landing-body {
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

.landing-container {
    text-align: center;
    max-width: 720px;
    width: 100%;
    padding: 0 16px;
}

.landing-header {
    margin-bottom: 52px;
}

.landing-icon {
    font-size: 4rem;
    line-height: 1;
    margin-bottom: 16px;
}

.landing-title {
    font-size: 2.4rem;
    color: #fff;
    margin-bottom: 10px;
}

.landing-subtitle {
    font-size: 1rem;
    color: rgba(255, 255, 255, 0.45);
}

.game-cards {
    display: flex;
    gap: 24px;
    justify-content: center;
    flex-wrap: wrap;
}

.game-card {
    background: #16213e;
    border-radius: 20px;
    padding: 32px 28px;
    width: 280px;
    text-align: left;
    text-decoration: none;
    color: #fff;
    display: flex;
    flex-direction: column;
    gap: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.06);
    transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
}

.game-card:hover {
    transform: translateY(-6px);
    box-shadow: 0 28px 70px rgba(0, 0, 0, 0.65);
}

.game-card-icon {
    font-size: 3.5rem;
    line-height: 1;
}

.game-card-info h2 {
    font-size: 1.35rem;
    margin-bottom: 8px;
}

.game-card-info p {
    font-size: 0.82rem;
    color: rgba(255, 255, 255, 0.48);
    line-height: 1.55;
    margin-bottom: 14px;
}

.game-card-tag {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    padding: 4px 12px;
    border-radius: 20px;
}

.apple-card .game-card-info h2 { color: #ff6b6b; }
.apple-card .game-card-tag {
    background: rgba(255, 107, 107, 0.15);
    color: #ff6b6b;
}
.apple-card:hover { border-color: rgba(255, 107, 107, 0.3); }

.shisen-card .game-card-info h2 { color: #ffd93d; }
.shisen-card .game-card-tag {
    background: rgba(255, 217, 61, 0.15);
    color: #ffd93d;
}
.shisen-card:hover { border-color: rgba(255, 217, 61, 0.3); }

.battle-card .game-card-info h2 { color: #a29bfe; }
.battle-card .game-card-tag {
    background: rgba(162, 155, 254, 0.15);
    color: #a29bfe;
}
.battle-card:hover { border-color: rgba(162, 155, 254, 0.3); }
