/* ===== 色モード ===== */
:root {
    color-scheme: dark;
    --bg: #163f2e;
    --bg-paint: radial-gradient(120% 70% at 50% 0%, #1f5540 0%, #163f2e 65%);
    --card: #1d4d39;
    --card-border: rgba(255, 255, 255, 0.10);
    --line: rgba(255, 255, 255, 0.12);
    --dashed: rgba(255, 255, 255, 0.28);
    --text: #f0ead9;
    --muted: #a9bfb2;
    --accent: #e6c15f;
    --on-accent: #1a1a1a;
    --ghost-border: rgba(255, 255, 255, 0.22);
    --ghost-text: #e6dfcd;
    --empty: rgba(255, 255, 255, 0.32);
    --tile-drop: rgba(0, 0, 0, 0.45);
    --font-ui: 'Zen Kaku Gothic New', 'Hiragino Sans', 'Hiragino Kaku Gothic ProN', sans-serif;
    --font-display: 'Shippori Mincho', 'Hiragino Mincho ProN', 'Yu Mincho', serif;
}

:root[data-theme="light"] {
    color-scheme: light;
    --bg: #f6f4ee;
    --bg-paint: #f6f4ee;
    --card: #ffffff;
    --card-border: #e3dfd3;
    --line: #e6e2d7;
    --dashed: #cfc9bb;
    --text: #1f1f1c;
    --muted: #6b6a61;   /* #f6f4ee 上で約5:1 */
    --accent: #8f6a12;
    --on-accent: #ffffff;
    --ghost-border: #cfc9bb;
    --ghost-text: #3a3a35;
    --empty: #c8c2b3;
    --tile-drop: rgba(0, 0, 0, 0.22);
}

/* ===== ベース ===== */
html, body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-ui);
    -webkit-font-smoothing: antialiased;
}

body {
    background: var(--bg-paint);
    background-attachment: fixed;
    min-height: 100dvh;
}

button {
    font: inherit;
    color: inherit;
    background: none;
    border: 0;
    padding: 0;
    margin: 0;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

button:disabled {
    cursor: default;
}

button:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

img {
    display: block;
}

.app {
    max-width: 430px;
    margin: 0 auto;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

/* ===== ヘッダー ===== */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: calc(20px + env(safe-area-inset-top)) 16px 6px;
}

.app-title {
    margin: 0;
    font-family: var(--font-display);
    font-size: 22px;
    font-weight: 700;
    letter-spacing: 0.06em;
    line-height: 1.2;
    white-space: nowrap;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.seg {
    display: flex;
    gap: 2px;
    padding: 3px;
    border-radius: 12px;
    border: 1px solid var(--ghost-border);
}

.seg button {
    height: 34px;
    padding: 0 14px;
    border-radius: 9px;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.04em;
    color: var(--muted);
}

.seg button[aria-pressed="true"] {
    background: var(--accent);
    color: var(--on-accent);
}

.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    border: 1px solid var(--ghost-border);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--ghost-text);
}

/* ===== 手牌 ===== */
.hand {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 10px 14px;
}

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

.hand-label {
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.hand-title {
    font-size: 13px;
    font-weight: 700;
}

.hand-hint {
    font-size: 11px;
    color: var(--muted);
}

.hand-count {
    font-size: 13px;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

.hand-count strong {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
}

.hand-count.is-full,
.hand-count.is-full strong {
    color: var(--accent);
}

.hand-grid {
    display: grid;
    grid-template-columns: repeat(13, minmax(0, 1fr));
    gap: 2px;
}

.hand-slot {
    display: block;
    width: 100%;
    aspect-ratio: 62.9 / 98.2;
}

.hand-slot--empty {
    border: 1.5px dashed var(--empty);
    border-radius: 4px;
    box-sizing: border-box;
}

/* ===== 牌画像 ===== */
.tile-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    filter: drop-shadow(0 2px 3px var(--tile-drop));
    user-select: none;
    -webkit-user-drag: none;
}

/* ===== 結果カード ===== */
.result {
    margin: 4px 14px 0;
    min-height: 188px;
    box-sizing: border-box;
    border-radius: 14px;
}

.result.card {
    padding: 16px 16px 14px;
    background: var(--card);
    border: 1px solid var(--card-border);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.result.placeholder {
    padding: 18px 16px;
    border: 1.5px dashed var(--dashed);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.result-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
}

.stat {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.stat--right {
    align-items: flex-end;
}

.stat-label {
    font-size: 11px;
    letter-spacing: 0.08em;
    color: var(--muted);
}

.stat-value {
    display: flex;
    align-items: baseline;
    gap: 3px;
}

.stat--right .stat-value {
    gap: 6px;
}

.stat-value .kinds {
    font-size: 14px;
    color: var(--muted);
}

.big {
    font-family: var(--font-display);
    font-size: 36px;
    font-weight: 700;
    line-height: 1;
}

.accent {
    color: var(--accent);
}

.unit {
    font-size: 15px;
    font-weight: 500;
}

.divider {
    height: 1px;
    background: var(--line);
}

.accept-list {
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
}

.accept {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.accept-tile {
    width: 34px;
    aspect-ratio: 62.9 / 98.2;
}

.accept-count {
    font-size: 12px;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

.accept-none {
    font-size: 12px;
    color: var(--muted);
}

.remaining {
    display: flex;
    align-items: baseline;
    gap: 4px;
}

.remaining .pre,
.remaining .post {
    font-size: 14px;
    color: var(--muted);
}

.placeholder-note {
    font-size: 12px;
    color: var(--muted);
}

/* ===== 牌パレット ===== */
.palette {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 16px 14px 0;
}

.palette-row {
    display: grid;
    grid-template-columns: repeat(10, minmax(0, 1fr));
    gap: 4px;
}

.palette-tile {
    display: block;
    width: 100%;
    aspect-ratio: 62.9 / 98.2;
}

/* 使い切り・三麻で存在しない牌: 色は保ったまま薄く（赤五が赤く見えるようグレースケールは使わない） */
.palette-tile:disabled {
    opacity: 0.45;
}

/* ===== 操作ボタン ===== */
.actions {
    margin-top: auto;
    display: flex;
    gap: 10px;
    padding: 14px 14px calc(22px + env(safe-area-inset-bottom));
}

.ghost {
    flex: 1;
    height: 44px;
    border-radius: 10px;
    border: 1px solid var(--ghost-border);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 500;
    color: var(--ghost-text);
}

.ghost:disabled {
    opacity: 0.45;
}

.ghost svg {
    flex-shrink: 0;
}

/* ===== 見つからないページ ===== */
.not-found {
    margin: auto;
    padding: 40px 24px;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.not-found h2 {
    margin: 0;
    font-family: var(--font-display);
    font-size: 22px;
    font-weight: 700;
    letter-spacing: 0.06em;
}

.not-found p {
    margin: 0;
    font-size: 13px;
    color: var(--muted);
}

.not-found a {
    color: var(--accent);
    font-weight: 700;
}

/* ===== Blazor 読み込み中・エラー表示 ===== */
.loading {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.loading-progress {
    position: relative;
    display: block;
    width: 6rem;
    height: 6rem;
}

.loading-progress circle {
    fill: none;
    stroke: var(--line);
    stroke-width: 0.6rem;
    transform-origin: 50% 50%;
    transform: rotate(-90deg);
}

.loading-progress circle:last-child {
    stroke: var(--accent);
    stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
    transition: stroke-dasharray 0.05s ease-in-out;
}

.loading-progress-text {
    font-size: 13px;
    color: var(--muted);
}

.loading-progress-text::after {
    content: var(--blazor-load-percentage-text, "読み込み中");
}

#blazor-error-ui {
    color-scheme: light only;
    background: lightyellow;
    color: #1a1a1a;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    box-sizing: border-box;
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
}
