/* css/style.css - Math Battleship Light Theme & Symmetrical Alignment */
:root {
    --bg-dark: #f1f5f9;       /* Light slate page background */
    --bg-card: #ffffff;       /* Pure white cards */
    --bg-card-alt: #f8fafc;   /* Subtle off-white */
    --border-color: #cbd5e1;  /* Slate border */
    --border-strong: #0f172a; /* Black axis border */
    --primary: #2563eb;       /* Royal Blue */
    --primary-hover: #1d4ed8;
    --axis-y: #047857;        /* Emerald for Y (Vertical) */
    --axis-x: #b45309;        /* Amber/Orange for X (Horizontal) */
    --accent-red: #dc2626;    /* Crimson Red for hits & fire */
    --accent-blue: #0284c7;   /* Cyan Blue for water misses */
    --text-main: #0f172a;     /* Deep black-slate text */
    --text-muted: #64748b;    /* Readable slate muted text */
    --font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    --min-touch-target: 44px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100%;
    width: 100%;
    overflow: hidden;
    background-color: var(--bg-dark);
    color: var(--text-main);
    font-family: var(--font-family);
    display: flex;
    flex-direction: column;
    transition: background-color 0.4s ease;
}

/* Dynamic Body Background for Turns */
body.turn-my-turn {
    background-color: #ecfdf5; /* Light soft pastel green: your turn */
}

body.turn-opponent-turn {
    background-color: #fff1f2; /* Light soft pastel red: opponent's turn */
}

/* Custom touch-friendly, visible scrollbars */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}
::-webkit-scrollbar-track {
    background: #e2e8f0;
    border-radius: 5px;
}
::-webkit-scrollbar-thumb {
    background: #94a3b8;
    border-radius: 5px;
}
::-webkit-scrollbar-thumb:hover {
    background: #64748b;
}

/* Header & Connection status */
header {
    background: #ffffff;
    border-bottom: 2px solid #e2e8f0;
    padding: 0.35rem 1.25rem;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    z-index: 10;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.brand h1 {
    font-size: 1.05rem;
    font-weight: 800;
    color: #0f172a;
    letter-spacing: -0.01em;
}

.brand .badge {
    background: #e0f2fe;
    color: #0369a1;
    border: 1px solid #7dd3fc;
    font-size: 0.72rem;
    font-weight: 700;
    padding: 0.12rem 0.55rem;
    border-radius: 9999px;
}

.header-status {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.85rem;
}

.room-display {
    background: #f1f5f9;
    border: 1px solid var(--border-color);
    padding: 0.15rem 0.55rem;
    border-radius: 0.375rem;
    font-family: monospace;
    font-weight: 800;
    color: #0f172a;
    letter-spacing: 0.08em;
}

.connection-indicator {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.8rem;
    font-weight: 600;
    color: #475569;
}

.status-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background-color: #10b981;
    display: inline-block;
}
.status-dot.warning { background-color: #f59e0b; }
.status-dot.danger { background-color: #ef4444; }

/* Main app container */
main {
    flex: 1 1 auto;
    width: 100%;
    min-height: 0;
    position: relative;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Views switcher - single, clean scroll container per active view */
.view {
    display: none !important;
    width: 100%;
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
}
.view.active {
    display: flex !important;
    flex-direction: column;
}

/* 1. Lobby View */
#view-lobby {
    align-items: center;
    justify-content: flex-start;
    padding: 1rem 1rem 3rem 1rem;
    min-height: 100%;
}

.lobby-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 1rem;
    padding: 1.25rem 1.75rem;
    max-width: 860px;
    width: 100%;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.08);
    margin: auto 0;
}

.lobby-header {
    margin-bottom: 0.85rem;
    text-align: center;
}

.lobby-card h2 {
    font-size: 1.4rem;
    color: #0f172a;
    margin-bottom: 0.15rem;
}

.lobby-card p.subtitle {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 0;
}

.lobby-content-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.25rem;
}

@media (min-width: 680px) {
    .lobby-content-grid {
        grid-template-columns: 1.15fr 1fr;
        gap: 1.5rem;
        align-items: stretch;
    }
}

.lobby-col {
    display: flex;
    flex-direction: column;
}

.lobby-section-title {
    font-size: 0.82rem;
    font-weight: 800;
    color: #334155;
    margin-bottom: 0.45rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* Difficulty Presets in Lobby */
.difficulty-selector {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    flex: 1;
}

.preset-card {
    background: #f8fafc;
    border: 2px solid var(--border-color);
    border-radius: 0.55rem;
    padding: 0.45rem 0.75rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
}

.preset-card input[type="radio"] {
    display: none;
}

.preset-card.selected {
    border-color: var(--primary);
    background: #eff6ff;
    box-shadow: 0 0 0 1px var(--primary);
}

.preset-badge {
    font-size: 0.72rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.badge-beginner { color: #059669; }
.badge-intermediate { color: #d97706; }
.badge-advanced { color: #dc2626; }

.preset-title {
    font-weight: 800;
    font-size: 0.88rem;
    color: #0f172a;
}

.preset-desc {
    font-size: 0.76rem;
    color: var(--text-muted);
    line-height: 1.25;
}

.lobby-actions-col {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.lobby-action-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.lobby-action-buttons .btn {
    min-height: 42px;
    padding: 0.45rem 0.75rem;
    font-size: 0.92rem;
}

.divider {
    display: flex;
    align-items: center;
    text-align: center;
    margin: 0.75rem 0;
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 700;
}
.divider::before, .divider::after {
    content: '';
    flex: 1;
    border-bottom: 1px solid var(--border-color);
}
.divider::before { margin-right: .5em; }
.divider::after { margin-left: .5em; }

.join-row {
    display: flex;
    gap: 0.5rem;
}

.join-row input.input-text {
    flex: 1;
    height: 42px;
    min-height: 42px;
    background: #ffffff;
    border: 2px solid var(--border-color);
    border-radius: 0.5rem;
    color: #0f172a;
    padding: 0.4rem 0.6rem;
    font-size: 1.05rem;
    font-family: inherit;
    text-transform: uppercase;
    font-weight: 800;
    text-align: center;
    letter-spacing: 0.12em;
}
.join-row input.input-text:focus {
    outline: none;
    border-color: var(--primary);
}

.join-row .btn {
    min-height: 42px;
    height: 42px;
    padding: 0 1.1rem;
    font-size: 0.92rem;
    white-space: nowrap;
}

/* Buttons */
.btn {
    min-height: var(--min-touch-target);
    padding: 0.5rem 1rem;
    font-size: 0.95rem;
    font-weight: 700;
    border-radius: 0.5rem;
    border: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    transition: all 0.2s ease;
    user-select: none;
}
.btn-sm {
    min-height: 32px;
    padding: 0.25rem 0.6rem;
    font-size: 0.8rem;
}
.btn-lg {
    min-height: 48px;
    font-size: 1.05rem;
}
.btn-primary { background: var(--primary); color: #ffffff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: #e2e8f0; color: #1e293b; border: 1px solid #cbd5e1; }
.btn-secondary:hover:not(:disabled) { background: #cbd5e1; }
.btn-success { background: #10b981; color: #ffffff; }
.btn-success:hover:not(:disabled) { background: #059669; }
.btn-danger { background: #dc2626; color: #ffffff; }
.btn-danger:hover:not(:disabled) { background: #b91c1c; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-full { width: 100%; }

/* 2. Setup View (Centered, Bigger Grid & Two-Button Boat Nav) */
#view-setup {
    padding: 0.5rem 0.75rem 2.5rem 0.75rem;
    min-height: 100%;
    align-items: center;
    justify-content: flex-start;
}

.setup-container {
    width: 100%;
    max-width: 1100px;
    display: flex;
    flex-direction: column;
    margin: auto 0;
}

.setup-layout {
    display: flex;
    flex-direction: row;
    gap: 0.85rem;
    align-items: center;
    justify-content: center;
    width: 100%;
}

/* Centered & Responsive Waters Card */
.setup-board-card {
    flex: 0 1 auto;
    width: 100%;
    max-width: min(480px, calc(100vh - 120px));
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    padding: 0.4rem 0.6rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}

.board-header {
    width: 100%;
    min-height: 26px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.15rem;
    flex-shrink: 0;
}
.board-title-group {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    flex-wrap: wrap;
}
.board-title {
    font-size: 0.92rem;
    font-weight: 800;
    color: #0f172a;
}
.board-instruction-hint {
    font-size: 0.75rem;
    color: #0284c7;
    font-weight: 700;
}
.board-badge {
    font-size: 0.7rem;
    font-weight: 700;
    padding: 0.12rem 0.4rem;
    border-radius: 9999px;
    background: #f1f5f9;
    border: 1px solid var(--border-color);
    color: #475569;
}

/* Maximize setup grid with fluid scaling for Chromebook and Smartboards */
.grid-viewport.large-grid {
    height: auto;
    width: 100%;
    max-height: min(440px, calc(100vh - 145px));
    max-width: min(440px, calc(100vh - 145px));
    aspect-ratio: 1 / 1;
    margin: auto;
    display: flex;
    align-items: center;
    justify-content: center;
}
.grid-viewport.large-grid svg {
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    display: block;
}

/* Right Controls Panel for Setup */
.setup-controls-panel {
    width: clamp(280px, 32vw, 360px);
    flex-shrink: 0;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    padding: 0.45rem 0.65rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
    max-height: calc(100vh - 70px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.panel-section-title {
    font-size: 0.8rem;
    font-weight: 800;
    color: #1e293b;
    margin-bottom: 0.1rem;
}

.ships-selector {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    flex: 0 1 auto;
}

/* Kid-Friendly Boat Unit Card with Two Navigation Buttons */
.kid-boat-unit {
    background: #f8fafc;
    border: 1.5px solid var(--border-color);
    border-radius: 0.45rem;
    padding: 0.25rem 0.45rem;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    transition: all 0.15s ease;
}
.kid-boat-unit.selected {
    border-color: var(--primary);
    background: #eff6ff;
    box-shadow: 0 0 0 1px var(--primary);
}
.kid-boat-unit.placed {
    border-color: #10b981;
}

.boat-unit-header {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    cursor: pointer;
}
.boat-preview-box {
    width: 40px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: 3px;
    padding: 1px;
}
.boat-vector-svg {
    width: 100%;
    height: 100%;
    display: block;
}
.boat-title-area {
    display: flex;
    flex-direction: column;
    flex: 1;
}
.boat-title {
    font-size: 0.8rem;
    font-weight: 800;
    color: #0f172a;
    line-height: 1.1;
}
.boat-subtitle {
    font-size: 0.67rem;
    color: var(--text-muted);
}
.placed-tag {
    color: #059669;
    font-weight: 700;
}
.unplaced-tag {
    color: #0284c7;
    font-weight: 600;
}

/* Two Navigation Options per Boat */
.boat-orient-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.25rem;
}

.btn-orient {
    height: 26px;
    min-height: 26px;
    background: #ffffff;
    border: 1.5px solid var(--border-color);
    border-radius: 0.35rem;
    font-size: 0.72rem;
    font-weight: 700;
    color: #334155;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.2rem;
    transition: all 0.15s ease;
}
.btn-orient:hover {
    background: #f1f5f9;
    border-color: #94a3b8;
}
.btn-orient.active-orient {
    background: var(--primary);
    color: #ffffff;
    border-color: var(--primary);
    box-shadow: 0 1px 3px rgba(37, 99, 235, 0.3);
}

.setup-buttons-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.25rem;
    margin-top: 0.1rem;
}

.setup-buttons-grid .btn {
    min-height: 28px;
    height: 28px;
    padding: 0.2rem 0.35rem;
    font-size: 0.72rem;
}

.btn-ready {
    min-height: 38px;
    height: 38px;
    font-size: 0.92rem;
    font-weight: 800;
    letter-spacing: 0.02em;
}

.setup-status-pill {
    font-size: 0.72rem;
    font-weight: 600;
    color: #475569;
    text-align: center;
    padding: 0.15rem 0.4rem;
    background: #f1f5f9;
    border-radius: 0.35rem;
}

/* 3. Battle View (Symmetrical Alignment & Straight Red Lines) */
#view-battle {
    padding: 0.35rem 0.6rem 2.5rem 0.6rem;
    min-height: 100%;
    align-items: center;
    justify-content: flex-start;
}

.battle-container {
    width: 100%;
    max-width: 1100px;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    margin: auto 0;
}

.turn-banner {
    width: 100%;
    height: 32px;
    border-radius: 0.5rem;
    text-align: center;
    font-size: 0.88rem;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.3s ease;
}
.turn-banner.my-turn {
    background: #059669;
    color: #ffffff;
    border: 1px solid #047857;
    box-shadow: 0 2px 8px rgba(5, 150, 105, 0.25);
}
.turn-banner.opponent-turn {
    background: #dc2626;
    color: #ffffff;
    border: 1px solid #b91c1c;
    box-shadow: 0 2px 8px rgba(220, 38, 38, 0.25);
}

/* Side-by-Side Symmetrical Boards */
.boards-wrapper {
    display: flex;
    flex-direction: row;
    gap: 0.75rem;
    justify-content: center;
    align-items: center;
    width: 100%;
}

.battle-board-card {
    flex: 1 1 0%;
    min-width: 0;
    max-width: 480px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    padding: 0.4rem 0.6rem;
    display: flex;
    flex-direction: column;
    justify-content: flex-start; /* Aligns top red line */
    gap: 0.25rem;
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}

/* Fixed identical dimensions so top red line is straight */
.grid-viewport.battle-grid {
    height: auto;
    width: 100%;
    max-height: min(380px, calc(100vh - 200px));
    max-width: min(380px, calc(100vh - 200px));
    aspect-ratio: 1 / 1;
    margin: 0 auto;
    flex-shrink: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}
.grid-viewport.battle-grid svg {
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    display: block;
}

/* Shared Box for Targeting and Battle Activity: EXACT same height (74px) */
.console-box {
    height: 74px;
    background: #f8fafc;
    border: 1.5px solid var(--border-color);
    border-radius: 0.5rem;
    padding: 0.3rem 0.5rem;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    flex-shrink: 0;
    margin-top: auto; /* Aligns bottom red line */
}

.console-title {
    font-size: 0.75rem;
    font-weight: 800;
    color: #475569;
    text-align: center;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    height: 14px;
    line-height: 14px;
}

.coord-inputs-row {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    height: 44px;
}

.coord-field {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
}

.coord-field label {
    font-size: 0.72rem;
    font-weight: 800;
}
.coord-field.y-field label { color: var(--axis-y); }
.coord-field.x-field label { color: var(--axis-x); }

.coord-input {
    height: 38px;
    background: #ffffff;
    border: 2px solid var(--border-color);
    border-radius: 0.375rem;
    color: #0f172a;
    font-size: 1.15rem;
    font-weight: 800;
    text-align: center;
    font-family: inherit;
    width: 100%;
}
.coord-field.y-field .coord-input:focus { border-color: var(--axis-y); outline: none; }
.coord-field.x-field .coord-input:focus { border-color: var(--axis-x); outline: none; }

.btn-fire {
    flex: 1.5;
    height: 38px;
    font-size: 1.05rem;
    font-weight: 800;
}

.battle-log {
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    padding: 0.35rem 0.5rem;
    font-size: 0.78rem;
    color: #334155;
    height: 48px;
    overflow-y: auto;
}
.battle-log-entry { margin-bottom: 0.15rem; }
.battle-log-entry.hit { color: #dc2626; font-weight: 800; }
.battle-log-entry.sunk { color: #b45309; font-weight: 800; }

/* SVG Styles - Light Theme */
.math-grid-svg { width: 100%; height: 100%; display: block; user-select: none; }
.grid-canvas-bg { fill: #ffffff; rx: 4px; stroke: #94a3b8; stroke-width: 1px; }
.cell-even { fill: #ffffff; }
.cell-odd { fill: #f8fafc; }
.cell-origin { fill: #e0f2fe; stroke: #0284c7; stroke-width: 1.5px; }

.grid-line { stroke: #cbd5e1; stroke-width: 1px; }
.grid-border-main { stroke: #0f172a; stroke-width: 1.5px; }

/* Clear Black X and Y Axes for Teachers */
.main-axis { stroke: #000000; stroke-width: 2.5px; marker-end: url(#axis-arrow); }
.main-axis.y-axis { stroke: #000000; }
.main-axis.x-axis { stroke: #000000; }

/* Crisp Black Labels */
.axis-label { fill: #0f172a; font-size: 13px; font-weight: 800; user-select: none; }
.axis-label.y-label { fill: #0f172a; }
.axis-label.x-label { fill: #0f172a; }

/* Dedicated Axis Titles with zero overlap */
.axis-title { font-size: 12px; font-weight: 800; letter-spacing: 0.02em; }
.axis-title.y-title { fill: var(--axis-y); }
.axis-title.x-title { fill: var(--axis-x); }

.origin-label { fill: #000000; font-size: 13px; font-weight: 800; }
.origin-badge-text { fill: #0369a1; font-size: 11px; font-weight: 800; }

.grid-touch-target { fill: transparent; cursor: crosshair; }
.grid-touch-target:hover { fill: rgba(37, 99, 235, 0.15); }
.math-grid-svg.non-interactive { cursor: default; }
.math-grid-svg.non-interactive .grid-touch-target { pointer-events: none; cursor: default; }

/* Crosshair SVG Styles */
.crosshair-line { stroke-width: 2.5px; stroke-dasharray: 4, 3; }
.crosshair-y-line { stroke: var(--axis-y); }
.crosshair-x-line { stroke: var(--axis-x); }
.crosshair-cell { fill: rgba(56, 189, 248, 0.35); stroke: #0284c7; stroke-width: 2.5px; rx: 4px; }
.crosshair-reticle { fill: rgba(220, 38, 38, 0.25); stroke: #dc2626; stroke-width: 2.5px; animation: reticle-pulse 1.2s infinite ease-in-out; }
.crosshair-dot { fill: #dc2626; }
.crosshair-badge-text { fill: #0f172a; font-size: 14px; font-weight: 800; filter: drop-shadow(0 1px 2px rgba(255,255,255,0.9)); }

@keyframes reticle-pulse {
    0%, 100% { r: 10px; opacity: 0.9; }
    50% { r: 15px; opacity: 0.5; }
}

/* Ships SVG */
.ship-cell { fill: #2563eb; stroke: #1d4ed8; stroke-width: 1.5px; }
.ship-cell.sunk { fill: #94a3b8; stroke: #64748b; }
.ship-segment { stroke: #2563eb; stroke-width: 7px; stroke-linecap: round; }
.ship-segment.sunk { stroke: #94a3b8; }
.ship-vertex { fill: #38bdf8; stroke: #1e40af; stroke-width: 2.5px; }
.ship-vertex.sunk { fill: #94a3b8; stroke: #64748b; }

/* Shots SVG */
.shot-marker { pointer-events: none; }
.hit-halo { fill: #dc2626; opacity: 0.9; filter: drop-shadow(0 0 6px rgba(220, 38, 38, 0.8)); }
.hit-cross-line { stroke: #ffffff; stroke-width: 2.5px; stroke-linecap: round; }
.miss-pin { fill: #ffffff; stroke: #0284c7; stroke-width: 2.5px; }
.miss-ripple { fill: none; stroke: #38bdf8; stroke-width: 2px; opacity: 0.8; }

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(15, 23, 42, 0.7);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    z-index: 1000;
}
.modal-overlay.active { display: flex; }
.modal-card {
    background: #ffffff;
    border: 2px solid var(--border-color);
    border-radius: 1.25rem;
    padding: 2rem 2.25rem;
    max-width: 480px;
    width: 100%;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 1.15rem;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    animation: modal-pop 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modal-pop {
    from { transform: scale(0.92); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.modal-icon {
    font-size: 3.5rem;
    line-height: 1;
    margin-bottom: -0.25rem;
}

.modal-card.victory {
    border-color: #10b981;
}
.modal-card.victory h2 {
    color: #059669;
    font-size: 1.65rem;
    font-weight: 800;
}

.modal-card.defeat {
    border-color: #f43f5e;
}
.modal-card.defeat h2 {
    color: #e11d48;
    font-size: 1.65rem;
    font-weight: 800;
}

.modal-card p {
    font-size: 0.98rem;
    color: #475569;
    line-height: 1.45;
}

.modal-actions {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-top: 0.5rem;
}

.modal-actions .btn {
    min-height: 48px;
    font-size: 1rem;
    font-weight: 800;
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    z-index: 2000;
    pointer-events: none;
}
.toast {
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-left: 5px solid var(--primary);
    padding: 0.6rem 1rem;
    border-radius: 0.5rem;
    color: #0f172a;
    font-size: 0.88rem;
    font-weight: 700;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.3s ease;
    pointer-events: auto;
}
.toast.visible { opacity: 1; transform: translateY(0); }
.toast.toast-warning { border-left-color: #d97706; }
.toast.toast-danger { border-left-color: #dc2626; }
.toast.toast-success { border-left-color: #059669; }

/* Responsive fallback for narrow mobile screens */
@media (max-width: 719px) {
    .setup-layout { flex-direction: column; height: auto; }
    .setup-controls-panel { width: 100%; }
    .boards-wrapper { flex-direction: column; height: auto; }
    .battle-board-card { max-width: 100%; }
}

/* Specific optimizations for compact viewports (e.g. Chromebooks ~1366x578, laptops, smartboards with toolbars) */
@media (max-height: 600px) {
    header {
        height: 36px;
        padding: 0.2rem 1rem;
    }
    .brand h1 {
        font-size: 0.95rem;
    }
    .brand .badge {
        font-size: 0.68rem;
        padding: 0.1rem 0.4rem;
    }
    
    /* Setup View Low-Height Optimizations */
    #view-setup {
        padding: 0.2rem 0.5rem 2rem 0.5rem;
    }
    .setup-layout {
        gap: 0.5rem;
    }
    .setup-board-card {
        padding: 0.3rem 0.5rem;
        max-width: min(420px, calc(100vh - 85px));
    }
    .board-header {
        min-height: 22px;
        margin-bottom: 0.1rem;
    }
    .board-title {
        font-size: 0.85rem;
    }
    .board-instruction-hint {
        font-size: 0.7rem;
    }
    .grid-viewport.large-grid {
        max-height: min(390px, calc(100vh - 85px));
        max-width: min(390px, calc(100vh - 85px));
    }
    .setup-controls-panel {
        width: clamp(260px, 28vw, 320px);
        padding: 0.35rem 0.5rem;
        gap: 0.2rem;
    }
    .panel-section-title {
        font-size: 0.74rem;
    }
    .ships-selector {
        gap: 0.15rem;
    }
    .kid-boat-unit {
        padding: 0.2rem 0.35rem;
        gap: 0.1rem;
    }
    .boat-preview-box {
        width: 36px;
        height: 16px;
    }
    .boat-title {
        font-size: 0.78rem;
    }
    .boat-subtitle {
        font-size: 0.65rem;
    }
    .btn-orient {
        height: 24px;
        min-height: 24px;
        font-size: 0.7rem;
        padding: 0.1rem 0.25rem;
    }
    .setup-buttons-grid {
        gap: 0.2rem;
    }
    .setup-buttons-grid .btn {
        min-height: 26px;
        height: 26px;
        padding: 0.15rem 0.3rem;
        font-size: 0.7rem;
    }
    .btn-ready {
        min-height: 36px;
        height: 36px;
        font-size: 0.88rem;
        padding: 0.25rem 0.5rem;
    }
    .setup-status-pill {
        font-size: 0.7rem;
        padding: 0.1rem 0.3rem;
    }

    /* Battle View Low-Height Optimizations */
    #view-battle {
        padding: 0.2rem 0.5rem 2rem 0.5rem;
    }
    .turn-banner {
        height: 28px;
        font-size: 0.82rem;
    }
    .boards-wrapper {
        gap: 0.5rem;
    }
    .battle-board-card {
        padding: 0.3rem 0.5rem;
        gap: 0.2rem;
        max-width: 420px;
    }
    .grid-viewport.battle-grid {
        max-height: min(340px, calc(100vh - 165px));
        max-width: min(340px, calc(100vh - 165px));
    }
    .console-box {
        height: 66px;
        padding: 0.25rem 0.45rem;
    }
    .console-title {
        font-size: 0.66rem;
        height: 12px;
        line-height: 12px;
    }
    .coord-inputs-row {
        height: 32px;
        gap: 0.3rem;
    }
    .coord-field label {
        font-size: 0.62rem;
    }
    .coord-input {
        height: 28px;
        font-size: 0.9rem;
    }
    .btn-fire {
        height: 28px;
        min-height: 28px;
        font-size: 0.82rem;
        padding: 0.15rem 0.4rem;
    }
    .battle-log {
        max-height: 42px;
        font-size: 0.68rem;
    }
    .battle-log-entry {
        padding: 0.08rem 0.25rem;
        font-size: 0.68rem;
    }
}

/* Generous Scaling for Larger Screens (Desktops, 1920x1080 Smartboards, Large Monitors) */
@media (min-width: 1100px) and (min-height: 720px) {
    /* 1. Lobby View Scaling */
    .lobby-card {
        max-width: 960px;
        padding: 2rem 2.5rem;
    }
    .lobby-card h2 {
        font-size: 1.65rem;
    }
    .preset-card {
        padding: 0.65rem 0.95rem;
    }
    .preset-title {
        font-size: 0.98rem;
    }
    .preset-desc {
        font-size: 0.82rem;
    }
    .lobby-action-buttons .btn {
        min-height: 48px;
        font-size: 1.02rem;
    }
    .join-row input.input-text, .join-row .btn {
        height: 48px;
        min-height: 48px;
        font-size: 1.05rem;
    }

    /* 2. Setup View Scaling */
    .setup-container {
        max-width: min(1400px, 94vw);
    }
    .setup-layout {
        gap: 1.5rem;
    }
    .setup-board-card {
        max-width: min(600px, calc(100vh - 150px));
        padding: 0.75rem 1rem;
    }
    .grid-viewport.large-grid {
        max-height: min(560px, calc(100vh - 180px));
        max-width: min(560px, calc(100vh - 180px));
    }
    .setup-controls-panel {
        width: clamp(320px, 26vw, 420px);
        padding: 0.85rem 1rem;
        gap: 0.5rem;
    }
    .panel-section-title {
        font-size: 0.92rem;
    }
    .kid-boat-unit {
        padding: 0.45rem 0.65rem;
        gap: 0.3rem;
    }
    .boat-preview-box {
        width: 52px;
        height: 24px;
    }
    .boat-title {
        font-size: 0.92rem;
    }
    .boat-subtitle {
        font-size: 0.75rem;
    }
    .btn-orient {
        height: 32px;
        min-height: 32px;
        font-size: 0.82rem;
    }
    .setup-buttons-grid .btn {
        min-height: 34px;
        height: 34px;
        font-size: 0.82rem;
    }
    .btn-ready {
        min-height: 46px;
        height: 46px;
        font-size: 1.05rem;
    }

    /* 3. Battle View Scaling */
    .battle-container {
        max-width: min(1500px, 96vw);
        gap: 0.6rem;
    }
    .turn-banner {
        height: 38px;
        font-size: 1rem;
    }
    .boards-wrapper {
        gap: 1.25rem;
    }
    .battle-board-card {
        max-width: min(580px, calc(50vw - 24px));
        padding: 0.65rem 0.9rem;
    }
    .grid-viewport.battle-grid {
        max-height: min(480px, calc(100vh - 240px));
        max-width: min(480px, calc(100vh - 240px));
    }
    .console-box {
        height: 84px;
        padding: 0.45rem 0.7rem;
    }
    .console-title {
        font-size: 0.78rem;
    }
    .coord-inputs-row {
        height: 44px;
        gap: 0.6rem;
    }
    .coord-input {
        height: 40px;
        font-size: 1.15rem;
    }
    .btn-fire {
        height: 40px;
        min-height: 40px;
        font-size: 1rem;
    }
    .battle-log {
        max-height: 52px;
        font-size: 0.76rem;
    }
}

/* Extra Large Screens (1920x1080 full-screen or higher) */
@media (min-width: 1400px) and (min-height: 900px) {
    .grid-viewport.large-grid {
        max-height: min(660px, calc(100vh - 200px));
        max-width: min(660px, calc(100vh - 200px));
    }
    .setup-board-card {
        max-width: min(700px, calc(100vh - 160px));
    }
    .grid-viewport.battle-grid {
        max-height: min(560px, calc(100vh - 260px));
        max-width: min(560px, calc(100vh - 260px));
    }
    .battle-board-card {
        max-width: min(640px, calc(50vw - 32px));
    }
}
