:root {
    --bg-main: #ffffff;
    --panel-bg: #ffffff;
    --pitch-grass-1: #327546;
    --pitch-grass-2: #2b673d;
    --pitch-line: rgba(255, 255, 255, 0.8);
    --grid-line: rgba(255, 255, 255, 0.5);
    --p1-color: #0b57d0;
    --p2-color: #b3261e;
    --highlight-move: rgba(255, 255, 255, 0.3);
    --highlight-pass: rgba(11, 87, 208, 0.5);
    --highlight-through: rgba(255, 171, 0, 0.5);
    --highlight-tackle: rgba(179, 38, 30, 0.5);
    --text-main: #1f1f1f;
    --text-muted: #5e5e5e;
    --border-color: #e0e0e0;
}

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

body {
    font-family: 'Noto Sans JP', -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    height: 100vh;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}

.app-container {
    display: flex;
    width: 100%;
    max-width: 1400px;
    height: 90vh;
    gap: 28px;
    padding: 24px;
}

/* Sidebar */
.sidebar {
    width: 340px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.brand-header {
    display: flex;
    flex-direction: column;
}

.logo {
    font-family: 'Chakra Petch', sans-serif;
    font-size: 1.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #1f1f1f;
    margin-bottom: 4px;
}

.system-text {
    font-family: 'Chakra Petch', monospace;
    font-size: 0.75rem;
    display: flex;
    gap: 8px;
}

.mode-select {
    background: transparent;
    border: 1px solid #c2c2c2;
    color: #5e5e5e;
    font-family: 'Chakra Petch', sans-serif;
    font-size: 0.75rem;
    font-weight: 700;
    border-radius: 4px;
    padding: 2px 4px;
    cursor: pointer;
    outline: none;
}
.mode-select:focus, .mode-select:hover {
    border-color: #1f1f1f;
    color: #1f1f1f;
}

.status-panel, .log-panel {
    background: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.03);
}

.turn-indicator {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
}

.turn-badge {
    flex: 1;
    text-align: center;
    padding: 10px;
    border-radius: 6px;
    font-weight: 700;
    font-size: 0.85rem;
    background: #f5f5f5;
    color: #9e9e9e;
    border: 1px solid transparent;
    transition: all 0.2s ease;
}

.turn-badge.active {
    color: white;
}

.turn-badge.active.p1-badge { 
    background: var(--p1-color); 
    box-shadow: 0 4px 12px rgba(11, 87, 208, 0.3);
}
.turn-badge.active.p2-badge { 
    background: var(--p2-color); 
    box-shadow: 0 4px 12px rgba(179, 38, 30, 0.3);
}

.ap-display {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.ap-dots {
    display: flex;
    gap: 8px;
}

.ap-dot {
    width: 24px;
    height: 8px;
    border-radius: 4px;
    background: #e0e0e0;
    transition: background 0.2s;
}

.ap-dot.active {
    background: #1f1f1f;
}

.game-info {
    font-size: 0.9rem;
    color: #424242;
    min-height: 4rem;
    line-height: 1.6;
    background: #f8f9fa;
    padding: 16px;
    border-radius: 8px;
    border: 1px solid #eeeeee;
}

.log-panel {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    font-size: 0.85rem;
    padding: 16px 16px 16px 32px;
    position: relative;
}

.log-entry {
    position: relative;
    padding: 10px 14px;
    border-radius: 8px;
    background: #ffffff;
    border: 1px solid #eeeeee;
    color: #424242;
    line-height: 1.4;
    box-shadow: 0 2px 8px rgba(0,0,0,0.02);
    display: flex;
    align-items: center;
    gap: 8px;
}

.log-entry::before {
    content: '';
    position: absolute;
    top: 50%; left: -21px;
    width: 10px; height: 10px;
    border-radius: 50%;
    transform: translateY(-50%);
    background: #bdbdbd;
    border: 2px solid var(--panel-bg);
    z-index: 2;
}

.log-entry::after {
    content: '';
    position: absolute;
    top: 50%; left: -17px;
    width: 2px;
    height: calc(100% + 12px);
    background: #e0e0e0;
    z-index: 1;
}
.log-entry:last-child::after { display: none; }

.log-entry.log-p1 { border-left: 3px solid var(--p1-color); }
.log-entry.log-p1::before { background: var(--p1-color); }

.log-entry.log-p2 { border-left: 3px solid var(--p2-color); }
.log-entry.log-p2::before { background: var(--p2-color); }

.log-entry.log-sys {
    background: #f8f9fa;
    border-color: #e0e0e0;
    font-weight: 600;
}
.log-entry.log-sys::before { background: #757575; }

.log-entry.log-gemini {
    border-left: 3px solid #8a2be2;
    background: linear-gradient(to right, rgba(138, 43, 226, 0.05), transparent);
    font-weight: 500;
}
.log-entry.log-gemini::before {
    background: #8a2be2;
    box-shadow: 0 0 8px #8a2be2;
}

.log-label {
    font-size: 0.8rem;
    font-weight: 800;
    font-family: var(--font-header);
    color: var(--text-dark);
    background: #e0e0e0;
    padding: 2px 6px;
    border-radius: 4px;
    margin-right: 6px;
    flex-shrink: 0;
    user-select: none;
}
.log-p1 .log-label { background: rgba(11, 87, 208, 0.1); color: var(--p1-color); }
.log-p2 .log-label { background: rgba(179, 38, 30, 0.1); color: var(--p2-color); }
.log-sys .log-label { background: #616161; color: #fff; }
.log-gemini .log-label { background: rgba(138, 43, 226, 0.15); color: #8a2be2; }

.log-text {
    flex: 1;
}

/* Tactical Button Hover Effect */
.btn {
    position: relative;
    display: block;
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: 8px;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.1s, background 0.2s;
    margin-top: 16px;
    font-size: 0.95rem;
    overflow: hidden;
}

.btn::before, .btn::after {
    content: '';
    position: absolute;
    width: 10px; height: 10px;
    border: 2px solid transparent;
    transition: border-color 0.2s, transform 0.2s;
    pointer-events: none;
}
.btn::before { top: 4px; left: 4px; border-right: none; border-bottom: none; transform: translate(-4px, -4px); }
.btn::after { bottom: 4px; right: 4px; border-left: none; border-top: none; transform: translate(4px, 4px); }

.btn:hover::before, .btn:hover::after {
    transform: translate(0, 0);
}

.btn.primary { background: #1f1f1f; color: #ffffff; }
.btn.primary:hover { background: #000000; transform: translateY(-1px); }
.btn.primary:hover::before, .btn.primary:hover::after { border-color: rgba(255,255,255,0.5); }

.btn.secondary { background: #e0e0e0; color: #1f1f1f; }
.btn.secondary:hover { background: #d5d5d5; }
.btn.secondary:hover::before, .btn.secondary:hover::after { border-color: rgba(0,0,0,0.3); }

.btn.outline { background: #ffffff; border: 1px solid #c2c2c2; color: #1f1f1f; }
.btn.outline:hover { background: #f5f5f5; }
.btn.outline:hover::before, .btn.outline:hover::after { border-color: rgba(0,0,0,0.3); }

.hidden {
    display: none !important;
}

/* Main Game Area */
.game-area {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
}

.pitch-container {
    position: relative;
    width: 800px;
    height: 571px; /* ratio 7:5 */
    background: repeating-linear-gradient(
        to right,
        var(--pitch-grass-1),
        var(--pitch-grass-1) 14.28%,
        var(--pitch-grass-2) 14.28%,
        var(--pitch-grass-2) 28.56%
    );
    border: 8px solid #ffffff;
    border-radius: 4px;
    box-shadow: 0 16px 40px rgba(0,0,0,0.15);
    overflow: visible; /* Changed for external goals */
}

/* Vignette Effect */
.pitch-container::after {
    content: '';
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: radial-gradient(circle, transparent 40%, rgba(0,0,0,0.5) 120%);
    mix-blend-mode: multiply;
    pointer-events: none;
    border-radius: 4px; /* Added to keep vignette clipped */
    z-index: 3;
}

/* Soccer Markings */
.pitch-markings {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    pointer-events: none;
    z-index: 1;
}

.center-line {
    position: absolute;
    top: 0; left: 50%;
    width: 3px; height: 100%;
    background: var(--pitch-line);
    transform: translateX(-50%);
}

.center-circle {
    position: absolute;
    top: 50%; left: 50%;
    width: 140px; height: 140px;
    border: 3px solid var(--pitch-line);
    border-radius: 50%;
    transform: translate(-50%, -50%);
}
.center-circle::after {
    content: '';
    position: absolute;
    top: 50%; left: 50%;
    width: 8px; height: 8px;
    background: var(--pitch-line);
    border-radius: 50%;
    transform: translate(-50%, -50%);
}

.penalty-area {
    position: absolute;
    top: 15%; height: 70%; width: 28.56%;
    border: 3px solid var(--pitch-line);
}
.penalty-area.left { left: 0; border-left: none; }
.penalty-area.right { right: 0; border-right: none; }

.goal-area {
    position: absolute;
    top: 30%; height: 40%; width: 14.28%;
    border: 3px solid var(--pitch-line);
}
.goal-area.left { left: 0; border-left: none; }
.goal-area.right { right: 0; border-right: none; }

/* External Goals */
.external-goal {
    position: absolute;
    top: 20%; height: 60%; width: 20px;
    border: 3px solid #ffffff;
    background: repeating-linear-gradient(45deg, transparent, transparent 4px, rgba(255,255,255,0.4) 4px, rgba(255,255,255,0.4) 8px);
    z-index: 0;
    box-shadow: inset 0 0 10px rgba(0,0,0,0.2);
}
.external-goal.p2-goal { left: -28px; border-right: none; border-radius: 8px 0 0 8px; }
.external-goal.p1-goal { right: -28px; border-left: none; border-radius: 0 8px 8px 0; }

.external-goal.finish-available {
    background: rgba(245, 158, 11, 0.5); /* #f59e0b */
    box-shadow: 0 0 15px rgba(245, 158, 11, 0.8), inset 0 0 20px rgba(245, 158, 11, 0.5);
    border-color: #f59e0b;
    cursor: pointer;
    animation: pulse-finish 1s infinite alternate;
    z-index: 4; /* Above vignette */
}
.external-goal.finish-available::after {
    content: 'TAP TO FINISH';
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    color: #fff;
    font-weight: 800;
    font-size: 0.85rem;
    white-space: nowrap;
    writing-mode: vertical-rl;
    text-shadow: 0 2px 4px rgba(0,0,0,0.8);
    pointer-events: none;
}
@keyframes pulse-finish {
    0% { opacity: 0.8; transform: scale(1); }
    100% { opacity: 1; transform: scale(1.05); }
}

/* Grid Cells overlay */
.pitch {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    grid-template-rows: repeat(5, 1fr);
    z-index: 2;
}

.cell {
    border: none;
    transition: background 0.15s;
    cursor: pointer;
    position: relative;
}

/* Dot marks at intersections instead of full borders */
.cell::after {
    content: '';
    position: absolute;
    bottom: -2px; right: -2px;
    width: 4px; height: 4px;
    background: var(--grid-line);
    border-radius: 50%;
    pointer-events: none;
}
.cell:nth-child(7n)::after { display: none; }
.cell:nth-last-child(-n+7)::after { display: none; }

.cell:hover {
    background: rgba(255, 255, 255, 0.15);
}

.cell.highlight-move { background: var(--highlight-move); }
.cell.highlight-pass { background: var(--highlight-pass); }
.cell.highlight-through { background: var(--highlight-through); }
.cell.highlight-tackle { background: var(--highlight-tackle); }
.cell.highlight-tackle-invalid { background: rgba(0, 0, 0, 0.5); cursor: not-allowed; }
.cell.highlight-danger-1 { background: rgba(245, 124, 0, 0.4); }
.cell.highlight-danger-2 { background: rgba(211, 47, 47, 0.4); }
.cell.goal-zone { background: rgba(255, 255, 255, 0.15); border: 1px dashed rgba(255,255,255,0.4); }
.cell.finish-zone {
    background: rgba(255, 255, 255, 0.08);
}

/* Ghost piece on hover */
.cell.highlight-move:hover::before, .cell.highlight-danger-1:hover::before, .cell.highlight-danger-2:hover::before {
    content: var(--piece-num);
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    width: 44px; height: 44px;
    border-radius: 50%;
    background: var(--active-color);
    border: 2px dashed #ffffff;
    opacity: 0.5;
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    font-family: 'Chakra Petch', sans-serif;
    font-weight: 700;
    font-size: 1.2rem;
    pointer-events: none;
    z-index: 15;
}

/* Offside warning */
.cell.offside-warning::after {
    content: "OFFSIDE";
    position: absolute;
    top: 6px; right: 6px;
    color: #ffffff;
    font-weight: 800;
    font-size: 0.65rem;
    background: #b3261e;
    padding: 2px 6px;
    border-radius: 4px;
    pointer-events: none;
    letter-spacing: 0.05em;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
    width: auto; height: auto; /* override grid dot sizes */
}

/* Pieces */
.pieces-layer {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    pointer-events: none;
    z-index: 10;
}

.piece {
    position: absolute;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    pointer-events: auto;
    cursor: pointer;
    transition: top 0.3s cubic-bezier(0.2, 0.8, 0.2, 1), 
                left 0.3s cubic-bezier(0.2, 0.8, 0.2, 1),
                transform 0.15s;
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    font-family: 'Chakra Petch', sans-serif;
    font-weight: 700;
    font-size: 1.2rem;
    box-shadow: 0 4px 8px rgba(0,0,0,0.3);
}

/* Directional Wedges */
.piece::before {
    content: '';
    position: absolute;
    width: 0; height: 0;
    border-top: 6px solid transparent;
    border-bottom: 6px solid transparent;
}
.piece.p1::before {
    right: -10px;
    border-left: 8px solid var(--p1-color);
    filter: drop-shadow(2px 0px 1px rgba(0,0,0,0.3));
}
.piece.p2::before {
    left: -10px;
    border-right: 8px solid var(--p2-color);
    filter: drop-shadow(-2px 0px 1px rgba(0,0,0,0.3));
}

.piece.p1 {
    background: var(--p1-color);
    border: 2px solid #ffffff;
}

.piece.p2 {
    background: var(--p2-color);
    border: 2px solid #ffffff;
}

.piece:hover {
    transform: translate(-50%, -50%) scale(1.08);
}

.piece.selected {
    transform: translate(-50%, -50%) scale(1.15);
    z-index: 20;
    box-shadow: 0 0 0 4px rgba(255,255,255,0.9), 0 8px 16px rgba(0,0,0,0.4);
}

/* Soccer Ball */
.piece .ball {
    width: 20px;
    height: 20px;
    background: #ffffff;
    border-radius: 50%;
    position: absolute;
    top: -8px;
    right: -8px;
    border: 1px solid #1f1f1f;
    z-index: 25;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 2px 6px rgba(0,0,0,0.4);
}
.piece .ball::after {
    content: '';
    width: 8px;
    height: 8px;
    background: #1f1f1f;
    clip-path: polygon(50% 0%, 100% 38%, 81% 100%, 19% 100%, 0% 38%);
    position: static; /* override cell dots */
}

/* Status Badges */
.status-badge {
    position: absolute;
    font-family: 'Chakra Petch', sans-serif;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 3px 6px;
    border-radius: 4px;
    color: white;
    pointer-events: none;
    white-space: nowrap;
    z-index: 30;
    letter-spacing: 0.05em;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}
.press-badge {
    bottom: -24px;
    left: 50%;
    transform: translateX(-50%);
    background: #f57c00;
}
.iso-badge {
    top: -24px;
    left: 50%;
    transform: translateX(-50%);
    background: #d32f2f;
}

/* Canvas for drawing lines (passes) */
.overlay-canvas {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    pointer-events: none;
    z-index: 5;
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    backdrop-filter: blur(3px);
}

.modal-content {
    background: var(--panel-bg);
    padding: 40px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    text-align: center;
    max-width: 450px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.15);
}

.modal-content h2 {
    font-size: 1.6rem;
    margin-bottom: 16px;
    color: #1f1f1f;
}

.modal-content p {
    color: var(--text-muted);
    margin-bottom: 32px;
}

/* Rules Modal Specific */
.rules-content {
    max-width: 650px;
    padding: 32px;
    text-align: left;
}
.rules-content h2 {
    text-align: center;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 16px;
}
.rules-text {
    max-height: 60vh;
    overflow-y: auto;
    padding-right: 16px;
    color: #424242;
    line-height: 1.7;
    font-size: 0.95rem;
}
.rules-text p {
    margin-bottom: 16px;
}
.rules-text hr {
    border: 0;
    height: 1px;
    background: var(--border-color);
    margin: 24px 0;
}

/* Labels */
.pitch-labels {
    position: absolute;
    display: flex;
    justify-content: space-around;
    align-items: center;
    color: rgba(255, 255, 255, 0.9);
    font-family: 'Chakra Petch', sans-serif;
    font-weight: 800;
    font-size: 1.15rem;
    text-shadow: 0 1px 4px rgba(0,0,0,0.8), 0 0 2px rgba(0,0,0,1);
    pointer-events: none;
    z-index: 4;
}
.pitch-labels.left {
    top: 0; left: 8px;
    width: 20px; height: 100%;
    flex-direction: column;
}
.pitch-labels.top {
    top: 8px; left: 0;
    width: 100%; height: 20px;
}

/* Helper classes for switching views */
.mobile-only {
    display: none !important;
}

.material-symbols-outlined.icon-inline {
    font-size: 1.2em;
    vertical-align: -0.2em;
    display: inline-block;
    line-height: 1;
}

.btn .material-symbols-outlined.icon-inline {
    margin-right: 4px;
}

/* ==========================================================================
   Online Matchmaking Styles
   ========================================================================== */

/* Keyframe for loading spinner */
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Glassmorphism style inside lobby content */
.lobby-content {
    background: rgba(18, 18, 18, 0.85) !important;
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.08) !important;
    color: #ffffff;
}

/* Override text color in dark mode lobby */
.lobby-content h2, 
.lobby-content h3 {
    color: #ffffff !important;
}

.lobby-content p {
    color: rgba(255, 255, 255, 0.6) !important;
}

/* Lobby Mode select buttons */
.lobby-btn {
    margin-top: 0 !important;
    font-size: 1rem !important;
    font-weight: 700 !important;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 52px;
}

/* Dividers inside lobby */
.lobby-divider {
    border: 0;
    border-top: 1px solid rgba(255, 255, 255, 0.1) !important;
    margin: 20px 0;
}

/* Role badge colors */
.role-badge.p1-badge {
    background: rgba(11, 87, 208, 0.2) !important;
    color: #00e5ff !important;
    border: 1px solid rgba(11, 87, 208, 0.4) !important;
}

.role-badge.p2-badge {
    background: rgba(179, 38, 30, 0.2) !important;
    color: #ff5252 !important;
    border: 1px solid rgba(179, 38, 30, 0.4) !important;
}

/* Status indicator panel in sidebar */
.online-status-panel {
    transition: all 0.3s ease;
}

/* Connection input state stylings */
#input-room-id:focus {
    outline: none;
    border-color: #00e5ff !important;
    box-shadow: 0 0 10px rgba(0, 229, 255, 0.2);
}

/* ==========================================================================
   Responsive Mobile Layouts
   ========================================================================== */

@media (max-width: 950px) {
    html {
        overflow: hidden !important;
        height: 100% !important;
    }

    body {
        overflow: hidden !important;
        height: 100dvh !important;
        min-height: 100dvh !important;
        display: flex !important;
        flex-direction: column;
        padding: 0 !important;
        background-color: var(--bg-main) !important;
    }

    .app-container {
        flex-direction: column !important;
        height: 100dvh !important;
        min-height: 100dvh !important;
        max-height: 100dvh !important;
        gap: 8px;
        padding: 8px;
        width: 100%;
        box-sizing: border-box;
        overflow: hidden;
    }

    .sidebar {
        display: none !important; /* Hide sidebar on mobile */
    }

    .game-area {
        flex: 1;
        min-height: 0;
        width: 100% !important;
        padding: 24px 0; /* Space for top/bottom goals */
        box-sizing: border-box;
        display: flex;
        justify-content: center;
        align-items: center;
        overflow: visible;
    }

    .pitch-container {
        width: 100% !important;
        max-width: min(calc(100vw - 24px), calc((100dvh - 270px) * 5 / 7)) !important;
        height: auto !important;
        aspect-ratio: 5 / 7 !important;
        margin: auto;
        background: repeating-linear-gradient(
            to bottom,
            var(--pitch-grass-1),
            var(--pitch-grass-1) 14.28%,
            var(--pitch-grass-2) 14.28%,
            var(--pitch-grass-2) 28.56%
        );
        border: 6px solid #ffffff;
        box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    }

    .pitch {
        grid-template-columns: repeat(5, 1fr) !important;
        grid-template-rows: repeat(7, 1fr) !important;
    }

    /* Switch coordinate labels for mobile */
    .desktop-only {
        display: none !important;
    }
    .mobile-only {
        display: flex !important;
    }
    
    .pitch-labels.mobile-only {
        position: absolute;
        display: flex;
        justify-content: space-around;
        align-items: center;
        color: rgba(255, 255, 255, 0.75);
        font-family: 'Chakra Petch', sans-serif;
        font-weight: 700;
        font-size: 0.85rem;
        text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
        pointer-events: none;
        z-index: 4;
    }
    
    .pitch-labels.left.mobile-only {
        top: 0;
        left: -22px;
        width: 16px;
        height: 100%;
        flex-direction: column;
    }
    
    .pitch-labels.top.mobile-only {
        top: -22px;
        left: 0;
        width: 100%;
        height: 16px;
    }

    /* Vertical Soccer Markings */
    .center-line {
        top: 50% !important;
        left: 0 !important;
        width: 100% !important;
        height: 3px !important;
        transform: translateY(-50%) !important;
    }

    .center-circle {
        width: 100px !important;
        height: 100px !important;
    }

    .penalty-area {
        left: 15% !important;
        width: 70% !important;
        height: 28.56% !important;
        right: auto !important;
        top: auto !important;
    }
    .penalty-area.left {
        top: 0 !important;
        border-top: none !important;
        border-left: 3px solid var(--pitch-line) !important;
        border-right: 3px solid var(--pitch-line) !important;
        border-bottom: 3px solid var(--pitch-line) !important;
    }
    .penalty-area.right {
        bottom: 0 !important;
        border-bottom: none !important;
        border-left: 3px solid var(--pitch-line) !important;
        border-right: 3px solid var(--pitch-line) !important;
        border-top: 3px solid var(--pitch-line) !important;
    }

    .goal-area {
        left: 30% !important;
        width: 40% !important;
        height: 14.28% !important;
        right: auto !important;
        top: auto !important;
    }
    .goal-area.left {
        top: 0 !important;
        border-top: none !important;
        border-left: 3px solid var(--pitch-line) !important;
        border-right: 3px solid var(--pitch-line) !important;
        border-bottom: 3px solid var(--pitch-line) !important;
    }
    .goal-area.right {
        bottom: 0 !important;
        border-bottom: none !important;
        border-left: 3px solid var(--pitch-line) !important;
        border-right: 3px solid var(--pitch-line) !important;
        border-top: 3px solid var(--pitch-line) !important;
    }

    /* External Goals (top & bottom) */
    .external-goal {
        left: 20% !important;
        width: 60% !important;
        height: 18px !important;
        right: auto !important;
        top: auto !important;
    }
    .external-goal.p2-goal {
        bottom: -24px !important;
        border-bottom: 3px solid #ffffff !important;
        border-top: none !important;
        border-left: 3px solid #ffffff !important;
        border-right: 3px solid #ffffff !important;
        border-radius: 0 0 8px 8px !important;
    }
    .external-goal.p1-goal {
        top: -24px !important;
        border-top: 3px solid #ffffff !important;
        border-bottom: none !important;
        border-left: 3px solid #ffffff !important;
        border-right: 3px solid #ffffff !important;
        border-radius: 8px 8px 0 0 !important;
    }
    
    .external-goal.finish-available {
        animation: pulse-finish-vertical 1s infinite alternate;
    }
    
    .external-goal.finish-available::after {
        writing-mode: horizontal-tb !important;
        font-size: 0.65rem !important;
        top: 50% !important;
        left: 50% !important;
        transform: translate(-50%, -50%) !important;
    }
    
    @keyframes pulse-finish-vertical {
        0% { opacity: 0.8; transform: translateY(0); }
        100% { opacity: 1; transform: translateY(2px); }
    }

    /* Scales pieces & markings down for small screen convenience */
    .piece {
        width: 38px !important;
        height: 38px !important;
        font-size: 1.1rem !important;
    }
    
    /* Directional Wedges for Vertical Layout */
    .piece::before {
        content: '' !important;
        position: absolute !important;
        width: 0 !important;
        height: 0 !important;
    }
    
    /* Blue piece points UP */
    .piece.p1::before {
        right: auto !important;
        left: 50% !important;
        top: -9px !important;
        transform: translateX(-50%) !important;
        border-left: 6px solid transparent !important;
        border-right: 6px solid transparent !important;
        border-bottom: 7px solid var(--p1-color) !important;
        border-top: none !important;
        filter: drop-shadow(0px -2px 1px rgba(0,0,0,0.3)) !important;
    }

    /* Red piece points DOWN */
    .piece.p2::before {
        left: 50% !important;
        bottom: -9px !important;
        top: auto !important;
        transform: translateX(-50%) !important;
        border-left: 6px solid transparent !important;
        border-right: 6px solid transparent !important;
        border-top: 7px solid var(--p2-color) !important;
        border-bottom: none !important;
        filter: drop-shadow(0px 2px 1px rgba(0,0,0,0.3)) !important;
    }

    .piece .ball {
        width: 16px !important;
        height: 16px !important;
        top: -6px !important;
        right: -6px !important;
    }
    
    .piece .ball::after {
        width: 6px !important;
        height: 6px !important;
    }
    
    .status-badge {
        font-size: 0.55rem !important;
        padding: 2px 4px !important;
    }
    
    .press-badge {
        bottom: -18px !important;
    }
    
    .iso-badge {
        top: -18px !important;
    }

    /* Mobile HUD and Footer Styles */
    .mobile-hud {
        display: flex !important;
    }
    .mobile-hud.hidden {
        display: none !important;
    }
    .mobile-footer {
        display: flex !important;
        padding-bottom: calc(8px + env(safe-area-inset-bottom)) !important;
    }
    .mobile-footer.hidden {
        display: none !important;
    }
    
    /* HUD buttons custom style */
    .btn-hud {
        padding: 6px 12px;
        border-radius: 6px;
        background: rgba(255,255,255,0.05) !important;
        transition: background 0.2s;
    }
    .btn-hud:hover, .btn-hud:active {
        background: rgba(255,255,255,0.15) !important;
    }

    /* HUD AP Glow Dot Style */
    .hud-ap-dot {
        font-size: 1.1rem;
        margin-left: 2px;
        vertical-align: middle;
        transition: all 0.3s ease;
    }
}

/* ==========================================================================
   Rules Modal Premium Tab Styling
   ========================================================================== */
#rules-modal .modal-content {
    background: rgba(18, 18, 18, 0.98) !important;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    color: #fff;
    max-width: 620px;
    width: 92%;
    padding: 24px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(20px);
}
#rules-modal h2 {
    color: #fff !important;
    margin-bottom: 16px;
    font-size: 1.5rem;
    font-family: var(--font-header);
    text-align: center;
    border-bottom: none;
    padding-bottom: 0;
}
.rules-tabs {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    margin-bottom: 20px;
}
.rules-tab-btn {
    flex: 1;
    padding: 12px 8px;
    background: transparent;
    border: none;
    border-bottom: 3px solid transparent;
    color: rgba(255, 255, 255, 0.5);
    font-weight: 700;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: 'Noto Sans JP', sans-serif;
}
.rules-tab-btn:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.03);
}
.rules-tab-btn.active {
    color: #00e5ff;
    border-bottom-color: #00e5ff;
    background: rgba(0, 229, 255, 0.05);
}
.rules-tab-content {
    display: none;
    max-height: 55vh;
    overflow-y: auto;
    padding-right: 8px;
    text-align: left;
}
.rules-tab-content.active {
    display: block;
}
.rules-tab-content::-webkit-scrollbar {
    width: 6px;
}
.rules-tab-content::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.02);
    border-radius: 4px;
}
.rules-tab-content::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 4px;
}
.rules-tab-content::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Rule Cards */
.rule-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 16px;
}
.rule-card h3 {
    font-size: 1.05rem;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 6px;
    font-family: var(--font-header);
    color: #fff !important;
}
.rule-card h3 .material-symbols-outlined {
    font-size: 1.25rem;
}
.rule-card p {
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.8) !important;
    line-height: 1.6;
    margin-bottom: 8px !important;
}
.rule-card p:last-child {
    margin-bottom: 0 !important;
}
.rule-card ul {
    padding-left: 20px;
    margin-bottom: 8px;
}
.rule-card li {
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.8);
    line-height: 1.6;
    margin-bottom: 6px;
}
.rule-card li:last-child {
    margin-bottom: 0;
}

/* Badges and Highlights */
.rule-badge-inline {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: bold;
    margin-left: 6px;
    vertical-align: middle;
    letter-spacing: 0.05em;
}
.badge-ap { background: rgba(0, 229, 255, 0.15); color: #00e5ff; border: 1px solid rgba(0, 229, 255, 0.3); }
.badge-free { background: rgba(16, 185, 129, 0.15); color: #10b981; border: 1px solid rgba(16, 185, 129, 0.3); }
.badge-danger { background: rgba(239, 68, 68, 0.15); color: #ef4444; border: 1px solid rgba(239, 68, 68, 0.3); }

.step-list {
    list-style: none;
    padding: 0;
}
.step-item {
    display: flex;
    gap: 12px;
    margin-bottom: 14px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.05);
    padding: 12px;
    border-radius: 8px;
}
.step-item:last-child {
    margin-bottom: 0;
}
.step-num {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #00e5ff;
    color: #0c0f12;
    font-weight: bold;
    font-family: 'Chakra Petch', sans-serif;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
}
.step-body {
    flex: 1;
}
.step-title {
    font-weight: bold;
    font-size: 0.95rem;
    margin-bottom: 6px;
    color: #fff;
}
.step-desc {
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.7);
    line-height: 1.6;
}
.rule-highlight {
    color: #f59e0b;
    font-weight: bold;
}
.rule-subtext {
    display: block;
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.5);
    margin-top: 4px;
}

/* ==========================================================================
   Replay Controls Panel Styling
   ========================================================================== */
#replay-controls {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    background: rgba(18, 18, 18, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 12px;
    padding: 10px 16px;
    display: flex;
    gap: 8px;
    align-items: center;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(10px);
    flex-wrap: nowrap;
    white-space: nowrap;
    box-sizing: border-box;
    max-width: 95vw;
}

#replay-controls .btn {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    gap: 4px;
    width: auto !important;
    margin: 0 !important;
    padding: 8px 12px !important;
    font-size: 0.8rem !important;
    height: 36px !important;
    border-radius: 6px !important;
    font-weight: 700 !important;
    cursor: pointer !important;
    transition: all 0.2s ease !important;
    flex-shrink: 0 !important;
}

#replay-controls .btn::before,
#replay-controls .btn::after {
    display: none !important; /* Remove tactical corner marks */
}

/* Outline button styling in replay panel */
#replay-controls .btn.outline {
    background: rgba(255, 255, 255, 0.08) !important;
    border: 1px solid rgba(255, 255, 255, 0.15) !important;
    color: #e0e0e0 !important;
}
#replay-controls .btn.outline:hover {
    background: rgba(255, 255, 255, 0.15) !important;
    border-color: rgba(255, 255, 255, 0.3) !important;
    color: #ffffff !important;
}

/* Primary/Play button styling in replay panel */
#replay-controls .btn.primary {
    background: linear-gradient(135deg, #0b57d0, #00e5ff) !important;
    border: none !important;
    color: #ffffff !important;
    box-shadow: 0 4px 12px rgba(0, 229, 255, 0.2) !important;
}
#replay-controls .btn.primary:hover {
    filter: brightness(1.1) !important;
    transform: translateY(-1px) !important;
}

/* Exit/Close button styling in replay panel */
#replay-controls #btn-replay-exit {
    background: rgba(239, 68, 68, 0.12) !important;
    border: 1px solid rgba(239, 68, 68, 0.3) !important;
    color: #ff5252 !important;
}
#replay-controls #btn-replay-exit:hover {
    background: rgba(239, 68, 68, 0.25) !important;
    color: #ffffff !important;
    border-color: rgba(239, 68, 68, 0.5) !important;
}

/* Divider styling in replay panel */
#replay-controls span {
    height: 20px;
    width: 1px;
    background: rgba(255, 255, 255, 0.15);
    margin: 0 4px;
    flex-shrink: 0;
}

/* Responsive mobile scaling for replay controls */
@media (max-width: 600px) {
    #replay-controls {
        bottom: 10px;
        padding: 6px 10px;
        gap: 4px;
        border-radius: 8px;
        max-width: 98vw;
    }
    #replay-controls .btn {
        padding: 6px 8px !important;
        height: 32px !important;
        font-size: 0 !important; /* Hide text, only show icons */
    }
    #replay-controls .btn .material-symbols-outlined {
        font-size: 1.1rem !important;
        margin: 0 !important;
    }
    #replay-controls #btn-replay-play {
        font-size: 0.7rem !important; /* Keep text for play/pause if it fits */
    }
}
