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

:root {
    --bg-dark: #1a1a2e;
    --bg-medium: #16213e;
    --bg-light: #0f3460;
    --table-green: #1b4d3e;
    --table-green-light: #2d6a4f;
    --text-primary: #e8e8e8;
    --text-secondary: #a0a0a0;
    --accent: #e94560;
    --accent-hover: #ff6b6b;
    --success: #52b788;
    --warning: #f4a261;
    --card-bg: #fefefe;
    --card-border: #ccc;
    --denari: #ffd700;
    --coppe: #4169e1;
    --bastoni: #228b22;
    --spade: #333;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--bg-dark);
    color: var(--text-primary);
    min-height: 100vh;
}

.hidden {
    display: none !important;
}

/* Buttons */
.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    background: var(--bg-light);
    color: var(--text-primary);
    transition: background 0.2s;
}

.btn:hover {
    background: #1a5276;
}

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

.btn-primary {
    background: var(--accent);
}

.btn-primary:hover:not(:disabled) {
    background: var(--accent-hover);
}

.btn-danger {
    background: #c0392b;
}

.btn-danger:hover {
    background: #e74c3c;
}

.btn-small {
    padding: 4px 10px;
    font-size: 12px;
}

.btn-tiny {
    padding: 2px 6px;
    font-size: 10px;
    margin-left: 8px;
}

/* Forms */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    margin-bottom: 4px;
    color: var(--text-secondary);
    font-size: 14px;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--bg-light);
    border-radius: 4px;
    background: var(--bg-medium);
    color: var(--text-primary);
    font-size: 14px;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--accent);
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.checkbox-label input {
    width: auto;
}

.error-msg {
    color: var(--accent);
    font-size: 13px;
    margin-top: 8px;
    min-height: 20px;
}

.form-note {
    color: var(--text-secondary);
    font-size: 13px;
    margin-bottom: 16px;
}

/* Views */
.view {
    min-height: 100vh;
}

/* Auth View */
.auth-container {
    max-width: 400px;
    margin: 0 auto;
    padding: 60px 20px;
    text-align: center;
}

.auth-container h1 {
    font-size: 48px;
    margin-bottom: 8px;
    color: var(--accent);
}

.subtitle {
    color: var(--text-secondary);
    margin-bottom: 40px;
}

.auth-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 24px;
}

.tab-btn {
    flex: 1;
    padding: 10px;
    background: var(--bg-medium);
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
}

.tab-btn:first-child {
    border-radius: 4px 0 0 4px;
}

.tab-btn:last-child {
    border-radius: 0 4px 4px 0;
}

.tab-btn.active {
    background: var(--accent);
    color: var(--text-primary);
}

.auth-form {
    background: var(--bg-medium);
    padding: 24px;
    border-radius: 8px;
    text-align: left;
}

.auth-form h2 {
    text-align: center;
    margin-bottom: 24px;
    font-size: 20px;
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 24px;
    background: var(--bg-medium);
    border-bottom: 1px solid var(--bg-light);
    position: relative;
}

.header h1 {
    font-size: 24px;
    color: var(--accent);
}

.header-user {
    display: flex;
    align-items: center;
    gap: 12px;
}

#user-info {
    color: var(--text-secondary);
}

.table-info {
    display: flex;
    align-items: center;
    gap: 12px;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
}

.table-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-actions {
    min-width: 100px;
}

.user-nickname {
    font-weight: 600;
    color: var(--accent);
}

.badge {
    background: var(--bg-light);
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
}

/* Lobby View */
.lobby-container {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 24px;
    padding: 24px;
    max-width: 1200px;
    margin: 0 auto;
}

.lobby-left h2,
.lobby-right h2 {
    margin-bottom: 16px;
    font-size: 20px;
}

.tables-list {
    background: var(--bg-medium);
    border-radius: 8px;
    padding: 16px;
    max-height: 400px;
    overflow-y: auto;
}

.table-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    background: var(--bg-dark);
    border-radius: 4px;
    margin-bottom: 8px;
}

.table-item:last-child {
    margin-bottom: 0;
}

.table-item-info {
    flex: 1;
}

.table-item-name {
    font-weight: 600;
    margin-bottom: 4px;
}

.table-item-meta {
    font-size: 12px;
    color: var(--text-secondary);
}

.table-item-meta .in-progress {
    color: var(--warning);
}

.join-private {
    margin-top: 24px;
}

.join-private h3 {
    margin-bottom: 12px;
    font-size: 16px;
}

.inline-form {
    display: flex;
    gap: 8px;
}

.inline-form input {
    flex: 1;
    padding: 8px;
    border: 1px solid var(--bg-light);
    border-radius: 4px;
    background: var(--bg-medium);
    color: var(--text-primary);
}

.create-form {
    background: var(--bg-medium);
    padding: 20px;
    border-radius: 8px;
}

.loading {
    color: var(--text-secondary);
    text-align: center;
    padding: 20px;
}

.no-tables {
    color: var(--text-secondary);
    text-align: center;
    padding: 20px;
}

/* Table View */
.table-container {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 16px;
    padding: 16px;
    height: calc(100vh - 60px);
}

.table-main {
    background: var(--table-green);
    border-radius: 8px;
    padding: 20px;
    display: flex;
    flex-direction: column;
}

/* Seats Grid */
.seats-grid {
    flex: 1;
    position: relative;
    display: grid;
    grid-template-columns: 1fr 2fr 1fr;
    grid-template-rows: 1fr 2fr 1fr;
    gap: 12px;
    min-height: 350px;
}

.seat {
    background: var(--table-green-light);
    border-radius: 8px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    position: relative;
}

.seat-top {
    grid-column: 2;
    grid-row: 1;
}

.seat-left {
    grid-column: 1;
    grid-row: 2;
}

.seat-right {
    grid-column: 3;
    grid-row: 2;
}

.seat-bottom {
    grid-column: 2;
    grid-row: 3;
}

.seat-label {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.seat-player {
    font-weight: 600;
    margin-bottom: 4px;
}

.seat-status {
    font-size: 11px;
    color: var(--warning);
}

.seat.occupied .seat-player {
    color: var(--success);
}

.seat.current-turn {
    box-shadow: 0 0 0 3px var(--accent);
}

.seat.is-dealer::after {
    content: "D";
    position: absolute;
    top: 4px;
    right: 4px;
    background: var(--warning);
    color: var(--bg-dark);
    width: 20px;
    height: 20px;
    border-radius: 50%;
    font-size: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
}

.seat.is-caller::after {
    content: "C";
    position: absolute;
    top: 4px;
    left: 4px;
    background: var(--accent);
    color: white;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    font-size: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
}

.seat-btn {
    margin-top: 8px;
    padding: 4px 10px;
    font-size: 11px;
}

.seat-played-card {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Position played cards toward the center of the table */
.seat-top .seat-played-card {
    bottom: -100px;
    left: 50%;
    transform: translateX(-50%);
}

.seat-bottom .seat-played-card {
    top: -100px;
    left: 50%;
    transform: translateX(-50%);
}

.seat-left .seat-played-card {
    right: -85px;
    top: 50%;
    transform: translateY(-50%);
}

.seat-right .seat-played-card {
    left: -85px;
    top: 50%;
    transform: translateY(-50%);
}

.seat-played-card .card {
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
    animation: cardPlay 0.3s ease-out;
}

@keyframes cardPlay {
    from {
        transform: scale(0.5);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

/* Game Area */
.game-area {
    grid-column: 2;
    grid-row: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
}

.trump-indicator {
    position: absolute;
    top: 0;
    background: rgba(0,0,0,0.4);
    padding: 8px 16px;
    border-radius: 4px;
    font-weight: bold;
    font-size: 16px;
}

.turn-indicator {
    position: absolute;
    bottom: 0;
    background: rgba(0,0,0,0.4);
    padding: 6px 14px;
    border-radius: 4px;
    font-size: 14px;
}

.turn-indicator.my-turn {
    background: var(--accent);
    color: white;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.phase-indicator {
    position: absolute;
    top: 0;
    right: 0;
    background: rgba(0,0,0,0.4);
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 12px;
    color: var(--text-secondary);
}


.trick-winner-seat {
    box-shadow: 0 0 0 4px var(--success), 0 0 20px rgba(82, 183, 136, 0.5) !important;
    animation: winPulse 0.5s ease-in-out 2;
}

@keyframes winPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.trick-winner-msg {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--success);
    color: white;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 16px;
    font-weight: bold;
    white-space: nowrap;
    z-index: 100;
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translate(-50%, -50%) scale(0.8); }
    to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

/* Player Hand */
.player-hand {
    margin-top: 16px;
    background: rgba(0,0,0,0.2);
    padding: 16px;
    border-radius: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}

/* Card Styling */
.card {
    width: 70px;
    height: 112px;
    background: transparent;
    border: none;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: default;
    transition: transform 0.15s, box-shadow 0.15s, filter 0.15s;
    position: relative;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    overflow: hidden;
}

.card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 4px;
}

.card.playable {
    cursor: pointer;
    box-shadow: 0 0 0 3px var(--accent), 0 4px 12px rgba(233,69,96,0.3);
    animation: cardGlow 1.5s ease-in-out infinite;
}

@keyframes cardGlow {
    0%, 100% { box-shadow: 0 0 0 3px var(--accent), 0 4px 12px rgba(233,69,96,0.3); }
    50% { box-shadow: 0 0 0 3px var(--accent), 0 4px 20px rgba(233,69,96,0.6); }
}

.card.playable:hover {
    transform: translateY(-12px) scale(1.05);
    box-shadow: 0 0 0 3px var(--accent), 0 8px 20px rgba(0,0,0,0.3);
    animation: none;
}

.card.disabled {
    opacity: 0.4;
    filter: grayscale(60%);
}

/* Trump Selection */
.trump-selection {
    margin-top: 16px;
    background: rgba(0,0,0,0.3);
    padding: 16px;
    border-radius: 8px;
    text-align: center;
}

.trump-selection h3 {
    margin-bottom: 12px;
}

.trump-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.trump-btn {
    width: 80px;
    height: 100px;
    font-size: 14px;
    font-weight: bold;
    border: 3px solid;
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
    background: linear-gradient(135deg, #fff 0%, #f5f5f5 100%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.trump-btn::before {
    font-size: 32px;
}

.trump-btn:hover {
    transform: translateY(-4px) scale(1.05);
    box-shadow: 0 6px 16px rgba(0,0,0,0.25);
}

.trump-btn[data-suit="denari"] {
    border-color: #d4af37;
    background: linear-gradient(135deg, #fffef0 0%, #fff8dc 100%);
}
.trump-btn[data-suit="denari"]::before {
    content: '◆';
    color: #ffd700;
    text-shadow: 0 0 3px rgba(255,215,0,0.5);
}
.trump-btn[data-suit="denari"]::after {
    content: 'Denari';
    color: #b8860b;
    font-size: 12px;
}

.trump-btn[data-suit="coppe"] {
    border-color: #4169e1;
    background: linear-gradient(135deg, #f0f5ff 0%, #e6f0ff 100%);
}
.trump-btn[data-suit="coppe"]::before {
    content: '🏆';
}
.trump-btn[data-suit="coppe"]::after {
    content: 'Coppe';
    color: #1e3a8a;
    font-size: 12px;
}

.trump-btn[data-suit="bastoni"] {
    border-color: #228b22;
    background: linear-gradient(135deg, #f0fff0 0%, #e6ffe6 100%);
}
.trump-btn[data-suit="bastoni"]::before {
    content: '♣';
    color: #228b22;
    text-shadow: 0 0 3px rgba(34,139,34,0.5);
}
.trump-btn[data-suit="bastoni"]::after {
    content: 'Bastoni';
    color: #155724;
    font-size: 12px;
}

.trump-btn[data-suit="spade"] {
    border-color: #4682b4;
    background: linear-gradient(135deg, #f5f9fc 0%, #e8f4fc 100%);
}
.trump-btn[data-suit="spade"]::before {
    content: '⚔';
    color: #4682b4;
    text-shadow: 0 0 3px rgba(70,130,180,0.5);
}
.trump-btn[data-suit="spade"]::after {
    content: 'Spade';
    color: #1e3a5f;
    font-size: 12px;
}

/* Maraffa Prompt */
.maraffa-prompt {
    margin-top: 16px;
    background: rgba(0,0,0,0.3);
    padding: 16px;
    border-radius: 8px;
    text-align: center;
}

.maraffa-prompt h3 {
    color: var(--warning);
    margin-bottom: 8px;
}

.maraffa-prompt p {
    margin-bottom: 12px;
    color: var(--text-secondary);
}

.maraffa-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
}

/* Sidebar */
.table-sidebar {
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow-y: auto;
}

.sidebar-section {
    background: var(--bg-medium);
    border-radius: 8px;
    padding: 16px;
}

.sidebar-section h3 {
    font-size: 14px;
    margin-bottom: 12px;
    color: var(--text-secondary);
}

/* Master Controls */
.game-config {
    margin-bottom: 12px;
}

.game-config label {
    display: block;
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.game-config select {
    width: 100%;
    padding: 6px;
    background: var(--bg-dark);
    border: 1px solid var(--bg-light);
    color: var(--text-primary);
    border-radius: 4px;
}

#start-game-btn {
    width: 100%;
    margin-bottom: 12px;
}

.seat-requests {
    margin-bottom: 12px;
}

.seat-request {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px;
    background: var(--bg-dark);
    border-radius: 4px;
    margin-bottom: 4px;
}

.seat-request-info {
    font-size: 13px;
}

.seat-request-actions {
    display: flex;
    gap: 4px;
}

.transfer-master {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--bg-light);
}

.transfer-master label {
    display: block;
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.transfer-master select {
    width: 100%;
    padding: 6px;
    background: var(--bg-dark);
    border: 1px solid var(--bg-light);
    color: var(--text-primary);
    border-radius: 4px;
    margin-bottom: 8px;
}

/* Game Info */
.scores {
    margin-bottom: 12px;
}

.score-row {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    font-size: 14px;
}

.score-row span:last-child {
    font-weight: bold;
    font-size: 18px;
}

.hand-info {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.tricks-won {
    font-size: 13px;
    color: var(--text-secondary);
}

.maraffa-indicator {
    color: var(--warning);
    font-weight: bold;
    margin-top: 8px;
    padding: 4px 8px;
    background: rgba(244, 162, 97, 0.2);
    border-radius: 4px;
}

/* Users List */
.users-list {
    list-style: none;
}

.users-list li {
    padding: 6px 0;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.users-list .master-badge {
    background: var(--accent);
    color: white;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 10px;
}

.users-list .seated-badge {
    background: var(--success);
    color: white;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 10px;
}

.users-list .me-badge {
    background: var(--accent);
    color: white;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 10px;
}

/* Chat */
.chat-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 200px;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    background: var(--bg-dark);
    border-radius: 4px;
    padding: 8px;
    margin-bottom: 8px;
    max-height: 200px;
    min-height: 100px;
}

.chat-message {
    margin-bottom: 8px;
    font-size: 13px;
}

.chat-message .sender {
    font-weight: 600;
    color: var(--accent);
}

.chat-message .text {
    color: var(--text-primary);
}

.chat-message .timestamp {
    font-size: 10px;
    color: var(--text-secondary);
}

.chat-input {
    display: flex;
    gap: 8px;
}

.chat-input input {
    flex: 1;
    padding: 8px;
    background: var(--bg-dark);
    border: 1px solid var(--bg-light);
    border-radius: 4px;
    color: var(--text-primary);
}

/* Modals */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: var(--bg-medium);
    padding: 32px;
    border-radius: 12px;
    max-width: 400px;
    text-align: center;
}

.modal-content h2 {
    margin-bottom: 16px;
    color: var(--accent);
}

.modal-content .result-scores {
    margin: 20px 0;
}

.modal-content .result-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--bg-light);
}

.modal-content .winner {
    color: var(--success);
    font-weight: bold;
    font-size: 20px;
    margin: 16px 0;
}

.modal-content.victory h3 {
    color: var(--success);
}

.modal-content .result-reason {
    margin-top: 12px;
    color: var(--text-secondary);
    font-style: italic;
}

.modal-content hr {
    border: none;
    border-top: 1px solid var(--bg-light);
    margin: 12px 0;
}

.modal-content button {
    margin-top: 16px;
}

/* MOTD Modal */
.motd-content {
    max-width: 500px;
    text-align: left;
}

.motd-content h2 {
    text-align: center;
}

.motd-content pre {
    white-space: pre-wrap;
    word-wrap: break-word;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--bg-dark);
    padding: 16px;
    border-radius: 8px;
    margin: 16px 0;
    max-height: 300px;
    overflow-y: auto;
}

.motd-content button {
    display: block;
    margin: 16px auto 0;
}

/* Responsive */
@media (max-width: 900px) {
    .lobby-container {
        grid-template-columns: 1fr;
    }

    .table-container {
        grid-template-columns: 1fr;
    }

    .table-sidebar {
        order: -1;
        flex-direction: row;
        flex-wrap: wrap;
    }

    .sidebar-section {
        flex: 1;
        min-width: 200px;
    }
}
