/* =========================================================
   超次元麻雀 — UI スタイル
   ========================================================= */
:root {
    --bg: #05040f;
    --panel: rgba(14, 12, 38, 0.86);
    --panel-2: rgba(28, 22, 70, 0.92);
    --line: rgba(160, 140, 255, 0.35);
    --text: #f1eefc;
    --muted: #a9a3c9;
    --gold: #f5c84c;
    --gold-2: #ffe9a3;
    --accent: #7b5cff;
    --accent-2: #36d6ff;
    --red: #ff4d6d;
    --green: #3ddc97;
    --font: "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
    --serif: "Hiragino Mincho ProN", "Yu Mincho", "MS PMincho", serif;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    user-select: none;
}

#three-root {
    position: fixed;
    inset: 0;
}

#three-root canvas {
    display: block;
}

#three-root.shake {
    animation: shake 0.6s linear 2;
}

@keyframes shake {
    0%, 100% {
        transform: translate(0, 0);
    }
    20% {
        transform: translate(-8px, 5px);
    }
    40% {
        transform: translate(7px, -6px);
    }
    60% {
        transform: translate(-6px, -4px);
    }
    80% {
        transform: translate(5px, 6px);
    }
}

.hidden {
    display: none !important;
}

/* 牌画像（HTML表示）：画像は枠なしのベタ塗りなので、縁と背の色をCSSで付ける */
img.tile-img {
    aspect-ratio: 3 / 4;
    border-radius: 9% / 7%;
    background: #F4F1E8;
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.18), 0 0 0 1px rgba(20, 14, 60, 0.55), 0 3px 0 #3B2BB8, 0 4px 6px rgba(0, 0, 0, 0.45);
    margin-bottom: 4px;
    vertical-align: bottom;
}

/* ---------- 共通ボタン ---------- */
.btn {
    font-family: var(--font);
    font-size: 15px;
    color: var(--text);
    background: linear-gradient(180deg, #3a2f86, #221a5a);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 10px 18px;
    cursor: pointer;
    transition: transform 0.08s, box-shadow 0.15s, filter 0.15s;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
}

.btn:hover {
    filter: brightness(1.25);
    box-shadow: 0 0 14px rgba(123, 92, 255, 0.6);
}

.btn:active {
    transform: translateY(1px) scale(0.98);
}

.btn.primary {
    background: linear-gradient(180deg, #ffd769, #c48a12);
    color: #2b1a00;
    font-weight: bold;
    border-color: #ffe9a3;
}

.btn.big {
    font-size: 20px;
    padding: 14px 34px;
}

.btn.small {
    font-size: 13px;
    padding: 6px 12px;
}

.btn.close {
    position: absolute;
    top: 10px;
    right: 10px;
}

/* ---------- 全画面 ---------- */
.screen {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
}

#loading {
    background: radial-gradient(ellipse at center, #1c1450 0%, #05040f 70%);
    z-index: 100;
}

.loading-box {
    text-align: center;
    width: min(420px, 90vw);
}

#loading-text {
    margin: 18px 0 10px;
    color: var(--muted);
}

.bar {
    height: 8px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.1);
    overflow: hidden;
}

#loading-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--accent), var(--accent-2));
    transition: width 0.2s;
}

.logo {
    font-family: var(--serif);
    font-size: clamp(42px, 8vw, 84px);
    font-weight: 900;
    letter-spacing: 0.12em;
    background: linear-gradient(180deg, #fff6d2 0%, var(--gold) 45%, #b06a00 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    filter: drop-shadow(0 0 18px rgba(123, 92, 255, 0.8));
}

.logo.small {
    font-size: 40px;
}

#title {
    background: radial-gradient(ellipse at center, rgba(30, 20, 80, 0.55) 0%, rgba(5, 4, 15, 0.2) 70%);
}

.title-box {
    text-align: center;
    padding: 30px 36px;
    border-radius: 20px;
    background: rgba(10, 8, 30, 0.6);
    border: 1px solid var(--line);
    backdrop-filter: blur(4px);
    max-width: 92vw;
}

.subtitle {
    color: var(--muted);
    margin: 6px 0 22px;
    letter-spacing: 0.08em;
    font-size: 14px;
}

.settings {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 10px 16px;
    margin-bottom: 22px;
    text-align: left;
}

.settings label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 13px;
    color: var(--muted);
}

.settings select {
    font-family: var(--font);
    font-size: 15px;
    padding: 7px 8px;
    border-radius: 8px;
    background: #15123a;
    color: var(--text);
    border: 1px solid var(--line);
}

.title-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: center;
    align-items: center;
}

.title-foot {
    margin-top: 18px;
    color: var(--muted);
    font-size: 12px;
}

/* ---------- 対局HUD ---------- */
#game-ui {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 10;
}

#game-ui > * {
    pointer-events: auto;
}

#hud-top {
    position: absolute;
    top: 10px;
    left: 10px;
    display: flex;
    gap: 12px;
    align-items: stretch;
}

#hud-round, #hud-dora {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 8px 12px;
    font-size: 14px;
}

#hud-round b {
    color: var(--gold);
    font-size: 18px;
}

#hud-dora .lbl {
    font-size: 11px;
    color: var(--muted);
    display: block;
    margin-bottom: 4px;
}

#dora-tiles {
    display: flex;
    gap: 3px;
}

#dora-tiles img {
    height: 46px;
}

#top-right {
    position: absolute;
    top: 10px;
    right: 10px;
    display: flex;
    gap: 8px;
}

#toggles {
    position: absolute;
    top: 70px;
    right: 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 8px 12px;
    font-size: 13px;
}

#toggles label {
    cursor: pointer;
    white-space: nowrap;
}

#shanten-info {
    margin-top: 6px;
    color: var(--accent-2);
    font-weight: bold;
    min-height: 1em;
}

#waits-panel {
    position: absolute;
    right: 10px;
    bottom: 210px;
    background: var(--panel-2);
    border: 1px solid var(--gold);
    border-radius: 12px;
    padding: 8px 10px;
    max-width: 48vw;
    max-height: 40vh;
    overflow: auto;
    box-shadow: 0 0 18px rgba(245, 200, 76, 0.3);
}

.wp-title {
    color: var(--gold);
    font-size: 13px;
    font-weight: bold;
    margin-bottom: 4px;
}

#waits-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.wait-item {
    text-align: center;
    font-size: 11px;
    line-height: 1.3;
    min-width: 52px;
}

.wait-item img {
    height: 50px;
    display: block;
    margin: 0 auto 2px;
}

.wait-item .left {
    color: var(--accent-2);
}

.wait-item .pts {
    color: var(--gold-2);
}

.wait-item .noyaku {
    color: var(--red);
}

#actions {
    position: absolute;
    left: 50%;
    bottom: 190px;
    transform: translateX(-50%);
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
}

.act-btn {
    font-family: var(--font);
    font-size: 22px;
    font-weight: bold;
    min-width: 96px;
    padding: 12px 22px;
    border-radius: 14px;
    border: 2px solid rgba(255, 255, 255, 0.6);
    color: #fff;
    cursor: pointer;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.6);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
    animation: pop-in 0.18s ease-out;
}

.act-btn:hover {
    filter: brightness(1.2);
    transform: translateY(-2px);
}

.act-btn.chi {
    background: linear-gradient(180deg, #3ddc97, #138657);
}

.act-btn.pon {
    background: linear-gradient(180deg, #4dabff, #1857b8);
}

.act-btn.kan {
    background: linear-gradient(180deg, #c77dff, #6a1fb0);
}

.act-btn.riichi {
    background: linear-gradient(180deg, #ffb347, #c8520c);
}

.act-btn.ron, .act-btn.tsumo {
    background: linear-gradient(180deg, #ff5d73, #a3102d);
}

.act-btn.skip {
    background: linear-gradient(180deg, #6b6b80, #36364a);
    font-size: 18px;
}

.act-btn.opt {
    background: linear-gradient(180deg, #2e9e72, #0f5a3c);
    display: flex;
    gap: 2px;
    align-items: center;
    padding: 6px 10px;
}

.act-btn.opt img {
    height: 42px;
}

@keyframes pop-in {
    from {
        transform: scale(0.6);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

#message {
    position: absolute;
    left: 50%;
    top: 18%;
    transform: translateX(-50%);
    font-size: 22px;
    font-weight: bold;
    color: var(--gold-2);
    text-shadow: 0 0 10px #000, 0 0 20px rgba(123, 92, 255, 0.9);
    pointer-events: none;
    text-align: center;
}

#decl-layer {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.decl {
    position: absolute;
    transform: translate(-50%, -50%);
    font-family: var(--serif);
    font-size: 56px;
    font-weight: 900;
    color: #fff;
    -webkit-text-stroke: 2px #6a1fb0;
    text-shadow: 0 0 18px #c77dff, 0 0 40px #36d6ff;
    animation: decl-anim 1.3s ease-out forwards;
    white-space: nowrap;
}

.decl.ron, .decl.tsumo {
    -webkit-text-stroke-color: #a3102d;
    text-shadow: 0 0 18px #ff5d73, 0 0 44px #ffd769;
    font-size: 72px;
}

.decl.riichi {
    -webkit-text-stroke-color: #c8520c;
    text-shadow: 0 0 18px #ffb347, 0 0 40px #ffe9a3;
}

.decl .serif {
    font-size: 20px;
    display: block;
    text-align: center;
    -webkit-text-stroke: 0;
    color: var(--gold-2);
    font-family: var(--font);
}

@keyframes decl-anim {
    0% {
        transform: translate(-50%, -50%) scale(2.2);
        opacity: 0;
    }
    15% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }
    80% {
        opacity: 1;
    }
    100% {
        transform: translate(-50%, -60%) scale(1.05);
        opacity: 0;
    }
}

#tooltip, #seen-pop {
    position: absolute;
    background: var(--panel-2);
    border: 1px solid var(--accent-2);
    border-radius: 10px;
    padding: 6px 10px;
    font-size: 12px;
    pointer-events: none;
    max-width: 360px;
    z-index: 20;
}

#tooltip .tt-title {
    color: var(--accent-2);
    font-weight: bold;
    margin-bottom: 3px;
}

#tooltip .tt-tiles {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
}

#tooltip .tt-tiles span {
    text-align: center;
    font-size: 10px;
}

#tooltip img {
    height: 34px;
    display: block;
}

#seen-pop {
    border-color: var(--gold);
    display: flex;
    gap: 8px;
    align-items: center;
    font-size: 14px;
}

#seen-pop img {
    height: 48px;
}

#sound-ctrl {
    position: absolute;
    left: 10px;
    bottom: 10px;
    display: flex;
    gap: 10px;
    align-items: center;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 6px 10px;
    font-size: 12px;
}

#sound-ctrl input[type="range"] {
    width: 80px;
    vertical-align: middle;
}

/* ---------- モーダル ---------- */
#modal {
    background: rgba(3, 2, 10, 0.72);
    z-index: 80;
}

.modal-box {
    position: relative;
    width: min(1000px, 94vw);
    max-height: 88vh;
    overflow: auto;
    background: linear-gradient(180deg, #17134a, #0b0926);
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 26px 28px;
    box-shadow: 0 0 40px rgba(123, 92, 255, 0.4);
}

.modal-box h2 {
    margin: 0 0 14px;
    color: var(--gold);
    font-family: var(--serif);
}

.modal-box h3 {
    color: var(--accent-2);
    margin: 20px 0 8px;
    border-bottom: 1px solid var(--line);
    padding-bottom: 4px;
}

.yaku-row {
    display: grid;
    grid-template-columns: 150px 90px 1fr;
    gap: 4px 12px;
    padding: 8px 0;
    border-bottom: 1px dashed rgba(160, 140, 255, 0.2);
    font-size: 13px;
}

.yaku-row .yname {
    font-weight: bold;
    color: var(--gold-2);
    font-size: 15px;
}

.yaku-row .yhan {
    color: var(--accent-2);
}

.yaku-row .yex {
    grid-column: 1 / -1;
    display: flex;
    flex-wrap: wrap;
    gap: 1px;
    align-items: flex-end;
}

.yaku-row .yex img {
    height: 38px;
}

.yaku-row .yex .sep {
    width: 8px;
}

.menu-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: stretch;
    max-width: 320px;
    margin: 0 auto;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 10px;
    margin-bottom: 14px;
}

.stat-card {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 10px;
}

.stat-card .v {
    font-size: 26px;
    color: var(--gold);
    font-weight: bold;
}

.ach-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.ach {
    padding: 4px 10px;
    border-radius: 14px;
    font-size: 12px;
    border: 1px solid var(--line);
    color: var(--muted);
}

.ach.got {
    border-color: var(--gold);
    color: var(--gold-2);
    background: rgba(245, 200, 76, 0.12);
}

.tut-page {
    min-height: 300px;
    font-size: 15px;
    line-height: 1.8;
}

.tut-page .tiles {
    display: flex;
    gap: 2px;
    flex-wrap: wrap;
    margin: 8px 0;
    align-items: flex-end;
}

.tut-page .tiles img {
    height: 50px;
}

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

/* ---------- 点数報告 ---------- */
#report {
    background: rgba(3, 2, 10, 0.78);
    z-index: 70;
}

.report-box {
    width: min(1100px, 96vw);
    max-height: 94vh;
    overflow: auto;
    background: linear-gradient(180deg, rgba(30, 22, 80, 0.95), rgba(8, 6, 26, 0.97));
    border: 2px solid var(--gold);
    border-radius: 20px;
    padding: 22px 28px;
    box-shadow: 0 0 60px rgba(245, 200, 76, 0.35);
    position: relative;
}

.rp-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
}

.rp-who {
    font-size: 26px;
    font-weight: bold;
    color: var(--gold-2);
}

.rp-who small {
    color: var(--muted);
    font-size: 15px;
    margin-left: 10px;
}

.rp-hand {
    display: flex;
    align-items: flex-end;
    gap: 1px;
    margin: 14px 0;
    flex-wrap: wrap;
}

.rp-hand img {
    height: 62px;
    transition: transform 0.3s;
}

.rp-hand .gap {
    width: 16px;
}

.rp-hand .win {
    margin-left: 18px;
    filter: drop-shadow(0 0 10px var(--gold));
}

.rp-hand img.side {
    transform: rotate(-90deg);
    margin: 0 10px;
}

.rp-dora {
    display: flex;
    gap: 24px;
    font-size: 13px;
    color: var(--muted);
}

.rp-dora .tiles {
    display: flex;
    gap: 2px;
    margin-top: 3px;
}

.rp-dora img {
    height: 44px;
}

.rp-yaku {
    margin: 14px 0;
    columns: 2;
    column-gap: 40px;
}

.yaku-line {
    display: flex;
    justify-content: space-between;
    font-size: 22px;
    padding: 3px 4px;
    border-bottom: 1px solid rgba(245, 200, 76, 0.2);
    break-inside: avoid;
    animation: yaku-in 0.35s ease-out;
}

.yaku-line .h {
    color: var(--gold);
    font-weight: bold;
}

.yaku-line.ym .n {
    color: #ff8fd8;
    text-shadow: 0 0 8px #ff3fb8;
}

@keyframes yaku-in {
    from {
        transform: translateX(-30px);
        opacity: 0;
    }
    to {
        transform: none;
        opacity: 1;
    }
}

.rp-total {
    display: flex;
    align-items: center;
    gap: 30px;
    margin-top: 10px;
}

.rp-fuhan {
    font-size: 24px;
    color: var(--muted);
}

.rp-points {
    font-size: 56px;
    font-weight: 900;
    color: var(--gold-2);
    text-shadow: 0 0 20px rgba(245, 200, 76, 0.8);
    animation: pop-in 0.3s;
}

.rp-titlebig {
    font-family: var(--serif);
    font-size: 64px;
    font-weight: 900;
    background: linear-gradient(180deg, #fff 0%, #ffd769 40%, #ff5d73 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    filter: drop-shadow(0 0 16px rgba(255, 93, 115, 0.8));
    animation: title-in 0.6s cubic-bezier(.2, 1.6, .4, 1);
}

.rp-titlebig.yakuman {
    font-size: 84px;
    background: linear-gradient(180deg, #fff 0%, #9df 30%, #c77dff 60%, #ff5dd6 100%);
    -webkit-background-clip: text;
    background-clip: text;
}

@keyframes title-in {
    from {
        transform: scale(3);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

.rp-buttons {
    display: flex;
    justify-content: flex-end;
    margin-top: 14px;
    gap: 10px;
}

.mv-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
    margin: 20px 0;
}

.mv-card {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 14px 18px;
}

.mv-card .nm {
    font-size: 18px;
    font-weight: bold;
}

.mv-card .wd {
    color: var(--muted);
    font-size: 13px;
    margin-left: 6px;
}

.mv-card .pt {
    font-size: 32px;
    font-weight: bold;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

.mv-card .df {
    font-size: 22px;
    font-weight: bold;
    font-variant-numeric: tabular-nums;
}

.mv-card .df.plus {
    color: var(--green);
}

.mv-card .df.minus {
    color: var(--red);
}

.mv-card.me {
    border-color: var(--gold);
}

.podium {
    display: flex;
    justify-content: center;
    align-items: flex-end;
    gap: 14px;
    margin: 24px 0 10px;
}

.podium .pd {
    text-align: center;
    width: 180px;
}

.podium .blk {
    border-radius: 12px 12px 0 0;
    background: linear-gradient(180deg, #4a3bb0, #1b1550);
    border: 1px solid var(--line);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 10px;
    font-size: 40px;
    font-weight: 900;
    color: var(--gold-2);
}

.podium .p1 .blk {
    height: 170px;
    background: linear-gradient(180deg, #ffd769, #9a6400);
    color: #2b1a00;
}

.podium .p2 .blk {
    height: 130px;
}

.podium .p3 .blk {
    height: 100px;
}

.podium .p4 .blk {
    height: 70px;
}

.podium .nm {
    font-weight: bold;
    margin-bottom: 4px;
}

.podium .sc {
    font-size: 13px;
    color: var(--muted);
    margin-bottom: 6px;
}

/* ---------- デバッグ ---------- */
#debug-panel {
    position: fixed;
    inset: 0;
    overflow: auto;
    background: #0b0926;
    z-index: 200;
    padding: 20px;
    font-size: 13px;
}

#debug-panel h2 {
    color: var(--gold);
}

#debug-panel table {
    border-collapse: collapse;
    width: 100%;
}

#debug-panel td, #debug-panel th {
    border: 1px solid var(--line);
    padding: 4px 6px;
    vertical-align: middle;
}

#debug-panel .ok {
    color: var(--green);
    font-weight: bold;
}

#debug-panel .ng {
    color: var(--red);
    font-weight: bold;
}

#debug-panel img {
    height: 40px;
}

.tile-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.tile-grid figure {
    margin: 0;
    text-align: center;
    font-size: 11px;
    color: var(--muted);
}

.tile-grid img {
    height: 80px !important;
}

.tile-preview {
    border: 1px solid var(--line);
    border-radius: 12px;
    overflow: hidden;
    max-width: 1100px;
}

.tile-preview canvas {
    display: block;
}

.zoom-row {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
}

.zoom-fig {
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-items: flex-start;
}

.zoom-fig figcaption {
    color: var(--muted);
}

.zoom-1x {
    width: 384px;
    height: 512px;
    overflow: auto;
    border: 1px solid var(--line);
}

#debug-panel .zoom-1x img {
    height: auto;
    width: 768px;
    max-width: none;
}

.zoom-3x {
    width: 384px;
    height: 200px;
    border: 1px solid var(--accent-2);
    background-repeat: no-repeat;
    background-size: 2304px 3072px; /* 768×1024 の3倍 */
    image-rendering: pixelated;
}
