/* app.css */
:root {
    color-scheme: dark;
}

* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
}

body {
    font-family: system-ui, sans-serif;
    margin: 0;
    background: #0f1117;
    color: #ececec;
    display: flex;
    flex-direction: column;
}

#app-root {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.page {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    max-width: 1040px;
    margin: 0 auto;
    padding: 20px clamp(16px, 4vw, 40px) 28px;
    width: 100%;
}

.row {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 14px;
}

.section {
    margin-top: 16px;
}

.table-wrap {
    border: 1px solid #2a2f3a;
    border-radius: 10px;
    overflow: hidden;
    background: #161b22;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    text-align: left;
    padding: 8px 10px;
    border-bottom: 1px solid #242a35;
    font-size: 14px;
}

th {
    background: #1d2430;
    font-size: 12px;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: #a9b6cc;
}

tbody tr:last-child td {
    border-bottom: none;
}

.muted {
    color: #9aa3b2;
    font-size: 13px;
}

.hidden {
    display: none !important;
}

.invisible {
    visibility: hidden !important;
    pointer-events: none !important;
}

.actions {
    white-space: nowrap;
}

.actions form {
    display: inline;
}

button {
    background: #252a34;
    color: #ececec;
    border: 1px solid #434a57;
    padding: 6px 10px;
    border-radius: 8px;
    cursor: pointer;
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

button:hover:not(:disabled) {
    background: #2d333b;
}

input,
select {
    background: #0f1620;
    color: #ececec;
    border: 1px solid #364152;
    border-radius: 6px;
    padding: 6px 8px;
    font-size: 14px;
}

a.nav-link {
    color: #9cc8ff;
    text-decoration: none;
    cursor: pointer;
}

a.nav-link:hover {
    text-decoration: underline;
}

/* Pills and Dots */
.pill {
    display: inline-block;
    padding: 2px 8px;
    border: 1px solid #424b5b;
    border-radius: 999px;
    font-size: 12px;
}

.colorDot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
    border: 1px solid rgba(255, 255, 255, 0.28);
    vertical-align: middle;
    margin-right: 5px;
}

/* Hand Cards (shared between Card List, Deck Builder, In Game) */
.handCardsWrap {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: stretch;
    --hand-card-width: 180px;
    --hand-card-height: 280px;
    margin-top: 12px;
}

.handCard {
    flex: 0 0 var(--hand-card-width);
    width: var(--hand-card-width);
    height: var(--hand-card-height);
    min-height: 0;
    overflow: hidden;
    border: 1px solid #4b5563;
    border-radius: 12px;
    background: #111827;
    color: #f8fafc;
    box-sizing: border-box;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    transition: border-color 120ms ease, transform 120ms ease;
}

.handCard.clickable:hover {
    border-color: #60a5fa;
    cursor: pointer;
    transform: translateY(-1px);
}

.handCard.selected {
    border-color: #7ef2b7;
    box-shadow: 0 0 0 1px rgba(126, 242, 183, 0.35);
}

.handCard.atLimit {
    opacity: 0.6;
    cursor: not-allowed;
}

.handCard.atLimit:hover {
    border-color: #4b5563;
    background: #111827;
    transform: none;
}

.handCard:disabled,
.handCard.handCardDisabled {
    opacity: 0.72;
    cursor: default;
    border-color: #4b5563;
    box-shadow: none;
    transform: none;
}

.handCard:disabled:hover,
.handCard.handCardDisabled:hover {
    border-color: #4b5563;
    transform: none;
}

.handCardTop {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    column-gap: 4px;
    min-width: 0;
}

.handCardTop::after {
    content: attr(data-cost-label);
    background: #1f2937;
    border-radius: 6px;
    padding: 1px 6px 1px 2px;
    font-size: 13px;
    line-height: 1.15;
    font-weight: 700;
    visibility: hidden;
    pointer-events: none;
    white-space: nowrap;
    text-align: left;
}

.handCardCost {
    background: #1f2937;
    border-radius: 6px;
    padding: 1px 6px 1px 2px;
    font-size: 13px;
    line-height: 1.15;
    font-weight: 700;
    justify-self: start;
    text-align: left;
}

.handCard.noAction .handCardCost {
    color: #eab308;
}

.handCard.unaffordable .handCardCost {
    color: #ef4444;
}

.handCardType {
    color: #cbd5e1;
    font-size: 12px;
    line-height: 1.2;
    text-align: center;
}

.handCardName {
    min-width: 0;
    font-size: 13px;
    font-weight: 700;
    line-height: 1.1;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.handCardEmoji {
    text-align: center;
    font-size: 34px;
    line-height: 1;
}

.handCardDesc {
    color: #e5e7eb;
    font-size: 13px;
    line-height: 1.3;
    text-align: left;
    overflow: auto;
    white-space: pre-wrap;
    flex: 1 1 0;
    min-height: 0;
}

/* Deck Builder specific */
.deck-layout {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 20px;
    align-items: start;
    margin-top: 12px;
}

@media (max-width: 900px) {
    .deck-layout {
        grid-template-columns: 1fr;
    }
}

.deckPanel {
    border: 1px solid #2a2f3a;
    border-radius: 10px;
    padding: 16px;
    background: #161b22;
}

.deckPanel h3 {
    margin-top: 0;
}

.deckForm {
    display: grid;
    gap: 10px;
}

.deckForm label {
    font-size: 14px;
}

.deckCount {
    font-size: 13px;
    color: #9aa3b2;
}

.deckCount.valid {
    color: #6ee7b7;
}

.deckCount.invalid {
    color: #f87171;
}

#deckListScroll {
    max-height: 200px;
    overflow-y: auto;
    margin: 10px 0;
    padding: 8px;
    background: #0f1620;
    border-radius: 6px;
    font-size: 13px;
    line-height: 1.5;
}

.deckEntry {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 0;
}

.deckEntry .remove {
    cursor: pointer;
    color: #f87171;
    font-weight: bold;
    padding: 0 4px;
}

.deckEntry .remove:hover {
    color: #fca5a5;
}

/* Lobby specific */
.lobby-layout {
    display: grid;
    grid-template-columns: minmax(250px, 320px) minmax(0, 1fr);
    gap: 16px;
    align-items: start;
    margin-top: 12px;
}

@media (max-width: 860px) {
    .lobby-layout {
        grid-template-columns: 1fr;
    }
}

.stack {
    display: grid;
    gap: 10px;
}

.panel {
    border: 1px solid #2a2f3a;
    border-radius: 10px;
    padding: 12px;
    background: #161b22;
}

.players-list {
    margin: 8px 0 0;
    padding-left: 18px;
}

.players-list li {
    margin: 4px 0;
}

.settings-form {
    display: grid;
    gap: 10px;
    max-width: 320px;
}

.settings-field {
    display: grid;
    gap: 6px;
}

.settings-field label {
    font-size: 14px;
}

.settings-form button {
    justify-self: start;
}

/* Game specific */
#gameMenu {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
    position: relative;
    border: 1px solid #2a2f3a;
    border-radius: 10px;
    padding: 10px;
    background: #161b22;
    margin: 10px;
    overflow: hidden;
}

#gameTopBar {
    --top-side-width: 320px;
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 72px;
}

#topLeftControls {
    flex: 0 0 var(--top-side-width);
    width: var(--top-side-width);
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

#gameLobbyName {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 20px;
    font-weight: 700;
    color: #e5e7eb;
}

#turnBanner {
    flex: 1 1 auto;
    min-width: 0;
    font-size: clamp(34px, 7vw, 72px);
    font-weight: 900;
    letter-spacing: 1px;
    line-height: 1;
    text-transform: uppercase;
    white-space: pre-line;
    text-align: center;
    margin: 0;
    text-shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
}

#topRightControls {
    flex: 0 0 var(--top-side-width);
    width: var(--top-side-width);
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    justify-content: center;
    gap: 8px;
}

#surrenderBtn {
    width: 120px;
    border-color: #991b1b;
    background: #7f1d1d;
    color: #fee2e2;
}

#gameConn {
    min-width: 100px;
    text-align: center;
}

#backHomeBtn {
    width: 120px;
}

#gameText {
    display: none;
}

#gameLayout {
    flex: 1;
    min-height: 0;
    position: relative;
    display: flex;
    flex-direction: row;
    gap: 8px;
    align-items: stretch;
}

#marketPanel {
    flex: 0 0 170px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    border: 1px solid #2a2f3a;
    border-radius: 8px;
    background: #10151d;
    padding: 8px;
    overflow: hidden;
    min-width: 0;
}

#marketPanelTitle {
    color: #e5e7eb;
    font-size: 12px;
    font-weight: 700;
    flex-shrink: 0;
}

#marketCards {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    overflow: hidden;
}

/* Market cards use handCard markup - condensed layout */
#marketCards .handCard {
    min-height: 70px;
    cursor: pointer;
    border: 2px solid #334155;
    border-radius: 10px;
    background: #111827;
    transition: border-color 0.15s;
}

#marketCards .handCard:hover {
    border-color: #60a5fa;
}

#marketCards .handCard.marketCard.disabled {
    cursor: default;
    opacity: 0.7;
}

#marketCards .handCard.marketCard.disabled:hover {
    border-color: #334155;
}

#rerollMarketBtn {
    flex-shrink: 0;
    margin-top: auto;
}

#canvasWrap {
    flex: 1;
    min-width: 0;
    position: relative;
    width: 100%;
    height: 100%;
    min-height: 0;
    border: 1px solid #2f3542;
    border-radius: 8px;
    background: #0c0f14;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

#gameTop {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: row;
    gap: 8px;
    align-items: stretch;
}

#boardCol {
    flex: 1;
    min-width: 0;
    position: relative;
    overflow: hidden;
}

#handRow {
    flex-shrink: 0;
    display: flex;
    flex-direction: row;
    align-items: stretch;
    min-height: 120px;
}

#boardCanvas {
    display: block;
    width: 100%;
    height: 100%;
    cursor: pointer;
}

#handPanel {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: row;
    align-items: stretch;
    gap: 8px;
    overflow: hidden;
    border: 1px solid #2a2f3a;
    border-radius: 10px;
    background: #10151d;
    padding: 8px;
    box-sizing: border-box;
}

#handCardsPanel {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow: hidden;
}

#handPanelTitle {
    flex-shrink: 0;
    color: #e5e7eb;
    font-size: 12px;
    font-weight: 700;
}

#handCards {
    flex: 1;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 10px;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 4px;
    --hand-card-width: 160px;
    --hand-card-height: 100%;
}

#handCards .handCard:hover {
    border-color: #60a5fa;
    background: #111827;
}

#handCards .handCard:disabled:hover,
#handCards .handCard.handCardDisabled:hover {
    border-color: #4b5563;
}

#handRightCol {
    flex-shrink: 0;
    min-width: 180px;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: center;
}

/* Tooltip: aspect ratio 1.2 (height/width) to match in-game hand cards, 280x336 */
#tooltip-root {
    position: fixed;
    z-index: 9999;
    pointer-events: none;
    width: 280px;
}

#tooltip-root.hidden {
    visibility: hidden;
}

.tooltipCard {
    width: 280px;
    height: 336px;
    overflow: hidden;
    border: 2px solid #334155;
    border-radius: 10px;
    background: #111827;
    padding: 10px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.tooltipCardTitle {
    text-align: center;
    font-size: 16px;
    font-weight: 800;
    line-height: 1.2;
}

.tooltipCardHeader {
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: center;
    column-gap: 4px;
    min-width: 0;
}

.tooltipCardHeaderTitle {
    min-width: 0;
    text-align: center;
    font-size: 16px;
    font-weight: 800;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tooltipCardEmoji {
    text-align: center;
    font-size: 48px;
    line-height: 1;
}

.tooltipCardOwner {
    color: #cbd5e1;
    font-size: 13px;
}

.tooltipCardType {
    color: #f8fafc;
    font-size: 12px;
    font-weight: 700;
}

.tooltipCardBody {
    color: #e5e7eb;
    font-size: 13px;
    line-height: 1.35;
    overflow: auto;
    white-space: pre-wrap;
    flex: 1 1 0;
    min-height: 0;
}

.tooltipCardReminders {
    color: #cbd5e1;
    font-size: 12px;
    line-height: 1.4;
    font-style: italic;
    white-space: pre-wrap;
    flex-shrink: 0;
    max-height: 60px;
    overflow: auto;
}

#gameSidePanel {
    flex: 0 0 240px;
    min-width: 200px;
    border: 1px solid #2a2f3a;
    border-radius: 8px;
    padding: 10px;
    background: #10151d;
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow: hidden;
    min-height: 0;
}

.gameSideSection {
    flex: 1 1 0;
    min-height: 0;
    border: 1px solid #2b3647;
    border-radius: 8px;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: rgba(15, 23, 42, 0.45);
    overflow: hidden;
}

.gameSideSection h4 {
    margin: 0;
}

#gamePanelInfo {
    font-size: 12px;
    line-height: 1.45;
    color: #d1d5db;
}

#gamePanelTurnOrder {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-height: 0;
    overflow: auto;
}

.gameTurnRow {
    border: 1px solid #334155;
    border-radius: 8px;
    background: #0f172a;
    padding: 6px 8px;
    font-size: 12px;
    line-height: 1.35;
}

.gameTurnRow.active {
    border-color: #f8fafc;
    background: #1f2937;
}

#gamePanelLog {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 0;
    overflow: auto;
    padding-right: 2px;
}

.gameLogRow {
    border: 1px solid #334155;
    border-radius: 8px;
    background: #0f172a;
    padding: 6px 8px;
    line-height: 1.3;
}

.gameLogMeta {
    color: #e2e8f0;
    font-size: 12px;
    margin-bottom: 3px;
}

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

.gameLogEntry {
    font-size: 12px;
}

.gameLogEntry.gameLogChild {
    padding-left: 1em;
}

.gameLogEntry .gameLogText {
    color: #cbd5e1;
}

.gameLogText {
    color: #cbd5e1;
    font-size: 12px;
}

#endTurnBtn {
    font-size: 18px;
    font-weight: 800;
    letter-spacing: 0.5px;
    padding: 12px 20px;
    border-width: 2px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    min-width: 180px;
    min-height: 128px;
    border-color: #92400e;
    background: #b45309;
    color: #fffbeb;
}