/* ─── Domino CSS Variables ────────────────────────────────────────────────── */
:root {
    --domino-face: #f5f0e8;
    --domino-border: #3a3a5e;
    --domino-pip: #1a1a1a;
    --domino-back: linear-gradient(135deg, #1a2a4a, #2a3a5a);
    --domino-back-pattern: rgba(255,255,255,0.08);
    --domino-selected: var(--gold);
    --domino-playable-glow: rgba(255, 200, 50, 0.4);
    --domino-board-bg: #0a2a1a;
    --domino-divider: #888;
}

/* ─── Tile Base ──────────────────────────────────────────────────────────── */
.domino-tile {
    display: inline-flex;
    align-items: stretch;
    width: 64px;
    height: 32px;
    border: 2px solid var(--domino-border);
    border-radius: 6px;
    background: var(--domino-face);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    position: relative;
    flex-shrink: 0;
}

.domino-tile--vertical {
    flex-direction: column;
    width: 32px;
    height: 64px;
}

.domino-tile--small {
    width: 56px;
    height: 28px;
}

.domino-tile--small.domino-tile--vertical {
    width: 28px;
    height: 56px;
}

.domino-tile--playable {
    box-shadow: 0 0 8px var(--domino-playable-glow), 0 0 16px var(--domino-playable-glow);
    cursor: pointer;
}

.domino-tile--playable:hover {
    transform: translateY(-4px);
    box-shadow: 0 0 12px var(--domino-playable-glow), 0 4px 12px rgba(0,0,0,0.3);
}

.domino-tile--selected {
    transform: translateY(-8px);
    box-shadow: 0 0 16px var(--domino-selected), 0 6px 20px rgba(0,0,0,0.4);
    border-color: var(--domino-selected);
}

.domino-tile--double {
    border-color: var(--gold);
}

/* ─── Tile Back ──────────────────────────────────────────────────────────── */
.domino-tile--back {
    background: var(--domino-back);
    cursor: default;
}

.domino-half--back {
    background: repeating-linear-gradient(
        45deg,
        transparent,
        transparent 3px,
        var(--domino-back-pattern) 3px,
        var(--domino-back-pattern) 4px
    );
}

/* ─── Tile Halves & Pips ─────────────────────────────────────────────────── */
.domino-half {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2px;
}

.domino-divider {
    width: 2px;
    background: var(--domino-divider);
    align-self: stretch;
}

.domino-tile--vertical .domino-divider {
    width: auto;
    height: 2px;
}

.domino-pips {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    width: 100%;
    height: 100%;
    gap: 1px;
}

.domino-pip {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--domino-pip);
    margin: auto;
}

.domino-pip--empty {
    background: transparent;
}

.domino-tile--small .domino-pip {
    width: 4px;
    height: 4px;
}

/* ─── Game Layout ────────────────────────────────────────────────────────── */
.domino-game {
    display: flex;
    flex-direction: column;
    height: calc(100vh - var(--header-h) - var(--nav-bottom-h) - env(safe-area-inset-bottom));
    height: calc(100dvh - var(--header-h) - var(--nav-bottom-h) - env(safe-area-inset-bottom));
    overflow: hidden;
    padding: 8px;
}

.domino-top-area {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 8px;
    min-height: 70px;
}

.domino-opponent-top {
    flex: 1;
    text-align: center;
}

.domino-opponent-left,
.domino-opponent-right {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 2;
}

.domino-opponent-left { left: 4px; }
.domino-opponent-right { right: 4px; }

/* ─── Board Area ─────────────────────────────────────────────────────────── */
.domino-board-area {
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 12px;
    background: var(--domino-board-bg);
    border: 1px solid rgba(255,255,255,0.05);
    margin: 8px 0;
    min-height: 200px;
    max-height: 400px;
    flex: 1;
}

#domino-board {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.domino-board-empty {
    color: var(--text-3);
    font-size: 16px;
}

.domino-board-layout {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.domino-chain--main {
    display: flex;
    align-items: center;
    gap: 2px;
    flex-wrap: nowrap;
}

.domino-chain--north,
.domino-chain--south {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.domino-spinner {
    position: relative;
    margin: 0 4px;
}

/* ─── Player Hand ────────────────────────────────────────────────────────── */
.domino-hand-area {
    padding: 12px 0 8px;
    border-top: 1px solid rgba(255,255,255,0.08);
}

#domino-hand {
    display: flex;
    justify-content: center;
    gap: 6px;
    flex-wrap: wrap;
    padding: 4px 8px;
}

/* ─── End Buttons ────────────────────────────────────────────────────────── */
#domino-end-buttons {
    display: none;
    justify-content: center;
    gap: 8px;
    padding: 8px 0;
    flex-wrap: wrap;
}

.domino-end-btn {
    min-width: 80px;
}

/* ─── Boneyard ───────────────────────────────────────────────────────────── */
#domino-boneyard {
    position: absolute;
    bottom: 8px;
    left: 8px;
}

.domino-boneyard-pile {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: rgba(0,0,0,0.4);
    border-radius: 8px;
}

.domino-boneyard-pile--active {
    border: 1px solid var(--gold);
}

.domino-boneyard-count {
    color: var(--text-2);
    font-size: 13px;
    font-weight: 600;
}

.domino-boneyard-stack {
    position: relative;
}

.domino-draw-btn {
    font-size: 12px;
}

.domino-boneyard-empty {
    color: var(--text-3);
    font-size: 12px;
    padding: 4px 8px;
}

/* ─── Opponents ──────────────────────────────────────────────────────────── */
.domino-opponent-info {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.domino-opponent-name {
    color: var(--text-2);
    font-size: 13px;
    font-weight: 600;
}

.domino-opponent-count {
    color: var(--text-3);
    font-size: 11px;
}

.domino-opponent-tiles {
    display: flex;
    gap: 2px;
}

/* ─── Scores Panel ───────────────────────────────────────────────────────── */
#domino-scores {
    background: rgba(0,0,0,0.3);
    border-radius: 8px;
    padding: 8px 12px;
    min-width: 120px;
}

.domino-score-header {
    font-size: 11px;
    color: var(--text-3);
    margin-bottom: 4px;
    text-align: center;
}

.domino-score-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.domino-score-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    color: var(--text-2);
}

.domino-score-val {
    font-weight: 700;
    color: var(--gold);
}

/* ─── Status Bar ─────────────────────────────────────────────────────────── */
.domino-status {
    text-align: center;
    padding: 6px 12px;
    font-size: 14px;
    font-weight: 600;
    border-radius: 6px;
    margin-bottom: 4px;
}

.domino-status--info { color: var(--cyan); }
.domino-status--success { color: var(--green); }
.domino-status--warning { color: var(--gold); }
.domino-status--error { color: var(--red); }

/* ─── Actions Bar ────────────────────────────────────────────────────────── */
#domino-actions {
    display: flex;
    justify-content: center;
    gap: 8px;
    padding: 4px 0;
}

/* ─── Round Overlay ──────────────────────────────────────────────────────── */
#domino-round-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.domino-overlay-content {
    text-align: center;
    padding: 32px;
    border-radius: 16px;
    background: var(--bg-2);
    border: 1px solid rgba(255,255,255,0.1);
    max-width: 320px;
}

.domino-overlay-content h3 {
    font-size: 22px;
    color: var(--text-1);
    margin-bottom: 12px;
}

.domino-overlay-result {
    color: var(--text-2);
    font-size: 16px;
    margin-bottom: 8px;
}

.domino-overlay-score {
    color: var(--gold);
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 20px;
}

/* ─── Animations ─────────────────────────────────────────────────────────── */
@keyframes domino-place {
    from { transform: scale(1.3); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

@keyframes domino-draw {
    from { transform: translateY(-20px) rotateY(180deg); opacity: 0; }
    to { transform: translateY(0) rotateY(0deg); opacity: 1; }
}

.domino-tile--placed {
    animation: domino-place 0.3s ease-out;
}

.domino-tile--drawn {
    animation: domino-draw 0.4s ease-out;
}

/* ─── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 400px) {
    .domino-tile { width: 52px; height: 26px; }
    .domino-tile--vertical { width: 26px; height: 52px; }
    .domino-tile--small { width: 44px; height: 22px; }
    .domino-tile--small.domino-tile--vertical { width: 22px; height: 44px; }
    .domino-pip { width: 4px; height: 4px; }
    .domino-tile--small .domino-pip { width: 3px; height: 3px; }
    #domino-hand { gap: 3px; }
    .domino-board-area { max-height: 280px; min-height: 160px; }
}

@media (min-width: 768px) {
    .domino-tile { width: 72px; height: 36px; }
    .domino-tile--vertical { width: 36px; height: 72px; }
    .domino-tile--small { width: 60px; height: 30px; }
    .domino-tile--small.domino-tile--vertical { width: 30px; height: 60px; }
    .domino-pip { width: 6px; height: 6px; }
    .domino-tile--small .domino-pip { width: 5px; height: 5px; }
    .domino-board-area { max-height: 350px; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .domino-tile { transition: none; }
    .domino-tile--placed,
    .domino-tile--drawn { animation: none; }
}
