/* ============================================
   BATALLA NAVAL ONLINE - STYLES
   Mobile-first design (320px base)
   ============================================ */

/* ============================================
   CSS VARIABLES
   ============================================ */
:root {
    /* Colors - Ocean theme */
    --color-ocean: #1a5276;
    --color-ocean-dark: #0e2f44;
    --color-ocean-light: #2980b9;
    --color-water: #3498db;
    --color-water-light: #85c1e9;

    /* Game states */
    --color-hit: #e74c3c;
    --color-sunk: #c0392b;
    --color-miss: #5dade2;
    --color-ship: #34495e;
    --color-ship-preview: rgba(52, 73, 94, 0.5);
    --color-ship-valid: rgba(46, 204, 113, 0.6);
    --color-ship-invalid: rgba(231, 76, 60, 0.6);

    /* UI states */
    --color-my-turn: #27ae60;
    --color-waiting: #f39c12;
    --color-victory: #f1c40f;
    --color-defeat: #7f8c8d;

    /* UI colors */
    --color-bg: #0e2f44;
    --color-text: #ecf0f1;
    --color-text-muted: #bdc3c7;
    --color-button: #3498db;
    --color-button-hover: #2980b9;
    --color-button-secondary: #34495e;

    /* Grid sizing - mobile default */
    --cell-size: 28px;
    --cell-gap: 2px;
    --mini-cell-size: 18px;
    --board-padding: 4px;

    /* Transitions */
    --transition-fast: 0.15s;
    --transition-normal: 0.3s;
}

/* Responsive breakpoints */
@media (min-width: 375px) {
    :root {
        --cell-size: 30px;
        --mini-cell-size: 20px;
    }
}

@media (min-width: 414px) {
    :root {
        --cell-size: 32px;
        --mini-cell-size: 22px;
    }
}

@media (min-width: 768px) {
    :root {
        --cell-size: 36px;
        --mini-cell-size: 24px;
    }
}

/* ============================================
   RESET & BASE
   ============================================ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    height: 100dvh;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, var(--color-ocean-dark) 0%, var(--color-ocean) 100%);
    color: var(--color-text);
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
}

/* ============================================
   SCREENS
   ============================================ */
.screen {
    display: none;
    min-height: 100vh;
    min-height: 100dvh;
    padding: 16px;
}

.screen.active {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.container {
    width: 100%;
    max-width: 400px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

/* ============================================
   TYPOGRAPHY
   ============================================ */
.title {
    font-size: 1.8rem;
    font-weight: 800;
    text-align: center;
    color: var(--color-text);
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.title-icon {
    font-size: 2.5rem;
}

.title-sub {
    font-size: 1rem;
    font-weight: 400;
    letter-spacing: 0.3em;
    color: var(--color-water-light);
}

h2 {
    font-size: 1.3rem;
    font-weight: 600;
    text-align: center;
}

h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-text-muted);
    margin-bottom: 8px;
}

h4 {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--color-text-muted);
    margin-bottom: 4px;
}

/* ============================================
   FORM ELEMENTS
   ============================================ */
.form-group {
    width: 100%;
}

input[type="text"] {
    width: 100%;
    padding: 14px 16px;
    font-size: 1rem;
    border: 2px solid var(--color-ocean-light);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.1);
    color: var(--color-text);
    outline: none;
    transition: border-color var(--transition-fast);
    text-align: center;
    text-transform: uppercase;
}

input[type="text"]::placeholder {
    color: var(--color-text-muted);
    text-transform: none;
}

input[type="text"]:focus {
    border-color: var(--color-water);
}

#input-code {
    font-size: 1.5rem;
    letter-spacing: 0.3em;
    font-weight: 700;
}

/* ============================================
   BUTTONS
   ============================================ */
.btn {
    width: 100%;
    padding: 16px 24px;
    font-size: 1rem;
    font-weight: 600;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all var(--transition-fast);
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    min-height: 52px;
}

.btn-primary {
    background: var(--color-button);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: var(--color-button-hover);
    transform: translateY(-1px);
}

.btn-primary:active:not(:disabled) {
    transform: translateY(0);
}

.btn-secondary {
    background: var(--color-button-secondary);
    color: var(--color-text);
}

.btn-secondary:hover:not(:disabled) {
    background: #3d566e;
}

.btn-text {
    background: transparent;
    color: var(--color-text-muted);
    text-decoration: underline;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ============================================
   DIVIDER
   ============================================ */
.divider {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 16px;
    color: var(--color-text-muted);
}

.divider::before,
.divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--color-ocean-light);
}

/* ============================================
   SHIPS DECORATION
   ============================================ */
.ships-decoration {
    font-size: 1.5rem;
    letter-spacing: 0.5em;
    opacity: 0.8;
}

/* ============================================
   ROOM CODE DISPLAY
   ============================================ */
.room-code-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 24px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 16px;
    width: 100%;
}

.room-code-display .label {
    font-size: 0.9rem;
    color: var(--color-text-muted);
}

.room-code-display .code {
    font-size: 2.5rem;
    font-weight: 800;
    letter-spacing: 0.3em;
    color: var(--color-water-light);
}

/* ============================================
   SPINNER
   ============================================ */
.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--color-ocean-light);
    border-top-color: var(--color-water);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ============================================
   BOARD
   ============================================ */
.board-container {
    display: flex;
    gap: 2px;
}

.board-labels-col {
    display: flex;
    flex-direction: column;
    gap: var(--cell-gap);
}

.board-wrapper {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.board-labels-row {
    display: flex;
    gap: var(--cell-gap);
}

.label-cell {
    width: var(--cell-size);
    height: var(--cell-size);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--color-text-muted);
}

.board-labels-col .label-cell:first-child {
    /* Empty corner */
}

.board {
    display: grid;
    grid-template-columns: repeat(10, var(--cell-size));
    grid-template-rows: repeat(10, var(--cell-size));
    gap: var(--cell-gap);
    background: var(--color-ocean-dark);
    padding: var(--board-padding);
    border-radius: 8px;
    border: 2px solid var(--color-ocean-light);
}

.board.mini {
    --cell-size: var(--mini-cell-size);
}

.board.mini .cell {
    font-size: 0.6rem;
}

.cell {
    width: var(--cell-size);
    height: var(--cell-size);
    background: var(--color-water);
    border-radius: 3px;
    cursor: pointer;
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    position: relative;
}

.cell:hover {
    background: var(--color-water-light);
}

/* Cell states */
.cell.ship {
    background: var(--color-ship);
}

.cell.preview {
    background: var(--color-ship-preview);
}

.cell.preview.valid {
    background: var(--color-ship-valid);
}

.cell.preview.invalid {
    background: var(--color-ship-invalid);
}

.cell.miss {
    background: var(--color-miss);
}

.cell.miss::after {
    content: '~';
    font-size: 1.2rem;
    color: white;
    opacity: 0.8;
}

.cell.hit {
    background: var(--color-hit);
    animation: pulse 0.5s ease-out;
}

.cell.hit::after {
    content: '🔥';
    font-size: 0.9em;
}

.cell.sunk {
    background: var(--color-sunk);
}

.cell.sunk::after {
    content: '💥';
    font-size: 0.9em;
}

.board.disabled .cell {
    cursor: not-allowed;
    opacity: 0.7;
}

.board.disabled .cell:hover {
    background: var(--color-water);
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

/* ============================================
   SETUP SCREEN
   ============================================ */
.ship-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 12px;
}

#ship-name {
    font-weight: 600;
    color: var(--color-text);
}

.ship-cells {
    font-size: 1.2rem;
    letter-spacing: 0.1em;
}

.setup-controls {
    display: flex;
    gap: 12px;
    width: 100%;
}

.setup-controls .btn {
    flex: 1;
}

.status-text {
    font-size: 0.9rem;
    color: var(--color-text-muted);
    text-align: center;
}

.status-text.ready {
    color: var(--color-my-turn);
}

.status-text.waiting {
    color: var(--color-waiting);
}

/* ============================================
   PLAYING SCREEN
   ============================================ */
.game-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 12px 16px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 12px;
}

.player-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.player-name {
    font-size: 0.85rem;
    font-weight: 600;
    max-width: 80px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ships-count {
    font-size: 0.7rem;
    letter-spacing: 0.1em;
}

.vs {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--color-text-muted);
}

.turn-indicator {
    padding: 10px 24px;
    border-radius: 20px;
    font-weight: 600;
    font-size: 0.9rem;
    transition: all var(--transition-normal);
}

.turn-indicator.my-turn {
    background: var(--color-my-turn);
    color: white;
}

.turn-indicator.waiting {
    background: var(--color-waiting);
    color: white;
}

.enemy-board-section,
.my-board-section {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.my-board-section {
    margin-top: 12px;
}

/* Shot feedback */
.shot-feedback {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    padding: 24px 48px;
    background: rgba(0, 0, 0, 0.9);
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    z-index: 100;
    animation: feedbackPop 0.3s ease-out;
}

.shot-feedback.hidden {
    display: none;
}

.shot-feedback .feedback-emoji {
    font-size: 3rem;
}

.shot-feedback .feedback-text {
    font-size: 1.2rem;
    font-weight: 700;
}

.shot-feedback.water .feedback-text {
    color: var(--color-water-light);
}

.shot-feedback.hit .feedback-text {
    color: var(--color-hit);
}

.shot-feedback.sunk .feedback-text {
    color: var(--color-victory);
}

@keyframes feedbackPop {
    0% { transform: translate(-50%, -50%) scale(0.5); opacity: 0; }
    100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

/* ============================================
   FINISHED SCREEN
   ============================================ */
.result-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 32px;
    border-radius: 16px;
    width: 100%;
}

.result-content.win {
    background: linear-gradient(135deg, var(--color-my-turn) 0%, #1e8449 100%);
}

.result-content.lose {
    background: linear-gradient(135deg, var(--color-defeat) 0%, #566573 100%);
}

.result-emoji {
    font-size: 4rem;
}

.result-text {
    font-size: 1.8rem;
    font-weight: 800;
}

.final-boards {
    display: flex;
    gap: 16px;
    width: 100%;
    justify-content: center;
}

.final-board-section {
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* ============================================
   ERROR SCREEN
   ============================================ */
.error-icon {
    font-size: 4rem;
}

#error-message {
    color: var(--color-text-muted);
    text-align: center;
}

/* ============================================
   TOAST
   ============================================ */
.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    padding: 12px 24px;
    background: rgba(0, 0, 0, 0.9);
    color: white;
    border-radius: 8px;
    font-size: 0.9rem;
    transition: transform var(--transition-normal);
    z-index: 200;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
}

/* ============================================
   ANIMATIONS
   ============================================ */
@keyframes splash {
    0% { transform: scale(0); opacity: 1; }
    100% { transform: scale(2); opacity: 0; }
}

@keyframes explode {
    0% { transform: scale(1); }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

.cell.animating-miss::before {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    background: var(--color-water-light);
    border-radius: 50%;
    animation: splash 0.5s ease-out forwards;
}

.cell.animating-hit {
    animation: explode 0.3s ease-out;
}
