/* style.css — Green felt table, tiles, layout, animations */

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

:root {
    --felt-green: #1a6b3c;
    --felt-dark: #145830;
    --tile-width: 46px;
    --tile-height: 64px;
    --tile-small: 36px;
    --tile-small-h: 50px;
    --border-radius: 4px;
    --gold: #d4a843;
    --red: #cc3333;
    --blue: #4488cc;
    --text-light: #e8e0d0;
    --panel-bg: rgba(0, 0, 0, 0.4);
}

html, body {
    height: 100%;
    font-family: 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
    background: #0a0a0a;
    color: var(--text-light);
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
}

/* Ensure tiles have visible white background like real tiles */
.tile img {
    background: #f5f0e8;
    border-radius: 3px;
    border: 1px solid #d0c8b0;
}

/* === Board Layout === */

#board {
    width: 100vw;
    height: 100vh;
    background: var(--felt-green);
    background-image:
        radial-gradient(ellipse at center, var(--felt-green) 0%, var(--felt-dark) 100%);
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
}

/* === Top Bar === */

#top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 16px;
    background: var(--panel-bg);
    font-size: 13px;
    z-index: 201;
    flex-shrink: 0;
    position: relative;
}

#round-info {
    font-weight: bold;
    letter-spacing: 0.5px;
}

#dora-display {
    display: flex;
    align-items: center;
    gap: 4px;
}

.dora-label {
    font-size: 12px;
    opacity: 0.8;
    margin-right: 4px;
}

.dora-indicator {
    width: 32px !important;
    height: 44px !important;
}

.dora-indicator img {
    width: 100%;
    height: 100%;
}

/* === Scores Bar === */

#scores-bar {
    display: flex;
    justify-content: center;
    gap: 24px;
    padding: 4px 16px;
    background: var(--panel-bg);
    font-size: 13px;
    flex-shrink: 0;
}

.score-display {
    padding: 2px 10px;
    border-radius: 3px;
}

.score-display.riichi {
    background: var(--red);
    animation: pulse 1s infinite;
}

/* === Main Play Area === */

#play-area {
    display: grid;
    grid-template-columns: 180px 1fr 180px;
    grid-template-rows: 100px 1fr 100px;
    gap: 0;
    padding: 8px;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* Opponents */

.opponent {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 4px;
}

#opponent-top {
    grid-column: 2;
    grid-row: 1;
    flex-direction: column;
}

#opponent-left {
    grid-column: 1;
    grid-row: 2;
}

#opponent-right {
    grid-column: 3;
    grid-row: 2;
}

.opp-info {
    font-size: 11px;
    opacity: 0.9;
    text-align: center;
    white-space: nowrap;
}

.opp-hand {
    display: flex;
    gap: 1px;
    flex-wrap: wrap;
    justify-content: center;
}

.opp-melds {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: center;
}

/* Center area: discard ponds */

#center-area {
    grid-column: 2;
    grid-row: 2;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
}

.discard-pond {
    display: grid;
    grid-template-columns: repeat(6, 32px);
    gap: 2px;
    position: absolute;
}

.discard-pond .tile {
    width: 32px;
    height: 44px;
}

.discard-pond .tile img {
    width: 100%;
    height: 100%;
}

/* Player (bottom) pond — above center */
#discard-pond-0 { bottom: 8px; left: 50%; transform: translateX(-50%); }
/* CPU 2 (top) pond — below center */
#discard-pond-2 { top: 8px; left: 50%; transform: translateX(-50%); }
/* CPU 1 (right) pond */
#discard-pond-1 { right: 8px; top: 50%; transform: translateY(-50%); }
/* CPU 3 (left) pond */
#discard-pond-3 { left: 8px; top: 50%; transform: translateY(-50%); }

/* === Player Area (Bottom) === */

#player-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 6px 16px 10px;
    background: rgba(0, 0, 0, 0.25);
    flex-shrink: 0;
}

#player-hand {
    display: flex;
    gap: 3px;
    justify-content: center;
    align-items: flex-end;
    min-height: var(--tile-height);
    padding: 4px 8px;
}

#player-melds {
    display: flex;
    gap: 12px;
    justify-content: center;
}

/* === Tile Styles === */

.tile {
    width: var(--tile-width);
    height: var(--tile-height);
    border-radius: var(--border-radius);
    overflow: hidden;
    position: relative;
    transition: transform 0.12s, box-shadow 0.12s;
    flex-shrink: 0;
    cursor: default;
}

.tile img {
    width: 100%;
    height: 100%;
    display: block;
    pointer-events: none;
}

.tile.small {
    width: var(--tile-small);
    height: var(--tile-small-h);
}

.tile.clickable {
    cursor: pointer;
}

.tile.clickable:hover {
    transform: translateY(-12px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.5), 0 0 8px rgba(212, 168, 67, 0.6);
    z-index: 5;
}

.tile.drawn {
    margin-left: 12px;
}

.tile.face-down {
    background: #2a7a4a;
    border: 1px solid #3a8a5a;
    border-radius: var(--border-radius);
}

.tile.face-down img {
    background: #2a7a4a;
    border: none;
}

.tile.red-dora img {
    filter: drop-shadow(0 0 3px rgba(255, 0, 0, 0.5));
}

.tile.riichi-sideways {
    transform: rotate(90deg);
    margin: 0 10px;
}

.tile.suggested {
    box-shadow: 0 0 12px 4px var(--gold);
    transform: translateY(-6px);
}

.tile.riichi-valid {
    border: 2px solid var(--gold);
}

.tile.disabled {
    opacity: 0.4;
    pointer-events: none;
}

.tile.called {
    border: 1px solid var(--blue);
}

/* Meld container */

.meld {
    display: flex;
    gap: 2px;
    padding: 2px 4px;
    background: rgba(0, 0, 0, 0.15);
    border-radius: 4px;
}

.meld .tile {
    width: 36px;
    height: 50px;
}

.meld .tile img {
    width: 100%;
    height: 100%;
}

/* === Action Buttons === */

#action-buttons {
    display: flex;
    gap: 8px;
    justify-content: center;
    min-height: 40px;
    padding: 4px;
}

.action-btn {
    padding: 8px 20px;
    font-size: 14px;
    font-weight: bold;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 1px;
    transition: background 0.15s, transform 0.1s;
    color: white;
    background: rgba(255, 255, 255, 0.2);
}

.action-btn:hover {
    transform: translateY(-2px);
    background: rgba(255, 255, 255, 0.3);
}

.action-btn:active {
    transform: translateY(0);
}

.action-tsumo, .action-ron {
    background: var(--red);
}

.action-riichi {
    background: var(--gold);
    color: #1a1a1a;
}

.action-chi {
    background: #2d8a4e;
}

.action-pon {
    background: #c44;
}

.action-kan {
    background: #4466aa;
}

.action-skip {
    background: rgba(255, 255, 255, 0.1);
}

/* === Learning Aids === */

#aids-bar {
    display: flex;
    gap: 6px;
    align-items: center;
    font-size: 12px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

#aids-bar button {
    padding: 3px 10px;
    font-size: 11px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    background: transparent;
    color: var(--text-light);
    border-radius: 3px;
    cursor: pointer;
    transition: background 0.15s;
}

#aids-bar button:hover,
#aids-bar button.active {
    background: rgba(255, 255, 255, 0.2);
}

#shanten-display, #waits-display {
    font-size: 12px;
    margin-left: 8px;
}

.wait-tile {
    display: inline-block;
    background: rgba(255, 255, 255, 0.2);
    padding: 1px 5px;
    border-radius: 3px;
    margin: 0 2px;
    font-weight: bold;
}

/* === Glossary Terms === */

.glossary-term {
    border-bottom: 1px dotted rgba(212, 168, 67, 0.6);
    cursor: help;
    color: inherit;
}

.glossary-term:hover {
    border-bottom-color: var(--gold);
    color: var(--gold);
}

.glossary-tip {
    position: fixed;
    width: 280px;
    padding: 10px 14px;
    background: #12121e;
    border: 1px solid rgba(212, 168, 67, 0.45);
    border-radius: 8px;
    font-size: 12px;
    line-height: 1.55;
    color: rgba(255, 255, 255, 0.9);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.55);
    pointer-events: auto;
    z-index: 30000;
    white-space: normal;
    text-align: left;
    font-weight: normal;
    font-style: normal;
    animation: glossFadeIn 0.12s ease-out;
}

.glossary-tip.gloss-locked {
    border-color: rgba(212, 168, 67, 0.7);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.65), 0 0 0 1px rgba(212, 168, 67, 0.15);
}

.gloss-close {
    position: absolute;
    top: 4px;
    right: 6px;
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.4);
    font-size: 18px;
    cursor: pointer;
    line-height: 1;
    padding: 2px 4px;
    transition: color 0.15s;
    z-index: 1;
}

.gloss-close:hover {
    color: white;
}

.gloss-content {
    padding-right: 16px;
}

@keyframes glossFadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* === Suggest Tooltip === */

.suggest-tooltip {
    position: fixed;
    width: 300px;
    background: #1e1e2e;
    border: 1px solid rgba(212, 168, 67, 0.5);
    border-radius: 10px;
    padding: 14px 18px;
    z-index: 90;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255,255,255,0.04);
    animation: balloonIn 0.2s ease-out;
}

.suggest-close {
    position: absolute;
    top: 6px;
    right: 8px;
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.4);
    font-size: 20px;
    cursor: pointer;
    line-height: 1;
    padding: 2px 4px;
    transition: color 0.15s;
}

.suggest-close:hover {
    color: white;
}

.suggest-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
    font-size: 15px;
    color: var(--gold);
}

.suggest-tile-img {
    width: 36px;
    height: 50px;
    border-radius: 3px;
    background: #f5f0e8;
    border: 1px solid #d0c8b0;
}

.suggest-reasons {
    list-style: none;
    padding: 0;
    margin: 0;
    font-size: 13px;
    line-height: 1.6;
    color: rgba(255, 255, 255, 0.8);
}

.suggest-reasons li {
    padding: 3px 0 3px 16px;
    position: relative;
}

.suggest-reasons li::before {
    content: '•';
    position: absolute;
    left: 2px;
    color: var(--gold);
}

/* === Modal === */

#modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 100;
}

#modal.visible {
    display: flex;
}

.result-modal {
    background: #2a2a2a;
    border-radius: 12px;
    padding: 24px 36px;
    max-width: 700px;
    max-height: 85vh;
    overflow-y: auto;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.result-modal h2 {
    margin-bottom: 16px;
    color: var(--gold);
    font-size: 24px;
}

.result-hand {
    display: flex;
    gap: 3px;
    justify-content: center;
    flex-wrap: wrap;
    margin: 12px 0;
}

.result-tile {
    width: 42px;
    height: 58px;
}

.result-tile img {
    width: 100%;
    height: 100%;
}

.result-meld {
    margin-left: 12px;
    display: inline-flex;
    gap: 2px;
}

.yaku-list-result {
    margin: 12px 0;
    text-align: left;
}

.yaku-item {
    padding: 4px 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 14px;
}

.score-result {
    margin: 16px 0;
    font-size: 18px;
}

.score-total {
    font-size: 28px;
    font-weight: bold;
    color: var(--gold);
    margin-top: 4px;
}

.score-label {
    font-size: 32px;
    font-weight: bold;
    color: var(--red);
    letter-spacing: 4px;
}

.draw-player {
    padding: 6px;
    font-size: 16px;
}

.final-ranking {
    margin: 16px 0;
}

.rank-entry {
    padding: 8px;
    font-size: 18px;
}

.rank-1 { color: var(--gold); font-weight: bold; font-size: 22px; }
.rank-2 { color: #c0c0c0; }
.rank-3 { color: #cd7f32; }

/* === Log Panel === */

#log-panel {
    position: fixed;
    right: 0;
    top: 40px;
    width: 220px;
    height: calc(100vh - 40px);
    background: rgba(0, 0, 0, 0.6);
    overflow-y: auto;
    padding: 8px;
    font-size: 11px;
    z-index: 20;
    border-left: 1px solid rgba(255, 255, 255, 0.1);
}

.log-line {
    padding: 2px 4px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    color: rgba(255, 255, 255, 0.7);
}

/* === Yaku Reference Panel === */

.yaku-reference {
    position: fixed;
    left: 0;
    top: 0;
    width: 320px;
    height: 100vh;
    background: rgba(20, 20, 20, 0.95);
    overflow-y: auto;
    padding: 16px;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.3s;
}

.yaku-reference.visible {
    transform: translateX(0);
}

.yaku-reference h3 {
    margin-bottom: 12px;
    color: var(--gold);
}

.yaku-entry {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 12px;
}

.yaku-name { flex: 1; }
.yaku-jp { flex: 1; text-align: center; opacity: 0.7; }
.yaku-han { width: 50px; text-align: right; color: var(--gold); }

.yaku-reference button {
    margin-top: 12px;
    padding: 6px 16px;
    border: 1px solid var(--text-light);
    background: transparent;
    color: var(--text-light);
    border-radius: 4px;
    cursor: pointer;
}

/* === Start Screen === */

#start-screen {
    display: flex;
    justify-content: center;
    align-items: center;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 200;
    background: rgba(0, 0, 0, 0.75);
}

.start-content {
    text-align: center;
}

.start-title {
    font-size: 48px;
    color: var(--gold);
    margin-bottom: 8px;
    letter-spacing: 3px;
    text-shadow: 0 2px 12px rgba(212, 168, 67, 0.3);
}

.start-subtitle {
    font-size: 16px;
    color: rgba(255, 255, 255, 0.5);
    margin-bottom: 32px;
    letter-spacing: 1px;
}

#start-btn {
    padding: 16px 56px;
    font-size: 24px;
    font-weight: bold;
    background: var(--gold);
    color: #1a1a1a;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    letter-spacing: 2px;
    transition: transform 0.15s, box-shadow 0.15s;
    display: block;
    margin: 0 auto;
}

#start-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 24px rgba(212, 168, 67, 0.4);
}

.start-links {
    margin-top: 20px;
    display: flex;
    gap: 16px;
    justify-content: center;
}

.start-link {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.25);
    color: rgba(255, 255, 255, 0.7);
    padding: 8px 20px;
    font-size: 14px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.start-link:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

.aids-sep {
    color: rgba(255, 255, 255, 0.2);
    margin: 0 2px;
}

#help-btn, #guide-btn, #glossary-btn {
    background: rgba(212, 168, 67, 0.2) !important;
    border-color: rgba(212, 168, 67, 0.4) !important;
    color: var(--gold) !important;
}

#help-btn:hover, #guide-btn:hover, #glossary-btn:hover {
    background: rgba(212, 168, 67, 0.35) !important;
}

/* === Animations === */

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

@keyframes slideIn {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.tile {
    animation: slideIn 0.2s ease-out;
}

/* === Responsive === */

@media (max-width: 1024px) {
    :root {
        --tile-width: 38px;
        --tile-height: 52px;
        --tile-small: 28px;
        --tile-small-h: 38px;
    }

    #log-panel {
        width: 160px;
        font-size: 10px;
    }

    .discard-pond .tile {
        width: 26px;
        height: 36px;
    }
}

@media (max-width: 768px) {
    :root {
        --tile-width: 32px;
        --tile-height: 44px;
        --tile-small: 24px;
        --tile-small-h: 33px;
    }

    #log-panel {
        display: none;
    }

    #play-area {
        grid-template-columns: 80px 1fr 80px;
    }
}

/* ======================================
   SPOTLIGHT TOUR
   ====================================== */

.tour-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10000;
}

.tour-svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.tour-dim {
    fill: rgba(0, 0, 0, 0.75);
    pointer-events: all;
    cursor: pointer;
}

.tour-highlight {
    position: absolute;
    border: 2px solid var(--gold);
    border-radius: 8px;
    box-shadow: 0 0 18px 4px rgba(212, 168, 67, 0.45), inset 0 0 18px 4px rgba(212, 168, 67, 0.08);
    pointer-events: none;
    z-index: 10001;
    animation: tourPulse 1.8s ease-in-out infinite;
}

@keyframes tourPulse {
    0%, 100% { box-shadow: 0 0 18px 4px rgba(212, 168, 67, 0.45), inset 0 0 18px 4px rgba(212, 168, 67, 0.08); }
    50% { box-shadow: 0 0 28px 8px rgba(212, 168, 67, 0.65), inset 0 0 28px 8px rgba(212, 168, 67, 0.12); }
}

.tour-balloon {
    position: absolute;
    width: 380px;
    background: #1e1e2e;
    border: 1px solid rgba(212, 168, 67, 0.4);
    border-radius: 12px;
    padding: 20px 24px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255,255,255,0.05);
    z-index: 10001;
    animation: balloonIn 0.25s ease-out;
}

@keyframes balloonIn {
    from { opacity: 0; transform: translateY(8px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.tour-step-label {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.4);
    margin-bottom: 4px;
    letter-spacing: 1px;
}

.tour-title {
    font-size: 18px;
    font-weight: bold;
    color: var(--gold);
    margin-bottom: 10px;
}

.tour-text {
    font-size: 14px;
    line-height: 1.6;
    color: rgba(255, 255, 255, 0.85);
    white-space: pre-line;
}

.tour-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 18px;
}

.tour-next-btn, .tour-prev-btn {
    padding: 8px 22px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
}

.tour-next-btn {
    background: var(--gold);
    color: #1a1a1a;
}

.tour-next-btn:hover {
    background: #e0b84f;
    transform: translateY(-1px);
}

.tour-prev-btn {
    background: transparent;
    border: 1px solid rgba(255,255,255,0.2);
    color: rgba(255,255,255,0.7);
}

.tour-prev-btn:hover {
    background: rgba(255,255,255,0.1);
}

/* ======================================
   GAME GUIDE OVERLAY
   ====================================== */

.guide-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    z-index: 9000;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    overflow-y: auto;
}

.guide-container {
    width: 760px;
    max-width: 95vw;
    background: #1a1a2a;
    border-radius: 16px;
    margin: 24px auto;
    padding: 36px 44px 44px;
    position: relative;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    overflow-y: auto;
    max-height: calc(100vh - 48px);
}

.guide-close {
    position: sticky;
    top: 0;
    float: right;
    font-size: 32px;
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.5);
    cursor: pointer;
    z-index: 2;
    line-height: 1;
    padding: 0 4px;
    transition: color 0.15s;
}

.guide-close:hover {
    color: white;
}

.guide-container h1 {
    text-align: center;
    font-size: 28px;
    color: var(--gold);
    margin-bottom: 32px;
    padding-right: 30px;
}

.guide-section {
    margin-bottom: 36px;
    padding-bottom: 24px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.guide-section:last-of-type {
    border-bottom: none;
}

.guide-section h2 {
    font-size: 20px;
    color: var(--gold);
    margin-bottom: 12px;
    padding-bottom: 6px;
    border-bottom: 2px solid rgba(212, 168, 67, 0.3);
}

.guide-section h3 {
    font-size: 15px;
    color: rgba(255, 255, 255, 0.9);
    margin: 16px 0 8px;
}

.guide-section p {
    font-size: 14px;
    line-height: 1.7;
    color: rgba(255, 255, 255, 0.8);
    margin-bottom: 8px;
}

.guide-section ul {
    margin: 8px 0 8px 20px;
    font-size: 14px;
    line-height: 1.7;
    color: rgba(255, 255, 255, 0.8);
}

.guide-tile {
    width: 40px;
    height: 56px;
    border-radius: 4px;
    background: #f5f0e8;
    border: 1px solid #d0c8b0;
    vertical-align: middle;
}

.guide-tile-row {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    align-items: center;
    margin: 8px 0;
}

.guide-group-sep {
    display: inline-block;
    width: 10px;
}

.guide-caption {
    font-size: 12px !important;
    color: rgba(255, 255, 255, 0.5) !important;
    font-style: italic;
}

.guide-note {
    font-size: 13px !important;
    color: rgba(255, 200, 100, 0.7) !important;
}

.guide-example {
    background: rgba(255, 255, 255, 0.03);
    border-radius: 8px;
    padding: 14px 18px;
    margin: 12px 0;
    border-left: 3px solid rgba(212, 168, 67, 0.4);
}

.guide-example h3 {
    margin-top: 0 !important;
}

.guide-arrow {
    font-size: 24px;
    margin: 0 12px;
    color: var(--gold);
}

/* Turn flow diagram */
.guide-flow {
    display: flex;
    align-items: center;
    gap: 0;
    flex-wrap: wrap;
    justify-content: center;
    margin: 16px 0;
}

.guide-flow-step {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    padding: 14px 16px;
    width: 140px;
    font-size: 13px;
    line-height: 1.5;
    text-align: center;
    color: rgba(255, 255, 255, 0.8);
}

.guide-flow-arrow {
    font-size: 20px;
    color: var(--gold);
    margin: 0 4px;
}

.flow-num {
    display: inline-block;
    width: 24px;
    height: 24px;
    line-height: 24px;
    text-align: center;
    border-radius: 50%;
    background: var(--gold);
    color: #1a1a1a;
    font-weight: bold;
    font-size: 13px;
    margin-bottom: 6px;
}

/* Call cards */
.guide-call {
    background: rgba(255, 255, 255, 0.03);
    border-radius: 8px;
    padding: 14px 18px;
    margin: 10px 0;
}

.guide-call-header {
    display: inline-block;
    padding: 4px 16px;
    border-radius: 4px;
    font-weight: bold;
    font-size: 15px;
    color: white;
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.call-chi { background: #2d8a4e; }
.call-pon { background: #c44; }
.call-kan { background: #4466aa; }
.call-ron { background: #cc3333; }
.call-tsumo { background: #cc3333; }

.guide-info {
    background: rgba(68, 136, 204, 0.12);
    border: 1px solid rgba(68, 136, 204, 0.3);
    border-radius: 8px;
    padding: 12px 16px;
    margin: 12px 0;
    font-size: 14px;
    color: rgba(255, 255, 255, 0.85);
}

.guide-warning {
    background: rgba(204, 150, 50, 0.12);
    border-color: rgba(204, 150, 50, 0.3);
}

/* Yaku table */
.guide-yaku-table, .guide-score-table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
    font-size: 13px;
}

.guide-yaku-table th, .guide-score-table th {
    background: rgba(212, 168, 67, 0.15);
    color: var(--gold);
    padding: 8px 12px;
    text-align: left;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.guide-yaku-table td, .guide-score-table td {
    padding: 7px 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    color: rgba(255, 255, 255, 0.8);
}

.guide-yaku-table tr:hover, .guide-score-table tr:hover {
    background: rgba(255, 255, 255, 0.03);
}

/* Tips */
.guide-tips {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.guide-tip {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    background: rgba(255, 255, 255, 0.03);
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 14px;
    line-height: 1.6;
    color: rgba(255, 255, 255, 0.8);
}

.tip-num {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--gold);
    color: #1a1a1a;
    font-weight: bold;
    font-size: 14px;
    flex-shrink: 0;
    margin-top: 1px;
}

/* Footer */
.guide-footer {
    text-align: center;
    margin-top: 24px;
}

.guide-close-btn {
    padding: 14px 40px;
    font-size: 16px;
    font-weight: bold;
    background: var(--gold);
    color: #1a1a1a;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
    letter-spacing: 0.5px;
}

.guide-close-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(212, 168, 67, 0.4);
}

/* === Glossary Panel === */

.glossary-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    z-index: 9000;
    display: flex;
    justify-content: center;
    align-items: flex-start;
}

.glossary-panel {
    width: 600px;
    max-width: 95vw;
    background: #1a1a2a;
    border-radius: 16px;
    margin: 24px auto;
    padding: 36px 44px 44px;
    position: relative;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    overflow-y: auto;
    max-height: calc(100vh - 48px);
}

.glossary-panel h1 {
    text-align: center;
    font-size: 28px;
    color: var(--gold);
    margin-bottom: 20px;
    padding-right: 30px;
}

.glossary-search-wrap {
    position: sticky;
    top: 0;
    z-index: 2;
    padding: 0 0 16px;
    background: #1a1a2a;
}

.glossary-search {
    width: 100%;
    padding: 10px 16px;
    font-size: 15px;
    background: #12121e;
    border: 1px solid rgba(212, 168, 67, 0.35);
    border-radius: 8px;
    color: var(--text-light);
    outline: none;
    transition: border-color 0.2s;
}

.glossary-search::placeholder {
    color: rgba(255, 255, 255, 0.35);
}

.glossary-search:focus {
    border-color: var(--gold);
}

.glossary-cat {
    margin-bottom: 24px;
}

.glossary-cat h2 {
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--gold);
    opacity: 0.8;
    margin-bottom: 10px;
    padding-bottom: 6px;
    border-bottom: 1px solid rgba(212, 168, 67, 0.15);
}

.glossary-entry {
    display: flex;
    gap: 12px;
    padding: 8px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    align-items: baseline;
}

.glossary-entry:last-child {
    border-bottom: none;
}

.glossary-entry-term {
    flex-shrink: 0;
    width: 110px;
    font-weight: 600;
    color: var(--gold);
    font-size: 14px;
}

.glossary-entry-def {
    flex: 1;
    font-size: 13px;
    color: rgba(255, 255, 255, 0.8);
    line-height: 1.5;
}

.glossary-exact {
    background: rgba(212, 168, 67, 0.1);
    border: 1px solid rgba(212, 168, 67, 0.35);
    border-radius: 8px;
    padding: 12px 14px;
    margin-bottom: 16px;
    box-shadow: 0 2px 12px rgba(212, 168, 67, 0.1);
}

.glossary-related-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: rgba(255, 255, 255, 0.35);
    margin-bottom: 12px;
    padding-bottom: 4px;
}

.glossary-empty {
    text-align: center;
    color: rgba(255, 255, 255, 0.4);
    padding: 40px 0;
    font-size: 15px;
}

/* ======================================
   ORIENTATION PROMPT
   ====================================== */

#orientation-prompt {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.92);
    z-index: 99999;
    justify-content: center;
    align-items: center;
    text-align: center;
    color: var(--text-light);
    font-size: 18px;
    padding: 24px;
}

@media (max-width: 600px) and (orientation: landscape) {
    #orientation-prompt {
        display: flex;
    }
}

/* ======================================
   MOBILE LANDSCAPE
   ====================================== */

@media (max-height: 500px) and (orientation: landscape) {

    :root {
        --tile-width: 28px;
        --tile-height: 38px;
        --tile-small: 16px;
        --tile-small-h: 22px;
    }

    /* --- Top Bar & Scores Compression --- */

    #top-bar {
        padding: 2px 8px;
        font-size: 10px;
        gap: 6px;
    }

    #aids-bar {
        gap: 4px;
        font-size: 10px;
    }

    #aids-bar button {
        padding: 2px 5px;
        font-size: 9px;
    }

    #shanten-display, #waits-display {
        display: none;
    }

    .dora-indicator {
        width: 22px !important;
        height: 30px !important;
    }

    .dora-label {
        font-size: 10px;
    }

    .aids-sep {
        display: none;
    }

    #scores-bar {
        padding: 2px 8px;
        font-size: 10px;
        gap: 6px;
    }

    .score-display {
        padding: 1px 6px;
    }

    /* --- Play Area Grid Restructure --- */

    #play-area {
        grid-template-columns: 1fr 1fr 1fr;
        grid-template-rows: auto 1fr;
        padding: 2px 4px;
    }

    #opponent-right {
        grid-column: 1;
        grid-row: 1;
    }

    #opponent-top {
        grid-column: 2;
        grid-row: 1;
    }

    #opponent-left {
        grid-column: 3;
        grid-row: 1;
    }

    #center-area {
        grid-column: 1 / -1;
        grid-row: 2;
    }

    /* --- Opponent Compression --- */

    .opponent {
        flex-direction: row;
        max-height: 32px;
        overflow: hidden;
        gap: 4px;
        padding: 2px 4px;
        justify-content: flex-start;
    }

    .opp-info {
        font-size: 9px;
        white-space: nowrap;
        min-width: 0;
    }

    .opp-hand {
        gap: 0;
    }

    .opp-hand .tile.small {
        width: 10px;
        height: 16px;
        margin: 0 -2px;
    }

    .opp-hand .tile.small img {
        display: none;
    }

    .opp-hand .tile.small.face-down {
        background: #2a7a4a;
        border: 1px solid #3a8a5a;
    }

    .opp-melds {
        gap: 3px;
    }

    .opp-melds .meld {
        gap: 1px;
        padding: 1px 2px;
    }

    .opp-melds .meld .tile {
        width: 14px;
        height: 20px;
    }

    /* --- Discard Ponds --- */

    .discard-pond {
        grid-template-columns: repeat(6, 18px);
        gap: 1px;
    }

    .discard-pond .tile {
        width: 18px;
        height: 24px;
    }

    .discard-pond .tile.riichi-sideways {
        margin: 0 4px;
    }

    #discard-pond-0 { bottom: 4px; }
    #discard-pond-2 { top: 4px; }
    #discard-pond-1 { right: 4px; }
    #discard-pond-3 { left: 4px; }

    /* --- Player Area --- */

    #player-area {
        padding: 2px 8px 4px;
        gap: 2px;
    }

    #player-hand {
        gap: 2px;
        padding: 2px 4px;
        min-height: var(--tile-height);
    }

    #player-melds {
        gap: 6px;
    }

    .tile.drawn {
        margin-left: 6px;
    }

    .meld .tile {
        width: 24px;
        height: 34px;
    }

    /* Reduce gap between melds and hand */
    #player-area > div {
        gap: 6px;
    }

    /* --- Action Buttons --- */

    #action-buttons {
        min-height: 28px;
        padding: 2px;
        gap: 6px;
    }

    .action-btn {
        padding: 4px 10px;
        font-size: 11px;
        min-height: 32px;
        letter-spacing: 0.5px;
    }

    /* --- Modals --- */

    .result-modal {
        padding: 12px 16px;
        max-width: 90vw;
        max-height: 80vh;
    }

    .result-modal h2 {
        font-size: 18px;
        margin-bottom: 8px;
    }

    .result-tile {
        width: 28px;
        height: 38px;
    }

    .result-meld {
        margin-left: 6px;
    }

    .yaku-item {
        font-size: 12px;
        padding: 3px 8px;
    }

    .score-result {
        margin: 8px 0;
        font-size: 14px;
    }

    .score-total {
        font-size: 20px;
    }

    .score-label {
        font-size: 22px;
        letter-spacing: 2px;
    }

    /* --- Tour & Guide --- */

    .tour-balloon {
        width: min(90vw, 300px);
        padding: 12px 16px;
    }

    .tour-title {
        font-size: 14px;
        margin-bottom: 6px;
    }

    .tour-text {
        font-size: 12px;
        line-height: 1.5;
    }

    .tour-nav {
        margin-top: 10px;
    }

    .tour-next-btn, .tour-prev-btn {
        padding: 6px 14px;
        font-size: 12px;
    }

    .guide-container {
        width: 95vw;
        padding: 16px 20px;
        margin: 8px auto;
    }

    .guide-container h1 {
        font-size: 20px;
        margin-bottom: 16px;
    }

    .guide-section h2 {
        font-size: 16px;
    }

    .glossary-panel {
        width: 95vw;
        padding: 16px 20px;
        margin: 8px auto;
    }

    .glossary-panel h1 {
        font-size: 20px;
        margin-bottom: 12px;
    }

    .yaku-reference {
        width: 280px;
    }

    /* --- Start Screen --- */

    .start-title {
        font-size: 28px;
    }

    .start-subtitle {
        font-size: 13px;
        margin-bottom: 16px;
    }

    #start-btn {
        padding: 10px 36px;
        font-size: 18px;
    }

    .start-links {
        margin-top: 12px;
        gap: 10px;
    }

    .start-link {
        padding: 6px 14px;
        font-size: 12px;
    }

    /* --- Log Panel --- */

    #log-panel {
        display: none;
    }

    /* --- Suggest Tooltip --- */

    .suggest-tooltip {
        width: min(90vw, 280px);
        padding: 10px 14px;
    }
}

/* ======================================
   MOBILE PORTRAIT
   ====================================== */

@media (max-width: 600px) and (orientation: portrait) {

    :root {
        --tile-width: 24px;
        --tile-height: 33px;
        --tile-small: 14px;
        --tile-small-h: 20px;
    }

    /* Hide orientation prompt in portrait */
    #orientation-prompt { display: none !important; }

    /* --- Top Bar & Scores --- */

    #top-bar {
        padding: 4px 8px;
        font-size: 10px;
        gap: 4px;
        flex-wrap: wrap;
    }

    #aids-bar {
        gap: 3px;
        font-size: 10px;
    }

    #aids-bar button {
        padding: 2px 6px;
        font-size: 9px;
    }

    #shanten-display, #waits-display {
        display: none;
    }

    .dora-indicator {
        width: 20px !important;
        height: 28px !important;
    }

    .dora-label {
        font-size: 9px;
    }

    .aids-sep {
        display: none;
    }

    #scores-bar {
        padding: 3px 8px;
        font-size: 10px;
        gap: 4px;
        flex-wrap: wrap;
    }

    .score-display {
        padding: 1px 5px;
    }

    /* --- Play Area: opponents on top, center below --- */

    #play-area {
        grid-template-columns: 1fr 1fr 1fr;
        grid-template-rows: auto 1fr;
        padding: 2px 4px;
    }

    #opponent-left {
        grid-column: 1;
        grid-row: 1;
    }

    #opponent-top {
        grid-column: 2;
        grid-row: 1;
    }

    #opponent-right {
        grid-column: 3;
        grid-row: 1;
    }

    #center-area {
        grid-column: 1 / -1;
        grid-row: 2;
    }

    /* --- Opponents (compact columns) --- */

    .opponent {
        flex-direction: column;
        gap: 2px;
        padding: 2px;
        align-items: center;
        justify-content: flex-start;
    }

    .opp-info {
        font-size: 9px;
        white-space: nowrap;
    }

    .opp-hand {
        gap: 0;
    }

    .opp-hand .tile.small {
        width: 8px;
        height: 14px;
        margin: 0 -1px;
    }

    .opp-hand .tile.small img {
        display: none;
    }

    .opp-hand .tile.small.face-down {
        background: #2a7a4a;
        border: 1px solid #3a8a5a;
    }

    .opp-melds {
        gap: 2px;
    }

    .opp-melds .meld {
        gap: 1px;
        padding: 1px 2px;
    }

    .opp-melds .meld .tile {
        width: 12px;
        height: 18px;
    }

    /* --- Discard Ponds --- */

    .discard-pond {
        grid-template-columns: repeat(6, 18px);
        gap: 1px;
    }

    .discard-pond .tile {
        width: 18px;
        height: 25px;
    }

    .discard-pond .tile.riichi-sideways {
        margin: 0 5px;
    }

    #discard-pond-0 { bottom: 4px; }
    #discard-pond-2 { top: 4px; }
    #discard-pond-1 { right: 4px; }
    #discard-pond-3 { left: 4px; }

    /* --- Player Area --- */

    #player-area {
        padding: 4px 6px 8px;
        gap: 4px;
    }

    /* Stack hand and melds vertically in portrait */
    #player-area > div {
        flex-direction: column;
        align-items: center;
        gap: 4px;
    }

    #player-hand {
        gap: 1px;
        padding: 2px 2px;
        min-height: var(--tile-height);
    }

    #player-melds {
        gap: 4px;
    }

    .tile.drawn {
        margin-left: 4px;
    }

    .meld .tile {
        width: 20px;
        height: 28px;
    }

    /* --- Action Buttons --- */

    #action-buttons {
        min-height: 32px;
        padding: 2px;
        gap: 6px;
    }

    .action-btn {
        padding: 6px 12px;
        font-size: 11px;
        min-height: 36px;
        letter-spacing: 0.5px;
    }

    /* --- Modals --- */

    .result-modal {
        padding: 16px 20px;
        max-width: 95vw;
        max-height: 85vh;
    }

    .result-modal h2 {
        font-size: 18px;
        margin-bottom: 8px;
    }

    .result-tile {
        width: 28px;
        height: 38px;
    }

    .result-meld {
        margin-left: 6px;
    }

    .yaku-item {
        font-size: 12px;
        padding: 3px 8px;
    }

    .score-result {
        margin: 8px 0;
        font-size: 14px;
    }

    .score-total {
        font-size: 22px;
    }

    .score-label {
        font-size: 24px;
        letter-spacing: 2px;
    }

    /* --- Tour & Guide --- */

    .tour-balloon {
        width: min(90vw, 320px);
        padding: 14px 16px;
    }

    .tour-title {
        font-size: 15px;
        margin-bottom: 8px;
    }

    .tour-text {
        font-size: 13px;
        line-height: 1.5;
    }

    .tour-nav {
        margin-top: 12px;
    }

    .tour-next-btn, .tour-prev-btn {
        padding: 6px 16px;
        font-size: 12px;
    }

    .guide-container {
        width: 95vw;
        padding: 16px 20px;
        margin: 8px auto;
    }

    .guide-container h1 {
        font-size: 22px;
        margin-bottom: 16px;
    }

    .guide-section h2 {
        font-size: 16px;
    }

    .glossary-panel {
        width: 95vw;
        padding: 16px 20px;
        margin: 8px auto;
    }

    .glossary-panel h1 {
        font-size: 20px;
        margin-bottom: 12px;
    }

    .yaku-reference {
        width: 280px;
    }

    /* --- Start Screen --- */

    .start-title {
        font-size: 32px;
    }

    .start-subtitle {
        font-size: 14px;
        margin-bottom: 20px;
    }

    #start-btn {
        padding: 14px 44px;
        font-size: 20px;
    }

    .start-links {
        margin-top: 16px;
        gap: 10px;
    }

    .start-link {
        padding: 8px 20px;
        font-size: 13px;
    }

    /* --- Log & Suggest --- */

    #log-panel {
        display: none;
    }

    .suggest-tooltip {
        width: min(90vw, 300px);
        padding: 10px 14px;
    }
}

/* ======================================
   TOUCH DEVICE STYLES
   ====================================== */

@media (hover: none) {
    .tile.clickable:hover {
        transform: none;
        box-shadow: none;
    }

    .tile.clickable:active {
        transform: translateY(-6px);
        box-shadow: 0 6px 16px rgba(0, 0, 0, 0.5), 0 0 8px rgba(212, 168, 67, 0.6);
        z-index: 5;
    }

    .action-btn {
        min-height: 36px;
        min-width: 44px;
    }

    .action-btn:hover {
        transform: none;
    }

    .action-btn:active {
        transform: translateY(-2px);
        background: rgba(255, 255, 255, 0.3);
    }

    #start-btn:hover {
        transform: none;
        box-shadow: none;
    }

    #start-btn:active {
        transform: translateY(-3px);
        box-shadow: 0 8px 24px rgba(212, 168, 67, 0.4);
    }
}
