/* STX — Dark theme (gate design system)
   Variables follow gate/theme.css naming convention.
   Dark-only: no light mode toggle needed. */

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

:root {
    /* Backgrounds — Tailwind Gray elevation (900 < 800 < 700) */
    --bg-app: #111827;
    --bg-surface: #1f2937;
    --bg-elevated: #374151;
    --bg-subtle: #293548;
    --bg-input: #1f2937;

    /* Text */
    --text-primary: #f3f4f6;
    --text-secondary: #d1d5db;
    --text-muted: #9ca3af;
    --text-disabled: #6b7280;

    /* Borders */
    --border: #374151;
    --border-input: #4b5563;

    /* Accent (Indigo) */
    --color-primary: #818cf8;
    --color-primary-hover: #6366f1;

    /* Semantic */
    --color-success: #22c55e;
    --color-danger: #ef4444;
    --color-warning: #f59e0b;

    /* Buttons — primary (outline in dark) */
    --btn-primary-bg: transparent;
    --btn-primary-text: #818cf8;
    --btn-primary-border: #818cf8;
    --btn-primary-hover-bg: rgba(99,102,241,0.1);
    --btn-primary-hover-border: #6366f1;

    /* Buttons — danger (outline) */
    --btn-danger-bg: transparent;
    --btn-danger-text: #ef4444;
    --btn-danger-border: #ef4444;

    /* Shadows — none in dark */
    --shadow-card: none;
    --overlay: rgba(0,0,0,0.7);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-app);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
}

h1 {
    font-size: 1.5rem;
    font-weight: 600;
}

.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 1.5rem 0 1rem;
}

.header-center {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.user-info {
    font-size: 0.8125rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.user-info .username {
    color: var(--text-primary);
    font-weight: 500;
}

.user-info a {
    color: var(--color-primary);
    text-decoration: none;
    cursor: pointer;
}

.user-info a:hover {
    text-decoration: underline;
}

.back-to-portal {
    color: var(--text-secondary);
    text-decoration: none;
    padding: 4px 8px;
    border-radius: 6px;
    transition: background 0.2s ease-in-out, color 0.2s ease-in-out;
    line-height: 1;
}

.back-to-portal:hover {
    background: var(--bg-subtle);
    color: var(--text-primary);
}

/* Layout */
.container {
    width: 100%;
    max-width: 480px;
    padding: 0 1rem;
}

/* Setup screen */
.setup {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-top: 2rem;
}

.setup label {
    color: var(--text-muted);
    font-size: 0.875rem;
    margin-bottom: 0.25rem;
}

.difficulty-select {
    display: flex;
    gap: 0.5rem;
}

.difficulty-select button {
    flex: 1;
    padding: 0.5rem;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    color: var(--text-primary);
    border-radius: 7px;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
    font-size: 0.875rem;
}

.difficulty-select button:hover {
    background: var(--bg-elevated);
}

.difficulty-select button.active {
    border-color: var(--color-primary-hover);
    color: var(--color-primary);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 38px;
    padding: 0 1.25rem;
    border-radius: 7px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
    border: 1px solid var(--btn-primary-border);
    background: var(--btn-primary-bg);
    color: var(--btn-primary-text);
}

.btn:hover {
    background: var(--btn-primary-hover-bg);
    border-color: var(--btn-primary-hover-border);
}

.btn-danger {
    border-color: var(--btn-danger-border);
    color: var(--btn-danger-text);
    background: var(--btn-danger-bg);
}

.btn-danger:hover {
    background: rgba(239, 68, 68, 0.08);
}

.btn-sm {
    height: 32px;
    padding: 0 0.75rem;
    font-size: 0.8125rem;
}

/* Game board */
.board {
    display: flex;
    flex-direction: column;
    gap: 2rem;
    margin: 1.5rem 0;
    position: relative;
}

.player-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.player-name {
    font-size: 0.875rem;
    color: var(--text-muted);
}

.player-name.active-turn {
    color: var(--color-primary);
    font-weight: 600;
}

.hands {
    display: flex;
    gap: 1.5rem;
    position: relative;
}

.hand {
    width: 96px;
    height: 120px;
    background: var(--bg-surface);
    border: 2px solid var(--border);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    transition: all 0.2s ease-in-out;
    cursor: default;
    position: relative;
}

.hand .side-label {
    font-size: 0.625rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.hand .finger-count {
    font-size: 2.5rem;
    font-weight: 700;
    line-height: 1;
}

.finger-count.value-changed {
    color: var(--color-danger);
    transition: color 0.8s ease-out;
}

.hand.dead {
    opacity: 0.3;
    border-style: dashed;
}

.hand.dead .finger-count {
    text-decoration: line-through;
    color: var(--text-muted);
}

.hand.selectable {
    cursor: pointer;
    border-color: var(--color-primary-hover);
}

.hand.selectable:hover {
    background: var(--bg-elevated);
    border-color: var(--color-primary);
}

.hand.selected {
    border-color: var(--color-primary);
    background: rgba(99, 102, 241, 0.15);
    box-shadow: 0 0 12px rgba(99, 102, 241, 0.3);
    transform: translateY(-8px);
}

.hand.targetable {
    cursor: pointer;
    border-color: var(--color-warning);
}

.hand.targetable:hover {
    background: rgba(245, 158, 11, 0.15);
    border-color: var(--color-warning);
}

/* Divider */
.divider {
    width: 100%;
    height: 1px;
    background: var(--border);
    position: relative;
}

.divider::after {
    content: 'VS';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--bg-app);
    padding: 0 0.75rem;
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.1em;
}

/* Actions */
.actions {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    margin: 1rem 0;
}

/* Split dialog */
.split-dialog {
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 7px;
    margin: 1rem 0;
}

.split-dialog.visible {
    display: flex;
}

.split-dialog h3 {
    font-size: 0.875rem;
    color: var(--text-muted);
}

.split-options {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
}

.split-option {
    padding: 0.5rem 1rem;
    background: var(--bg-app);
    border: 1px solid var(--border);
    border-radius: 7px;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s ease-in-out;
    font-size: 0.875rem;
}

.split-option:hover {
    border-color: var(--color-primary-hover);
    color: var(--color-primary);
}

/* Status bar */
.status {
    text-align: center;
    padding: 0.75rem;
    font-size: 0.875rem;
    color: var(--text-muted);
    min-height: 2.5rem;
}

.status.your-turn {
    color: var(--color-primary);
    font-weight: 500;
}

.status.game-over {
    font-weight: 600;
}

.status.win {
    color: var(--color-success);
}

.status.lose {
    color: var(--color-danger);
}

.status.draw {
    color: var(--color-warning);
}

/* Log */
.move-log {
    max-height: 150px;
    overflow-y: auto;
    padding: 0.75rem;
    background: var(--bg-surface);
    border-radius: 7px;
    margin: 1rem 0;
    font-size: 0.8125rem;
    color: var(--text-muted);
}

.move-log .entry {
    padding: 0.125rem 0;
}

/* --- Animations --- */

@keyframes lunge {
    0%   { transform: translate(0, 0); }
    35%  { transform: translate(var(--lunge-x, 0), var(--lunge-y, -30px)); }
    100% { transform: translate(0, 0); }
}
.hand.anim-lunge {
    animation: lunge 1000ms ease-in-out;
    z-index: 10;
    box-shadow: 0 0 16px rgba(99, 102, 241, 0.5);
    border-color: var(--color-primary) !important;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    15%      { transform: translateX(-10px); }
    30%      { transform: translateX(10px); }
    45%      { transform: translateX(-8px); }
    60%      { transform: translateX(6px); }
    75%      { transform: translateX(-3px); }
    90%      { transform: translateX(1px); }
}
.hand.anim-hit {
    animation: shake 800ms ease-in-out;
    box-shadow: 0 0 28px rgba(239, 68, 68, 0.7);
    border-color: var(--color-danger) !important;
    background: rgba(239, 68, 68, 0.12);
}

@keyframes number-pop {
    0%   { transform: scale(0.5); opacity: 0; }
    50%  { transform: scale(1.8); opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
}
.finger-count.anim-pop { animation: number-pop 700ms ease-out; }

@keyframes split-pulse {
    0%, 100% { transform: scale(1); }
    50%      { transform: scale(1.08); }
}
.hand.anim-split-pulse { animation: split-pulse 900ms ease-in-out; }

@keyframes float-up {
    0%   { opacity: 1; transform: translateY(0) scale(1); }
    30%  { opacity: 1; transform: translateY(-20px) scale(1.2); }
    100% { opacity: 0; transform: translateY(-50px) scale(0.8); }
}
.split-float {
    position: absolute;
    font-size: 1.5rem;
    font-weight: 700;
    pointer-events: none;
    animation: float-up 1800ms ease-out forwards;
    z-index: 20;
}
.split-float.plus  { color: var(--color-success); }
.split-float.minus { color: var(--color-danger); }

@keyframes orb-fly {
    0%   { opacity: 0; transform: translate(var(--orb-sx, 0), var(--orb-sy, 0)) scale(0.3); }
    15%  { opacity: 1; transform: translate(var(--orb-sx, 0), var(--orb-sy, 0)) scale(1.2); }
    85%  { opacity: 1; transform: translate(var(--orb-ex, 0), var(--orb-ey, 0)) scale(1); }
    100% { opacity: 0; transform: translate(var(--orb-ex, 0), var(--orb-ey, 0)) scale(0.3); }
}
.split-orb {
    position: absolute;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--color-primary);
    box-shadow: 0 0 16px rgba(99, 102, 241, 0.8), 0 0 32px rgba(99, 102, 241, 0.4);
    pointer-events: none;
    z-index: 25;
    opacity: 0;
    animation: orb-fly var(--orb-duration, 600ms) ease-in-out forwards;
}
.split-orb.attack {
    background: var(--color-danger);
    box-shadow: 0 0 16px rgba(239, 68, 68, 0.8), 0 0 32px rgba(239, 68, 68, 0.4);
}

@keyframes death-collapse {
    0%   { transform: scale(1); opacity: 1; box-shadow: 0 0 28px rgba(239, 68, 68, 0.7); }
    30%  { transform: scale(1.02); opacity: 0.9; box-shadow: 0 0 20px rgba(239, 68, 68, 0.4); }
    100% { transform: scale(0.85); opacity: 0.3; box-shadow: none; }
}
.hand.anim-death { animation: death-collapse 1200ms ease-in forwards; }

@keyframes revive-glow {
    0%   { opacity: 0.3; transform: scale(0.85); box-shadow: none; }
    40%  { box-shadow: 0 0 24px rgba(34, 197, 94, 0.7); border-color: var(--color-success); }
    70%  { box-shadow: 0 0 12px rgba(34, 197, 94, 0.3); }
    100% { opacity: 1; transform: scale(1); box-shadow: none; }
}
.hand.anim-revive { animation: revive-glow 1000ms ease-out forwards; }

@keyframes selectable-pulse {
    0%, 100% { box-shadow: 0 0 0 rgba(99, 102, 241, 0); }
    50%      { box-shadow: 0 0 12px rgba(99, 102, 241, 0.3); }
}
.hand.selectable { animation: selectable-pulse 2s ease-in-out infinite; }

/* Rules link */
.rules-link {
    color: var(--text-secondary);
    text-decoration: none;
    padding: 4px 8px;
    border-radius: 6px;
    transition: background 0.2s ease-in-out, color 0.2s ease-in-out;
    line-height: 1;
    display: inline-flex;
}

.rules-link:hover {
    background: var(--bg-subtle);
    color: var(--text-primary);
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: var(--overlay);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 1rem;
}

.modal-overlay.visible {
    display: flex;
}

.modal {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    max-width: 420px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
}

.modal-header h2 {
    font-size: 1.125rem;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0 0.25rem;
    line-height: 1;
    transition: color 0.2s ease-in-out;
}

.modal-close:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: 1.25rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

.modal-body p {
    margin-bottom: 0.75rem;
}

.modal-body strong {
    color: var(--text-primary);
}

/* Responsive */
@media (max-width: 400px) {
    .hand {
        width: 80px;
        height: 100px;
    }
    .hand .finger-count {
        font-size: 2rem;
    }
}
