@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@400;600;700&family=Noto+Sans+JP:wght@300;400;500&display=swap');

* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #0d0d1a;
    --bg2: #13132b;
    --bg3: #1a1a35;
    --border: #3a3a6e;
    --accent: #c9a227;
    --accent2: #8b5cf6;
    --text: #e8e0f0;
    --text-dim: #9090b0;
    --card-bg: #1e1e3f;
    --card-border: #5a5a9e;
    --card-hover: #2a2a55;
    --win: #4ade80;
    --lose: #f87171;
    --radius: 8px;
}

body {
    font-family: 'Noto Sans JP', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

.battle-popups {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: rgba(5, 6, 18, 0.62);
    backdrop-filter: blur(2px);
    pointer-events: auto;
}

.battle-popups.active {
    display: flex;
}

.battle-popup {
    background: rgba(19,19,43,0.97);
    border: 1px solid var(--border);
    border-left: 8px solid var(--accent2);
    border-radius: 14px;
    box-shadow: 0 18px 44px rgba(0,0,0,0.45);
    padding: 1rem 1.1rem;
    pointer-events: auto;
    animation: popupIn 220ms ease-out both;
    width: min(92vw, 840px);
}

.battle-popup.success {
    border-left-color: var(--win);
}

.battle-popup.warn {
    border-left-color: var(--lose);
}

.battle-popup.notice {
    border-left-color: var(--accent);
}

.battle-popup.hide {
    animation: popupOut 190ms ease-in both;
}

.battle-popup-title {
    font-size: clamp(1.2rem, 3.1vw, 1.9rem);
    color: var(--accent);
    font-weight: 700;
    margin-bottom: 0.35rem;
}

.battle-popup.success .battle-popup-title {
    color: var(--win);
}

.battle-popup.warn .battle-popup-title {
    color: var(--lose);
}

.battle-popup-message {
    font-size: clamp(1rem, 2.25vw, 1.35rem);
    color: var(--text);
    line-height: 1.5;
}

.battle-popup-cards {
    margin-top: 0.65rem;
    display: flex;
    gap: 0.45rem;
    flex-wrap: wrap;
}

.battle-popup-cards .card {
    width: 100px;
    height: 130px;
    flex-shrink: 0;
}

@keyframes popupIn {
    from { opacity: 0; transform: translateY(8px) scale(0.97); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes popupOut {
    from { opacity: 1; transform: translateY(0); }
    to { opacity: 0; transform: translateY(-8px); }
}

h1, h2, h3 { font-family: 'Cinzel', serif; color: var(--accent); }

/* ── Lobby ── */
.lobby-container {
    max-width: 600px;
    margin: 0 auto;
    padding: 2rem 1rem;
}

.lobby-header { text-align: center; margin-bottom: 2rem; }
.lobby-header h1 { font-size: 2.5rem; letter-spacing: 0.1em; }
.lobby-header p { color: var(--text-dim); margin-top: 0.5rem; }

.lobby-card {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.lobby-card h2 { font-size: 1.2rem; margin-bottom: 1rem; }

.form-group { margin-bottom: 1rem; }
.form-group label { display: block; color: var(--text-dim); font-size: 0.85rem; margin-bottom: 0.3rem; }
.form-group input {
    width: 100%;
    padding: 0.6rem 0.8rem;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
    font-size: 1rem;
}
.form-group input:focus { outline: none; border-color: var(--accent2); }

.join-code-display {
    background: var(--bg3);
    border: 2px solid var(--accent);
    border-radius: var(--radius);
    padding: 1rem;
    text-align: center;
    margin: 1rem 0;
}
.join-code-value {
    font-family: 'Cinzel', serif;
    font-size: 2rem;
    color: var(--accent);
    letter-spacing: 0.3em;
}

.status { padding: 0.7rem 1rem; border-radius: 4px; margin-top: 1rem; display: none; }
.status.success { background: rgba(74,222,128,0.1); border: 1px solid var(--win); color: var(--win); }
.status.error { background: rgba(248,113,113,0.1); border: 1px solid var(--lose); color: var(--lose); }

/* ── Buttons ── */
.btn {
    padding: 0.6rem 1.2rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg3);
    color: var(--text);
    cursor: pointer;
    font-size: 0.9rem;
    font-family: inherit;
    transition: all 0.15s;
}
.btn:hover { background: var(--bg2); border-color: var(--accent2); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary { background: var(--accent2); border-color: var(--accent2); font-weight: 500; }
.btn-primary:hover { background: #7c3aed; }
.btn-row { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.5rem; }

/* ── Game Layout ── */
.game-container {
    display: grid;
    grid-template-columns: 1fr;
    grid-auto-rows: max-content;
    height: 100vh;
    max-width: 100%;
    margin: 0 auto;
    padding: 0.5rem;
    gap: 0.5rem;
    align-items: start;
}

.game-header,
.game-board,
.center-col,
.action-panel,
.log-panel {
    grid-column: 1;
}

.game-card-preview-overlay {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    gap: 0.5rem;
    position: fixed;
    inset: 0;
    padding: 0.5rem;
}

.game-card-preview-overlay > .game-container {
    flex: 1 1 auto;
    min-width: 0;
}

.game-card-preview-overlay > .card-preview-panel {
    flex: 0 0 320px;
    width: 320px;
    min-width: 320px;
    max-width: 320px;
}

.card-preview-panel {
    grid-column: auto;
    grid-row: auto;
}

.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.5rem 1rem;
}
.game-header h1 { font-size: 1.2rem; }
.phase-badge {
    background: var(--accent2);
    padding: 0.2rem 0.7rem;
    border-radius: 20px;
    font-size: 0.8rem;
}

.game-board {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    height: 430px;
    min-height: 430px;
    max-height: 430px;
}

.player-area {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.7rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    min-height: 0;
    overflow-y: auto;
}
.player-area.opponent { border-color: rgba(139,92,246,0.4); }
.player-area.me { border-color: rgba(201,162,39,0.4); }

.player-name-tag {
    font-size: 0.85rem;
    color: var(--text-dim);
    font-weight: 500;
}

.field-area {
    height: 96px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.2);
    border: 1px dashed var(--border);
    border-radius: 4px;
    padding: 0.3rem;
    overflow: hidden;
}

.center-col {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.5rem;
	height: 130px;
}

.info-box {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.5rem;
    font-size: 0.8rem;
    min-width: 0;
}
.info-box h4 { color: var(--accent); margin-bottom: 0.3rem; font-size: 0.75rem; }

.pile-stack {
    display: flex;
    flex-flow: row nowrap;
    overflow-x: auto;
    overflow-y: visible;
    min-height: 66px;
    align-items: flex-start;
    padding: 0.5rem 0.4rem 0.35rem 0.2rem;
}

.pile-stack > .card {
    position: relative;
    margin-right: -34px;
    z-index: 1;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.pile-stack > .card:last-child {
    margin-right: 0;
}

.pile-stack > .card:hover {
    z-index: 100;
    transform: translateY(-2px);
    box-shadow: 0 10px 18px rgba(0,0,0,0.45);
}

.pile-stack .empty-text {
    margin-left: 0.1rem;
}

.scoreboard { display: flex; flex-direction: column; gap: 0.3rem; }
.score-item { font-size: 0.8rem; }
.score-item.me { color: var(--accent); }
.wins { font-weight: bold; }

.hand-area {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    height: 96px;
    align-content: flex-start;
    overflow-y: auto;
    overflow-x: hidden;
}

.standby-area {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    height: 96px;
    align-content: flex-start;
    overflow-y: auto;
    overflow-x: hidden;
}

/* ── Cards ── */
.card {
    width: 70px;
    height: 90px;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 6px;
    padding: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    cursor: default;
    transition: all 0.15s;
    position: relative;
    overflow: hidden;
}

.card.anim-deal {
    animation: cardDealIn var(--animation-duration, 260ms) ease-out both;
    animation-delay: var(--stagger, 0ms);
}

.card.anim-move {
    animation: cardMoveIn var(--animation-duration, 240ms) ease-out both;
    animation-delay: var(--stagger, 0ms);
}

.card.anim-flip {
    animation: cardFlipIn var(--animation-duration, 340ms) cubic-bezier(.2,.75,.2,1) both;
    animation-delay: var(--stagger, 0ms);
    transform-style: preserve-3d;
}

@keyframes cardDealIn {
    from { opacity: 0; transform: translateY(-16px) scale(0.95); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes cardMoveIn {
    from { opacity: 0; transform: translateX(14px); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes cardFlipIn {
    0% { opacity: 0.4; transform: perspective(600px) rotateY(90deg) scale(0.97); }
    70% { opacity: 1; transform: perspective(600px) rotateY(-10deg) scale(1.01); }
    100% { opacity: 1; transform: perspective(600px) rotateY(0deg) scale(1); }
}
.card.small { width: 48px; height: 60px; font-size: 0.6rem; border-radius: 3px;}
.pile-stack > .card.small {
    margin-right: -34px;
}
.card-back { background: #11162a; }
.card-number { font-size: 0.6rem; color: var(--text-dim); position: absolute; top: 3px; left: 3px; z-index: 10; }
.card.small .card-number { font-size: 0.5rem; top: 2px; left: 2px; }
.card-face-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: right center;
    display: block;
    background: #0f1222;
}
.card.selected { border-color: var(--accent); background: #2a2a50; box-shadow: 0 0 8px rgba(201,162,39,0.4); }
.card.standby { border-color: var(--accent2); }
.card-selectable .card:hover { background: var(--card-hover); border-color: var(--accent2); cursor: pointer; }
.field-empty { color: var(--text-dim); font-size: 0.8rem; }
.empty-text { color: var(--text-dim); font-size: 0.75rem; }

.card-preview-panel {
    display: flex;
    flex-direction: row;
    gap: 0.6rem;
    align-items: flex-start;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.6rem;
    min-height: auto;
    height: fit-content;
}

.card-preview-image {
    width: 150px;
    height: 195px;
    border: 1px solid var(--card-border);
    border-radius: 8px;
    object-fit: contain;
    object-position: center;
    background: #0f1222;
    flex-shrink: 0;
}

.card-preview-text {
    flex: 1;
    min-width: 0;
    overflow-y: auto;
    max-height: 400px;
}

.card-preview-text h4 {
    font-size: 1rem;
    color: var(--accent);
    margin-bottom: 0.4rem;
}

.card-preview-text p {
    font-size: 0.88rem;
    color: var(--text);
    line-height: 1.55;
}

/* ── Action Panel ── */
.action-panel {
    background: var(--bg2);
    border: 1px solid var(--accent2);
    border-radius: var(--radius);
    padding: 0.8rem;
    height: 170px;
    overflow-y: auto;
}
.action-panel p { margin-bottom: 0.5rem; font-size: 0.9rem; }
.action-panel select {
    background: var(--bg3);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.3rem;
    border-radius: 4px;
    max-width: 100%;
}
.action-panel label { display: inline-flex; align-items: center; gap: 0.3rem; margin-right: 0.5rem; font-size: 0.85rem; }

/* ── Log ── */
.log-panel {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.5rem 0.8rem;
    height: 100px;
    overflow-y: auto;
}
.log-entry {
    font-size: 0.75rem;
    color: var(--text-dim);
    padding: 0.15rem 0;
    border-bottom: 1px solid rgba(255,255,255,0.03);
}

/* ── Game Result ── */
.game-result { text-align: center; padding: 1rem; }
.game-result h2 { font-size: 1.5rem; margin-bottom: 0.5rem; }
.game-result p { color: var(--text-dim); margin-bottom: 1rem; }

/* ── Responsive ── */
@media (max-width: 768px) {
    .game-card-preview-overlay {
        flex-direction: column;
        align-items: stretch;
        padding: 0.35rem;
        gap: 0.35rem;
    }

    .game-card-preview-overlay > .game-container,
    .game-card-preview-overlay > .card-preview-panel {
        flex: 1 1 auto;
    }

    .game-container {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto auto auto auto;
        height: auto;
        padding: 0.35rem;
        gap: 0.35rem;
    }

    .game-header,
    .game-board,
    .center-col,
    .action-panel,
    .log-panel,
    .card-preview-panel {
        grid-column: 1 !important;
        grid-row: auto !important;
    }

    .game-header {
        padding: 0.4rem 0.7rem;
        flex-direction: column;
        gap: 0.3rem;
        align-items: flex-start;
    }

    .game-header h1 { font-size: 1rem; }

    .game-board {
        grid-template-columns: 1fr;
        height: auto;
        min-height: auto;
        max-height: none;
    }

    .player-area {
        padding: 0.5rem;
        gap: 0.35rem;
    }

    .field-area { height: 80px; }

    .center-col {
        grid-template-columns: 1fr;
        height: auto;
    }

    .info-box {
        padding: 0.4rem;
        font-size: 0.75rem;
    }

    .pile-stack {
        min-height: 56px;
        padding: 0.3rem 0.2rem 0.25rem 0.15rem;
    }

    .pile-stack > .card { margin-right: -28px; }
    .pile-stack > .card.small { margin-right: -22px; }

    .card { width: 52px; min-height: 68px; padding: 0; }
    .card.small { width: 40px; min-height: 52px; }

    .card-number { font-size: 0.6rem; top: 2px; left: 3px; }
    .card.small .card-number { font-size: 0.45rem; top: 1px; left: 1px; }

    .hand-area { height: 80px; gap: 0.2rem; }
    .standby-area { height: 80px; gap: 0.2rem; }

    .action-panel {
        height: auto;
        max-height: 120px;
        padding: 0.5rem;
    }

    .action-panel p { font-size: 0.8rem; margin-bottom: 0.3rem; }

    .log-panel {
        height: 80px;
        padding: 0.4rem;
    }

    .log-entry { font-size: 0.7rem; padding: 0.1rem 0; }

    .card-preview-panel {
        flex-direction: column;
        gap: 0.5rem;
        padding: 0.4rem;
        align-items: center;
    }

    .card-preview-image {
        width: 100%;
        max-width: 120px;
        height: auto;
        aspect-ratio: 3 / 4.15;
        border-radius: 6px;
    }

    .card-preview-text h4 {
        font-size: 0.9rem;
        margin-bottom: 0.3rem;
    }

    .card-preview-text p {
        font-size: 0.8rem;
        line-height: 1.4;
    }

    .battle-popup {
        width: min(95vw, 600px);
        padding: 0.8rem;
    }

    .battle-popup-cards .card { width: 80px; height: 104px; }
}

/* ── Ultra-mobile (small phones) ── */
@media (max-width: 480px) {
    .game-container {
        padding: 0.25rem;
        gap: 0.25rem;
    }

    .game-header {
        padding: 0.3rem 0.5rem;
        gap: 0.2rem;
    }

    .game-header h1 { font-size: 0.9rem; }

    #phase-label { font-size: 0.7rem; }

    .player-area { padding: 0.35rem; gap: 0.25rem; }

    .card { width: 46px; min-height: 60px; }
    .card.small { width: 34px; min-height: 45px; }

    .field-area { height: 70px; }
    .hand-area { height: 70px; }
    .standby-area { height: 70px; }

    .center-col { gap: 0.25rem; }

    .info-box {
        padding: 0.35rem;
        font-size: 0.7rem;
    }

    .info-box h4 { font-size: 0.65rem; }

    .pile-stack > .card { margin-right: -22px; }
    .pile-stack > .card.small { margin-right: -16px; }

    .action-panel {
        max-height: 100px;
        padding: 0.4rem;
    }

    .log-panel {
        height: 70px;
        padding: 0.35rem;
    }

    .card-preview-panel {
        flex-direction: column;
        gap: 0.4rem;
        padding: 0.35rem;
        align-items: center;
    }

    .card-preview-image {
        width: 100%;
        max-width: 100px;
        height: auto;
        aspect-ratio: 3 / 4.15;
    }

    .card-preview-text h4 { font-size: 0.8rem; }
    .card-preview-text p { font-size: 0.75rem; }
}
