﻿html, body {
    font-family: "Roboto", "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", "Heiti SC", -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
    margin: 0;
    padding: 0;
    background: radial-gradient(circle at top, #f7f9fc 0%, #eef1f6 45%, #e6ebf2 100%);
    color: #1f2937;
    -webkit-tap-highlight-color: transparent;
}

* {
    box-sizing: border-box;
}

h1:focus {
    outline: none;
}

a, .btn-link {
    color: #0071c1;
}

.btn-primary {
    color: #fff;
    background-color: #1b6ec2;
    border-color: #1861ac;
}

.btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus {
    box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem #258cfb;
}

/* ========== App Container ========== */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    max-width: 560px;
    margin: 0 auto;
    background: transparent;
    overflow: hidden;
}

.main-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 10px 8px 10px;
    min-height: 0;
}

/* When calc-app is the child, main-content should not add extra padding/scroll */
.main-content:has(.calc-app) {
    padding: 2px 6px 0;
    overflow: hidden;
}

/* ========== Bottom Navigation ========== */
.bottom-nav {
    flex-shrink: 0;
    height: 56px;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(18px);
    border-top: 1px solid rgba(255, 255, 255, 0.45);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    box-shadow: 0 -8px 20px rgba(15, 23, 42, 0.06);
}

.nav-tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    color: #64748b;
    padding: 8px 6px;
    transition: color 0.2s;
}

.nav-tab:hover {
    color: #4b5563;
    text-decoration: none;
}

.nav-tab.active {
    color: #2563eb;
}

.tab-icon {
    font-size: 22px;
    margin-bottom: 2px;
}

.tab-label {
    font-size: 11px;
    font-weight: 600;
}

/* ========== Calculator Page — Fixed App Layout ========== */
.calc-app {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.calc-display {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 2px 0;
    -webkit-overflow-scrolling: touch;
}

.calc-display::-webkit-scrollbar { display: none; }

/* Score Bar */
.score-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: linear-gradient(135deg, rgba(37, 99, 235, 0.95), rgba(59, 130, 246, 0.9));
    border-radius: 12px;
    padding: 8px 12px;
    color: #fff;
    box-shadow: 0 6px 16px rgba(37, 99, 235, 0.18);
    flex-shrink: 0;
    gap: 8px;
}

.score-bar-left {
    display: flex;
    align-items: baseline;
    gap: 4px;
}

.score-bar-value {
    font-size: 32px;
    font-weight: 700;
    line-height: 1;
}

.score-bar-label {
    font-size: 14px;
    opacity: 0.85;
}

.score-bar-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
    flex: 1;
}

.score-bar-status {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.2);
}

.score-bar-status.valid {
    background: rgba(74, 222, 128, 0.35);
}

.score-bar-count {
    font-size: 10px;
    opacity: 0.7;
}

.score-settings-btn {
    border: none;
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
    width: 30px;
    height: 30px;
    border-radius: 10px;
    font-size: 15px;
    cursor: pointer;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}

.score-settings-btn:active {
    background: rgba(255, 255, 255, 0.35);
}

.score-settings-btn.open {
    background: rgba(255, 255, 255, 0.35);
}

/* Settings Panel */
.settings-panel {
    background: rgba(255, 255, 255, 0.82);
    border-radius: 10px;
    padding: 6px 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    border: 1px solid rgba(255, 255, 255, 0.6);
    box-shadow: 4px 4px 12px rgba(148, 163, 184, 0.15);
    flex-shrink: 0;
}

.chip-sep {
    width: 1px;
    height: 18px;
    background: #e2e8f0;
    margin: 0 2px;
    flex-shrink: 0;
}

/* Hand Bar */
.hand-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(255, 255, 255, 0.82);
    border-radius: 12px;
    padding: 6px 8px;
    min-height: 40px;
    border: 1px solid rgba(255, 255, 255, 0.6);
    box-shadow: 6px 6px 16px rgba(148, 163, 184, 0.2), -6px -6px 16px rgba(255, 255, 255, 0.7);
    flex-shrink: 0;
}

.hand-bar-tiles {
    flex: 1;
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
    align-items: center;
    overflow: hidden;
}

.hand-placeholder {
    font-size: 11px;
    color: #94a3b8;
}

.hand-tile {
    border: none;
    background: none;
    padding: 1px;
    cursor: pointer;
    border-radius: 4px;
    transition: transform 0.1s;
    line-height: 0;
}

.hand-tile:active {
    transform: scale(0.88);
    background: #fee2e2;
}

.hand-meld {
    display: inline-flex;
    align-items: center;
    gap: 1px;
    border: none;
    background: rgba(241, 245, 249, 0.9);
    border-radius: 6px;
    padding: 2px 4px;
    cursor: pointer;
    position: relative;
    line-height: 0;
}

.hand-meld:active {
    background: #fee2e2;
}

.meld-tag {
    position: absolute;
    bottom: -2px;
    right: -2px;
    font-size: 8px;
    background: #2563eb;
    color: #fff;
    padding: 0 3px;
    border-radius: 4px;
    line-height: 1.4;
    font-weight: 700;
}

.hand-sep {
    color: #cbd5e1;
    font-size: 18px;
    margin: 0 2px;
    user-select: none;
}

.hand-clear {
    border: none;
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
    width: 28px;
    height: 28px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    flex-shrink: 0;
}

.tile-sm {
    height: 28px;
    width: auto;
    vertical-align: middle;
    image-rendering: auto;
}

/* Result / Wait Bars */
.result-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 6px 10px;
    background: rgba(255, 255, 255, 0.78);
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.6);
    box-shadow: 4px 4px 12px rgba(148, 163, 184, 0.15);
    flex-shrink: 0;
}

.result-bar .result-chip {
    padding: 3px 8px;
    font-size: 11px;
}

/* Wait Section — expandable detail */
.wait-section {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex-shrink: 0;
}

.wait-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    background: rgba(255, 255, 255, 0.78);
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.6);
    box-shadow: 4px 4px 12px rgba(148, 163, 184, 0.15);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-shrink: 0;
}

.wait-bar::-webkit-scrollbar { display: none; }

.wait-bar-label {
    font-size: 12px;
    font-weight: 700;
    color: #2563eb;
    flex-shrink: 0;
}

.wait-item {
    display: flex;
    align-items: center;
    gap: 3px;
    border: none;
    background: rgba(37, 99, 235, 0.08);
    border-radius: 8px;
    padding: 4px 8px;
    cursor: pointer;
    flex-shrink: 0;
    transition: transform 0.1s;
}

.wait-item:active {
    transform: scale(0.93);
    background: rgba(37, 99, 235, 0.18);
}

.wait-item.expanded {
    background: rgba(37, 99, 235, 0.18);
    box-shadow: 0 0 0 1.5px rgba(37, 99, 235, 0.4);
}

.wait-fan {
    font-size: 11px;
    font-weight: 700;
    color: #2563eb;
}

.wait-detail {
    background: rgba(255, 255, 255, 0.85);
    border-radius: 10px;
    padding: 8px 10px;
    border: 1px solid rgba(37, 99, 235, 0.15);
    box-shadow: 4px 4px 12px rgba(148, 163, 184, 0.15);
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.wait-detail-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.wait-detail-left {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.wait-detail-fan {
    font-size: 14px;
    font-weight: 700;
    color: #2563eb;
}

.wait-detail-decomp {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    align-items: center;
    flex: 1;
    min-width: 0;
}

.wait-detail-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.wait-detail-add {
    align-self: flex-end;
    border: none;
    background: linear-gradient(135deg, rgba(37, 99, 235, 0.95), rgba(59, 130, 246, 0.9));
    color: #fff;
    padding: 4px 14px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.1s;
}

.wait-detail-add:active {
    transform: scale(0.95);
}

/* Winning tile highlight marker */
.tile-win-marker {
    display: inline-flex;
    position: relative;
    border-radius: 4px;
    box-shadow: 0 0 0 1.5px #ef4444, 0 0 6px rgba(239, 68, 68, 0.3);
}

.tile-win-marker::after {
    content: "胡";
    position: absolute;
    top: -6px;
    right: -6px;
    font-size: 7px;
    font-weight: 800;
    color: #fff;
    background: #ef4444;
    padding: 0 3px;
    border-radius: 3px;
    line-height: 1.4;
    z-index: 1;
}

/* ── Tile Keyboard (flex child, not fixed) ── */
.calc-keyboard {
    flex-shrink: 0;
    background: rgba(241, 245, 249, 0.96);
    backdrop-filter: blur(16px);
    border-top: 1px solid rgba(226, 232, 240, 0.7);
    border-radius: 14px 14px 0 0;
    padding: 4px 6px 2px;
    box-shadow: 0 -6px 18px rgba(15, 23, 42, 0.06);
}

.kb-targets {
    display: flex;
    gap: 3px;
    margin-bottom: 3px;
}

.kb-target {
    flex: 1;
    border: none;
    background: rgba(255, 255, 255, 0.8);
    color: #475569;
    padding: 5px 0;
    border-radius: 8px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    box-shadow: 2px 2px 6px rgba(148, 163, 184, 0.15);
    transition: background 0.15s, color 0.15s;
}

.kb-target.active {
    background: linear-gradient(135deg, rgba(37, 99, 235, 0.95), rgba(59, 130, 246, 0.9));
    color: #fff;
}

.kb-rows {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.kb-row {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    gap: 3px;
}

.kb-row:last-child {
    grid-template-columns: repeat(7, 1fr);
}

.kb-tile {
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: rgba(255, 255, 255, 0.92);
    border-radius: 8px;
    padding: 4px 0;
    cursor: pointer;
    box-shadow: 2px 2px 6px rgba(148, 163, 184, 0.15);
    transition: transform 0.1s, opacity 0.15s;
    min-height: 42px;
}

.kb-tile:active {
    transform: scale(0.9);
    background: rgba(37, 99, 235, 0.12);
}

.kb-tile.disabled {
    opacity: 0.3;
    pointer-events: none;
}

.kb-tile .tile-sm {
    height: 32px;
}

.chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}

.chip-sm {
    border: none;
    background: rgba(255, 255, 255, 0.75);
    color: #475569;
    padding: 5px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 3px 3px 8px rgba(148, 163, 184, 0.18), -3px -3px 8px rgba(255, 255, 255, 0.8);
    transition: transform 0.15s, background 0.15s, color 0.15s;
}

.chip-sm.active {
    background: linear-gradient(135deg, rgba(37, 99, 235, 0.95), rgba(59, 130, 246, 0.9));
    color: #fff;
    box-shadow: 0 6px 14px rgba(37, 99, 235, 0.2);
}

/* ========== Loading Screen ========== */
.loading-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    gap: 16px;
    padding: 24px;
}

.loading-icon {
    font-size: 64px;
    animation: loading-bounce 1.2s ease-in-out infinite;
}

@keyframes loading-bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

.loading-title {
    font-size: 22px;
    font-weight: 700;
    color: #1e293b;
    letter-spacing: 1px;
}

.loading-spinner {
    width: 60px;
    height: 60px;
    margin: 8px 0;
}

.loading-progress {
    width: 100%;
    height: 100%;
    animation: loading-rotate 1.2s linear infinite;
}

.loading-progress circle {
    fill: none;
    stroke-width: 3px;
}

.loading-progress circle:first-child {
    stroke: #e2e8f0;
}

.loading-progress circle:last-child {
    stroke: #2563eb;
    stroke-dasharray: 220;
    stroke-dashoffset: 60;
    stroke-linecap: round;
}

@keyframes loading-rotate {
    to { transform: rotate(360deg); }
}

.loading-progress-text {
    font-size: 13px;
    font-weight: 600;
    color: #2563eb;
}

.loading-hint {
    font-size: 13px;
    color: #94a3b8;
}

/* ========== Error UI ========== */
#blazor-error-ui {
    color-scheme: light only;
    background: lightyellow;
    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;
}

/* ========== Fan Table Page ========== */
.fan-table-container {
    padding: 4px 0;
}

.fan-filter-bar {
    display: flex;
    flex-wrap: nowrap;
    gap: 6px;
    overflow-x: auto;
    padding: 4px 2px 8px;
    -webkit-overflow-scrolling: touch;
}

.fan-filter-bar::-webkit-scrollbar {
    display: none;
}

.fan-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

/* Compact fan item */
.fan-item {
    background: rgba(255, 255, 255, 0.82);
    border-radius: 12px;
    padding: 10px 12px;
    border: 1px solid rgba(255, 255, 255, 0.6);
    box-shadow: 4px 4px 12px rgba(148, 163, 184, 0.18), -4px -4px 12px rgba(255, 255, 255, 0.7);
    cursor: pointer;
    transition: background 0.15s;
}

.fan-item:active {
    background: rgba(255, 255, 255, 0.95);
}

.fan-item-header {
    display: flex;
    align-items: center;
    gap: 8px;
}

.fan-item-icon {
    font-size: 18px;
    width: 28px;
    text-align: center;
    flex-shrink: 0;
}

.fan-item-name {
    flex: 1;
    font-size: 14px;
    font-weight: 500;
    color: #1e293b;
}

.fan-item-pts {
    font-size: 12px;
    font-weight: 700;
    color: #2563eb;
    background: rgba(37, 99, 235, 0.08);
    padding: 2px 8px;
    border-radius: 999px;
    flex-shrink: 0;
}

.fan-item-detail {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px dashed #e2e8f0;
}

.fan-item-desc {
    font-size: 13px;
    color: #64748b;
    line-height: 1.6;
    margin: 0;
}

.fan-item-example {
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
    margin-top: 6px;
}

.fan-item-example-text {
    font-size: 12px;
    color: #2563eb;
    line-height: 1.6;
    margin: 6px 0 0 0;
}

/* ========== Shared ========== */
.chip-label {
    font-size: 11px;
    color: #64748b;
    margin-right: 2px;
    flex-shrink: 0;
}

.flower-value {
    min-width: 24px;
    text-align: center;
    font-weight: 700;
    font-size: 13px;
    color: #1e293b;
}

.result-chip {
    background: rgba(37, 99, 235, 0.12);
    color: #1e40af;
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 11px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: background 0.15s;
}

.result-chip.expanded {
    background: rgba(37, 99, 235, 0.25);
    box-shadow: 0 0 0 1.5px rgba(37, 99, 235, 0.4);
}

.fan-reason-bar {
    padding: 6px 10px;
    background: rgba(255, 255, 255, 0.85);
    border-radius: 10px;
    border: 1px solid rgba(37, 99, 235, 0.15);
    box-shadow: 4px 4px 12px rgba(148, 163, 184, 0.15);
    flex-shrink: 0;
}

.fan-reason-text {
    font-size: 12px;
    color: #475569;
    line-height: 1.5;
}

/* Decomposition display */
.tile-xs {
    height: 22px;
    width: auto;
    vertical-align: middle;
    image-rendering: auto;
}

.wait-decomp {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
    padding: 4px 0;
}

.result-decomp {
    padding: 6px 10px;
    background: rgba(255, 255, 255, 0.78);
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.6);
    box-shadow: 4px 4px 12px rgba(148, 163, 184, 0.15);
    flex-shrink: 0;
}

.wait-decomp-group {
    display: inline-flex;
    align-items: center;
    gap: 1px;
    background: rgba(241, 245, 249, 0.9);
    border-radius: 6px;
    padding: 2px 3px;
}
