/* Escape Hormuz — mobile-first dark theme (iteration 3) */

:root {
    --bg:       #0d1117;
    --surface:  #161b22;
    --surface2: #21262d;
    --border:   #30363d;
    --text:     #e6edf3;
    --muted:    #7d8590;
    --accent:   #4a9eff;
    --cyan:     #00e5ff;
    --gold:     #ffd700;
    --danger:   #f85149;
    --success:  #3fb950;

    --radius: 10px;
    --gap: 10px;
}

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

html, body {
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 15px;
    line-height: 1.5;
    overscroll-behavior: none;
}

.screen {
    min-height: 100dvh;
    padding: 16px 14px env(safe-area-inset-bottom, 12px);
    display: flex;
    flex-direction: column;
    gap: var(--gap);
}

.hidden { display: none !important; }

/* --- Typography --- */

.title {
    font-size: 1.8rem;
    font-weight: 700;
    text-align: center;
}

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

/* --- Cards --- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 12px;
}

/* --- Buttons --- */

.primary-btn, .secondary-btn, .action-btn {
    border: none;
    border-radius: var(--radius);
    padding: 12px 20px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    touch-action: manipulation;
    transition: opacity 0.15s, box-shadow 0.15s;
}

.primary-btn {
    background: var(--accent);
    color: #fff;
    width: 100%;
}

.secondary-btn {
    background: var(--surface2);
    color: var(--text);
    border: 1px solid var(--border);
    width: 100%;
}

.primary-btn:active, .secondary-btn:active, .action-btn:active {
    opacity: 0.75;
}

/* --- Join row --- */

.join-row {
    display: flex;
    gap: 8px;
}

.join-row input {
    flex: 1;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 14px;
    color: var(--text);
    font-size: 0.95rem;
}

.join-row input::placeholder {
    color: var(--muted);
}

.join-row .secondary-btn {
    width: auto;
    white-space: nowrap;
}

/* --- User info card --- */

#user-info {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.stat {
    color: var(--muted);
    font-size: 0.85rem;
}

/* --- Error --- */

.error {
    color: var(--danger);
    font-size: 0.88rem;
    padding: 8px 12px;
    border: 1px solid var(--danger);
    border-radius: var(--radius);
    background: rgba(248, 81, 73, 0.08);
}

/* --- Race header --- */

.race-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 600;
}

.badge {
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.badge-waiting  { background: var(--surface2); color: var(--muted); border: 1px solid var(--border); }
.badge-active   { background: rgba(74, 158, 255, 0.15); color: var(--accent); border: 1px solid var(--accent); }
.badge-finished { background: rgba(255, 215, 0, 0.15); color: var(--gold); border: 1px solid var(--gold); }

/* --- Canvas map --- */

.strait-container {
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--border);
    background: #0a2a4a;
    width: 100%;
}

#strait-canvas {
    display: block;
    width: 100%;
}

/* --- Turn info --- */

.turn-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.muted {
    color: var(--muted);
    font-size: 0.85rem;
}

/* --- Player list --- */

.player-row {
    display: grid;
    grid-template-columns: auto 1fr auto;
    grid-template-rows: auto auto;
    gap: 2px 8px;
    align-items: center;
    padding: 7px 0;
    border-bottom: 1px solid var(--border);
}

.player-row:last-child {
    border-bottom: none;
}

.player-boat {
    grid-row: 1 / 3;
    font-size: 1.1rem;
}

.player-name {
    font-weight: 600;
    font-size: 0.9rem;
}

.player-sub {
    grid-row: 1 / 3;
    font-size: 1.1rem;
    text-align: right;
}

.player-stat {
    grid-column: 2;
}

.player-me .player-name {
    color: var(--cyan);
}

/* --- Action panel --- */

.action-panel {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.action-row {
    display: flex;
    gap: 6px;
}

.action-btn {
    flex: 1;
    background: var(--surface2);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 13px 6px;
    font-size: 0.88rem;
    border-radius: var(--radius);
}

.action-btn:hover:not(:disabled) {
    background: var(--surface);
    border-color: var(--accent);
    color: var(--accent);
}

.action-btn.muted-btn {
    color: var(--muted);
}

/* Currently-selected action for the in-flight turn (rapid-tick mode).
   The selection persists until the tick fires; tapping a different
   action moves the highlight (and overwrites server-side). */
.action-btn.action-selected {
    background: var(--accent);
    color: #08151c;
    border-color: var(--accent);
    font-weight: 700;
}
.action-btn.action-selected:hover:not(:disabled) {
    background: var(--accent);
    color: #08151c;
}

/* Disabled state */
.action-btn:disabled,
.action-btn.disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Pulse highlight when it's your turn */
@keyframes turnPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(0, 229, 255, 0); }
    50%       { box-shadow: 0 0 0 4px rgba(0, 229, 255, 0.25); }
}

.action-panel.pulse .action-btn:not(:disabled) {
    animation: turnPulse 1.8s ease-in-out infinite;
    border-color: rgba(0, 229, 255, 0.5);
}

/* Submitted action feedback */
.submitted-action {
    text-align: center;
    font-size: 0.85rem;
    color: var(--success);
    padding: 4px 0;
}

/* --- Back button --- */

.back-btn {
    margin-top: auto;
}

/* --- Waiting room --- */

.waiting-race-id-card {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.waiting-race-label {
    color: var(--muted);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.waiting-race-id-value {
    font-size: 2.8rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    color: var(--cyan);
    font-variant-numeric: tabular-nums;
}

.copy-id-btn {
    width: auto;
    padding: 8px 18px;
    font-size: 0.85rem;
}

.card-header {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
    margin-bottom: 8px;
}

.host-tag {
    display: inline-block;
    font-size: 0.7rem;
    background: rgba(74, 158, 255, 0.15);
    color: var(--accent);
    border: 1px solid var(--accent);
    border-radius: 4px;
    padding: 1px 5px;
    margin-left: 6px;
    vertical-align: middle;
}

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

/* --- Toast --- */

.toast {
    position: fixed;
    bottom: calc(env(safe-area-inset-bottom, 12px) + 16px);
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--surface2);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 10px 18px;
    border-radius: 20px;
    font-size: 0.88rem;
    opacity: 0;
    transition: opacity 0.2s, transform 0.2s;
    pointer-events: none;
    white-space: nowrap;
    z-index: 9999;
}

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

/* --- End / podium screen --- */

.podium-card {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.podium-row {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 10px 4px;
    border-bottom: 1px solid var(--border);
}

.podium-row:last-child {
    border-bottom: none;
}

.podium-medal {
    font-size: 1.6rem;
    width: 2rem;
    text-align: center;
    flex-shrink: 0;
}

.podium-name {
    font-size: 1rem;
    font-weight: 600;
}

.podium-me .podium-name {
    color: var(--cyan);
}

.podium-me {
    background: rgba(0, 229, 255, 0.05);
    border-radius: var(--radius);
}
