/* Local Noto (subset) — Toy blocks external font CDNs */
@font-face {
  font-family: "Noto Serif SC";
  font-style: normal;
  font-weight: 600 700;
  font-display: swap;
  src: url("./fonts/NotoSerifSC-Bold.subset.woff2") format("woff2");
}
@font-face {
  font-family: "Noto Sans SC";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("./fonts/NotoSansSC-Regular.subset.woff2") format("woff2");
}
@font-face {
  font-family: "Noto Sans SC";
  font-style: normal;
  font-weight: 500 700;
  font-display: swap;
  src: url("./fonts/NotoSansSC-Bold.subset.woff2") format("woff2");
}

:root,
html[data-theme="night"] {
  color-scheme: dark;
  /* Felt table - green family only (night) */
  --felt: #0c3428;
  --felt-deep: #071f18;
  --felt-mid: #114536;
  --felt-light: #1a5c45;
  /* Single accent: amber-gold, saturation held back */
  --gold: #c9a227;
  --gold-hi: #d4b03a;
  --gold-lo: #9a7a1c;
  --gold-line: rgba(201, 162, 39, 0.32);
  --gold-line-strong: rgba(201, 162, 39, 0.5);
  /* Compat aliases (same family, not second accents) */
  --gold-bright: var(--gold-hi);
  --amber: var(--gold);
  --ink: #f3eee4;
  --ink-dim: #b8ae98;
  --card: rgba(7, 31, 24, 0.9);
  --danger: #d45a5a;
  --ok: #5bbf82;
  --radius-outer: 16px;
  --radius-inner: 11px;
  --radius: var(--radius-outer);
  --shadow: 0 10px 28px rgba(4, 28, 20, 0.55), 0 2px 6px rgba(4, 28, 20, 0.35);
  --shadow-gold: 0 6px 18px rgba(60, 48, 8, 0.28);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --dur: 220ms;
  --theme-color-dur: 0.35s;
  --bg-crossfade: 0.55s;
  --text-on-gold: #1a1406;
  --surface-glass: rgba(7, 31, 24, 0.52);
  --surface-glass-solid: rgba(7, 31, 24, 0.96);
  --badge-bg: rgba(7, 31, 24, 0.45);
  --btn-ghost-bg: rgba(7, 31, 24, 0.55);
  --panel-outer-start: rgba(18, 58, 44, 0.55);
  --panel-outer-end: rgba(7, 31, 24, 0.35);
  --panel-border: rgba(201, 162, 39, 0.22);
  --panel-border-hover: rgba(201, 162, 39, 0.42);
  --panel-bezel: rgba(6, 26, 20, 0.92);
  --panel-bezel-gold: rgba(201, 162, 39, 0.12);
  --panel-bezel-gold-hover: rgba(201, 162, 39, 0.2);
  --panel-inner-border: rgba(201, 162, 39, 0.14);
  --inset-hi: rgba(243, 238, 228, 0.06);
  --inset-hi-soft: rgba(243, 238, 228, 0.04);
  --topnav-border: rgba(201, 162, 39, 0.22);
  --topnav-shadow: 0 8px 24px rgba(4, 28, 20, 0.4);
  --check-bg: var(--felt-deep);
  --input-bg: var(--felt-deep);
  --check-border: rgba(201, 162, 39, 0.22);
  --table-border: rgba(201, 162, 39, 0.2);
  --table-th-bg: rgba(20, 70, 52, 0.65);
  --table-han-bg: rgba(7, 31, 24, 0.7);
  --table-hover: rgba(201, 162, 39, 0.12);
  --table-active: rgba(201, 162, 39, 0.22);
  --table-na: rgba(184, 174, 152, 0.35);
  --table-limit-bg: rgba(201, 162, 39, 0.1);
  --yaku-divider: rgba(201, 162, 39, 0.14);
  --yaku-hit-divider: rgba(201, 162, 39, 0.12);
  --compare-border: rgba(201, 162, 39, 0.18);
  --fuuro-bg: rgba(7, 31, 24, 0.65);
  --fuuro-border: rgba(201, 162, 39, 0.25);
  --disclaimer: rgba(184, 174, 152, 0.72);
  --toast-bad-bg: rgba(212, 90, 90, 0.15);
  --toast-bad-border: rgba(212, 90, 90, 0.35);
  --toast-bad-ink: #f0c0c0;
  --toast-ok-bg: rgba(91, 191, 130, 0.12);
  --toast-ok-border: rgba(91, 191, 130, 0.35);
  --toast-ok-ink: #b8e6c8;
  --grain-opacity: 0.045;
  --header-shadow: 0 2px 12px rgba(4, 28, 20, 0.55);
  --tool-hover-shadow: 0 14px 32px rgba(4, 28, 20, 0.6);
  /* Silhouette overlay stops (night: deep mask) */
  --bg-mask-a1: rgba(7, 31, 24, 0.55);
  --bg-mask-a2: rgba(7, 31, 24, 0.42);
  --bg-mask-a3: rgba(7, 31, 24, 0.78);
  --bg-mask-a4: rgba(7, 31, 24, 0.9);
  --bg-mask-b1: rgba(7, 31, 24, 0.78);
  --bg-mask-b2: rgba(7, 31, 24, 0.4);
  --bg-mask-b3: rgba(7, 31, 24, 0.12);
  --bg-mask-web-a1: rgba(7, 31, 24, 0.9);
  --bg-mask-web-a2: rgba(7, 31, 24, 0.7);
  --bg-mask-web-a3: rgba(7, 31, 24, 0.28);
  --bg-mask-web-a4: rgba(7, 31, 24, 0.12);
  --bg-mask-web-b1: rgba(7, 31, 24, 0.28);
  --bg-mask-web-b2: rgba(7, 31, 24, 0.5);
  font-size: 16px;
}

/* Day: warm rice / soft green mist + deeper amber accents */
html[data-theme="day"] {
  color-scheme: light;
  --felt: #dce8de;
  --felt-deep: #f4efe4;
  --felt-mid: #e5efe6;
  --felt-light: #c8dccf;
  --gold: #a67c12;
  --gold-hi: #b8891a;
  --gold-lo: #8a6810;
  --gold-line: rgba(166, 124, 18, 0.38);
  --gold-line-strong: rgba(166, 124, 18, 0.58);
  --gold-bright: var(--gold-hi);
  --amber: var(--gold);
  --ink: #1a2a22;
  --ink-dim: #5a6b60;
  --card: rgba(255, 252, 248, 0.96);
  --danger: #c94444;
  --ok: #2a9a58;
  --shadow: 0 10px 28px rgba(50, 70, 55, 0.12), 0 2px 6px rgba(50, 70, 55, 0.08);
  --shadow-gold: 0 6px 18px rgba(120, 90, 20, 0.18);
  --text-on-gold: #1a1406;
  --surface-glass: rgba(244, 239, 228, 0.78);
  --surface-glass-solid: rgba(244, 239, 228, 0.96);
  --badge-bg: rgba(220, 232, 222, 0.75);
  --btn-ghost-bg: rgba(232, 240, 230, 0.85);
  --panel-outer-start: rgba(200, 220, 205, 0.65);
  --panel-outer-end: rgba(232, 240, 230, 0.45);
  --panel-border: rgba(90, 130, 100, 0.28);
  --panel-border-hover: rgba(166, 124, 18, 0.5);
  --panel-bezel: rgba(180, 200, 185, 0.9);
  --panel-bezel-gold: rgba(166, 124, 18, 0.18);
  --panel-bezel-gold-hover: rgba(166, 124, 18, 0.32);
  --panel-inner-border: rgba(90, 130, 100, 0.2);
  --inset-hi: rgba(255, 255, 255, 0.55);
  --inset-hi-soft: rgba(255, 255, 255, 0.4);
  --topnav-border: rgba(90, 130, 100, 0.28);
  --topnav-shadow: 0 8px 24px rgba(50, 70, 55, 0.12);
  --check-bg: rgba(255, 252, 245, 0.98);
  --input-bg: #efe8d8;
  --check-border: rgba(90, 130, 100, 0.28);
  --table-border: rgba(90, 130, 100, 0.28);
  --table-th-bg: rgba(200, 220, 205, 0.85);
  --table-han-bg: rgba(232, 240, 230, 0.9);
  --table-hover: rgba(166, 124, 18, 0.14);
  --table-active: rgba(166, 124, 18, 0.24);
  --table-na: rgba(90, 107, 96, 0.4);
  --table-limit-bg: rgba(166, 124, 18, 0.12);
  --yaku-divider: rgba(90, 130, 100, 0.2);
  --yaku-hit-divider: rgba(90, 130, 100, 0.16);
  --compare-border: rgba(90, 130, 100, 0.22);
  --fuuro-bg: rgba(232, 240, 230, 0.9);
  --fuuro-border: rgba(90, 130, 100, 0.3);
  --disclaimer: rgba(90, 107, 96, 0.78);
  --toast-bad-bg: rgba(201, 68, 68, 0.1);
  --toast-bad-border: rgba(201, 68, 68, 0.35);
  --toast-bad-ink: #8a2a2a;
  --toast-ok-bg: rgba(42, 154, 88, 0.1);
  --toast-ok-border: rgba(42, 154, 88, 0.35);
  --toast-ok-ink: #1a6a3a;
  --grain-opacity: 0.03;
  --header-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
  --tool-hover-shadow: 0 14px 32px rgba(50, 70, 55, 0.16);
  /* Day masks used only if needed; dual layers bake cooler soft overlays */
  --bg-mask-a1: rgba(248, 250, 247, 0.42);
  --bg-mask-a2: rgba(248, 250, 247, 0.22);
  --bg-mask-a3: rgba(236, 244, 238, 0.38);
  --bg-mask-a4: rgba(248, 250, 247, 0.5);
  --bg-mask-b1: rgba(248, 250, 247, 0.48);
  --bg-mask-b2: rgba(248, 250, 247, 0.18);
  --bg-mask-b3: rgba(248, 250, 247, 0.04);
  --bg-mask-web-a1: rgba(248, 250, 247, 0.58);
  --bg-mask-web-a2: rgba(248, 250, 247, 0.32);
  --bg-mask-web-a3: rgba(236, 244, 238, 0.1);
  --bg-mask-web-a4: rgba(255, 255, 255, 0.02);
  --bg-mask-web-b1: rgba(255, 255, 255, 0.12);
  --bg-mask-web-b2: rgba(236, 244, 238, 0.22);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  scroll-behavior: smooth;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  min-height: 100dvh;
  font-family: "Noto Sans SC", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei",
    system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background-color: var(--felt-deep);
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

/* Dual-layer day/night backdrop: crossfade via opacity on html[data-theme] */
.bg-stack {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

.bg-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-repeat: no-repeat;
  background-size: cover, cover, cover;
  transition: opacity var(--bg-crossfade) ease;
  will-change: opacity;
}

/* Night: deep green mask + silhouette */
.bg-layer.bg-night {
  background-color: #071f18;
  background-position: center, center, 70% 28%;
  background-image:
    linear-gradient(
      180deg,
      rgba(7, 31, 24, 0.55) 0%,
      rgba(7, 31, 24, 0.42) 32%,
      rgba(7, 31, 24, 0.78) 72%,
      rgba(7, 31, 24, 0.9) 100%
    ),
    linear-gradient(
      90deg,
      rgba(7, 31, 24, 0.78) 0%,
      rgba(7, 31, 24, 0.4) 48%,
      rgba(7, 31, 24, 0.12) 100%
    ),
    url("./assets/bg-mobile.png");
  opacity: 1;
}

/* Day: cool soft mist (not dirty yellow) + day art */
.bg-layer.bg-day {
  background-color: #f4efe4;
  background-position: center, center, 70% 28%;
  background-image:
    linear-gradient(
      180deg,
      rgba(248, 250, 247, 0.48) 0%,
      rgba(248, 250, 247, 0.2) 34%,
      rgba(236, 244, 238, 0.36) 72%,
      rgba(248, 250, 247, 0.52) 100%
    ),
    linear-gradient(
      90deg,
      rgba(248, 250, 247, 0.5) 0%,
      rgba(248, 250, 247, 0.16) 48%,
      rgba(255, 255, 255, 0.02) 100%
    ),
    url("./assets/bg-day-mobile.png");
  opacity: 0;
}

html[data-theme="day"] .bg-layer.bg-night {
  opacity: 0;
}

html[data-theme="day"] .bg-layer.bg-day {
  opacity: 1;
}

html[data-theme="night"] .bg-layer.bg-night {
  opacity: 1;
}

html[data-theme="night"] .bg-layer.bg-day {
  opacity: 0;
}

@media (min-width: 768px) {
  .bg-layer.bg-night {
    background-position: center, center, right 35%;
    background-image:
      linear-gradient(
        90deg,
        rgba(7, 31, 24, 0.9) 0%,
        rgba(7, 31, 24, 0.7) 34%,
        rgba(7, 31, 24, 0.28) 68%,
        rgba(7, 31, 24, 0.12) 100%
      ),
      linear-gradient(
        180deg,
        rgba(7, 31, 24, 0.28) 0%,
        rgba(7, 31, 24, 0.5) 100%
      ),
      url("./assets/bg-web.png");
  }

  .bg-layer.bg-day {
    background-position: center, center, right 35%;
    background-image:
      linear-gradient(
        90deg,
        rgba(248, 250, 247, 0.62) 0%,
        rgba(248, 250, 247, 0.34) 32%,
        rgba(236, 244, 238, 0.1) 62%,
        rgba(255, 255, 255, 0.02) 100%
      ),
      linear-gradient(
        180deg,
        rgba(255, 255, 255, 0.14) 0%,
        rgba(236, 244, 238, 0.22) 100%
      ),
      url("./assets/bg-day-web.png");
  }
}

@media (min-width: 1100px) {
  body {
    justify-content: flex-start;
    padding-left: max(24px, calc((100vw - 920px) / 2));
    padding-right: 24px;
  }

  .bg-layer.bg-night,
  .bg-layer.bg-day {
    background-position: center, center, right 40%;
  }
}

@media (max-width: 380px) {
  .bg-layer.bg-night,
  .bg-layer.bg-day {
    background-position: center, center, 78% 22%;
  }
}

/* Sunrise / dusk veil + staged crossfade */
.bg-veil {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  opacity: 0;
  background-repeat: no-repeat;
  background-size: 140% 140%;
  background-position: 50% 110%;
  will-change: opacity, background-position;
}

html.theme-switching {
  --bg-crossfade: 0.95s;
  --theme-color-dur: 0.5s;
}

html.theme-switching .theme-toggle button,
html.theme-switching [data-theme-set] {
  pointer-events: none;
  cursor: wait;
  opacity: 0.72;
}

html.theme-switching .bg-layer {
  transition:
    opacity var(--bg-crossfade) cubic-bezier(0.4, 0.05, 0.2, 1),
    filter 0.75s ease;
}

/* Night → Day: amber gold rises; night dims then fades; day fades in */
html.theme-switching.theme-to-day .bg-veil {
  background-image: linear-gradient(
    18deg,
    rgba(255, 176, 72, 0.62) 0%,
    rgba(255, 210, 120, 0.38) 28%,
    rgba(255, 236, 190, 0.16) 52%,
    rgba(255, 250, 235, 0) 78%
  );
  mix-blend-mode: screen;
  animation: theme-veil-sunrise 1.25s cubic-bezier(0.33, 0.1, 0.25, 1) forwards;
}

html.theme-switching.theme-to-day .bg-layer.bg-night {
  opacity: 0;
  filter: brightness(0.55);
}

html.theme-switching.theme-to-day .bg-layer.bg-day {
  opacity: 1;
  filter: none;
  transition-delay: 0.08s;
}

/* Day → Night: deep teal dusk; day fades; night rises */
html.theme-switching.theme-to-night .bg-veil {
  background-image: linear-gradient(
    200deg,
    rgba(18, 42, 68, 0.55) 0%,
    rgba(12, 58, 52, 0.42) 36%,
    rgba(6, 28, 36, 0.28) 62%,
    rgba(4, 18, 24, 0) 88%
  );
  mix-blend-mode: soft-light;
  animation: theme-veil-dusk 1.25s cubic-bezier(0.33, 0.1, 0.25, 1) forwards;
}

html.theme-switching.theme-to-night .bg-layer.bg-day {
  opacity: 0;
  filter: brightness(0.7);
}

html.theme-switching.theme-to-night .bg-layer.bg-night {
  opacity: 1;
  filter: none;
  transition-delay: 0.06s;
}

@keyframes theme-veil-sunrise {
  0% {
    opacity: 0;
    background-position: 50% 130%;
  }
  16% {
    opacity: 0.9;
    background-position: 48% 70%;
  }
  48% {
    opacity: 0.55;
    background-position: 46% 40%;
  }
  78% {
    opacity: 0.22;
    background-position: 45% 28%;
  }
  100% {
    opacity: 0;
    background-position: 44% 18%;
  }
}

@keyframes theme-veil-dusk {
  0% {
    opacity: 0;
    background-position: 50% -10%;
  }
  18% {
    opacity: 0.85;
    background-position: 52% 30%;
  }
  50% {
    opacity: 0.5;
    background-position: 54% 55%;
  }
  80% {
    opacity: 0.2;
    background-position: 55% 75%;
  }
  100% {
    opacity: 0;
    background-position: 56% 100%;
  }
}

/* Fixed grain - pointer-events none */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 40;
  opacity: var(--grain-opacity);
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-repeat: repeat;
  background-size: 180px 180px;
  mix-blend-mode: overlay;
}

body {
  display: flex;
  justify-content: center;
  padding: 14px 12px 48px;
  position: relative;
  transition: background-color var(--theme-color-dur) ease, color var(--theme-color-dur) ease;
}

/* Theme color crossfade for major chrome (transform stays on component rules) */
.panel,
.tool-card,
.topnav,
.badge,
.sub,
.disclaimer,
.header h1,
.section-title,
.toast-msg,
.theme-toggle,
.result-panel,
.yaku-item,
table,
th,
td {
  transition: background-color var(--theme-color-dur) ease, color var(--theme-color-dur) ease,
    border-color var(--theme-color-dur) ease, box-shadow var(--theme-color-dur) ease,
    background var(--theme-color-dur) ease;
}

.app {
  width: 100%;
  max-width: 375px;
  position: relative;
  z-index: 1;
}

@media (min-width: 768px) {
  .app {
    max-width: 420px;
  }
}

@media (min-width: 1100px) {
  .app {
    max-width: 440px;
  }
}

/* -- Typography -- */
.header {
  text-align: left;
  padding: 6px 2px 16px;
}

.header h1 {
  margin: 0;
  font-size: 1.55rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.15;
  color: var(--gold-hi);
  text-shadow: var(--header-shadow);
  text-wrap: balance;
}

.header .sub {
  margin-top: 8px;
  font-size: 0.78rem;
  color: var(--ink-dim);
  line-height: 1.5;
  max-width: 32em;
  text-wrap: pretty;
}

.badge {
  display: inline-block;
  margin-top: 10px;
  padding: 4px 11px;
  border: 1px solid var(--gold-line-strong);
  border-radius: 6px;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: none;
  color: var(--gold);
  background: var(--badge-bg);
}

.section-title {
  font-size: 0.72rem;
  color: var(--gold);
  letter-spacing: 0.14em;
  margin: 0 0 12px;
  font-weight: 700;
}

.num,
.points,
.fu-total .rounded,
.score-table,
.yi-han,
.ci-fu,
.meta,
.result-card .limit {
  font-variant-numeric: tabular-nums;
}

.points,
.fu-total .rounded {
  font-family: ui-monospace, "SF Mono", "Cascadia Mono", "Menlo", "Consolas", monospace;
}

/* -- Floating glass topnav -- */
.topnav {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  padding: 5px 6px 5px 5px;
  border-radius: 999px;
  background: var(--surface-glass);
  border: 1px solid var(--topnav-border);
  box-shadow:
    inset 0 1px 0 var(--inset-hi),
    var(--topnav-shadow);
  -webkit-backdrop-filter: blur(14px) saturate(1.25);
  backdrop-filter: blur(14px) saturate(1.25);
  position: sticky;
  top: 8px;
  z-index: 30;
}

.topnav a {
  color: var(--text-on-gold);
  text-decoration: none;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 8px 14px;
  border: none;
  border-radius: 999px;
  background: linear-gradient(160deg, var(--gold-hi), var(--gold-lo));
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  transition: transform var(--dur) var(--ease), opacity var(--dur) var(--ease),
    filter var(--dur) var(--ease), background var(--theme-color-dur) ease,
    color var(--theme-color-dur) ease;
}

.topnav a:hover {
  filter: brightness(1.06);
  transform: translateY(-1px);
}

.topnav a:active {
  transform: scale(0.98);
  filter: brightness(0.96);
}

.topnav a:focus-visible {
  outline: 2px solid var(--gold-hi);
  outline-offset: 2px;
}

.topnav .crumb {
  flex: 1;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  color: var(--ink-dim);
  text-align: right;
  padding-right: 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (prefers-reduced-transparency: reduce) {
  .topnav {
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    background: var(--surface-glass-solid);
  }
}

/* -- Double-bezel surfaces -- */
.panel {
  position: relative;
  background: linear-gradient(165deg, var(--panel-outer-start) 0%, var(--panel-outer-end) 100%);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-outer);
  box-shadow:
    0 0 0 3px var(--panel-bezel),
    0 0 0 4px var(--panel-bezel-gold),
    var(--shadow);
  padding: 3px;
  margin-bottom: 14px;
}

.panel::before {
  content: "";
  display: block;
  position: absolute;
  inset: 3px;
  border-radius: var(--radius-inner);
  background: var(--card);
  border: 1px solid var(--panel-inner-border);
  box-shadow: inset 0 1px 0 var(--inset-hi-soft);
  pointer-events: none;
  z-index: 0;
}

.panel > * {
  position: relative;
  z-index: 1;
}

.panel {
  padding: 15px 14px 17px;
}

/* -- Forms -- */
.row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.row:last-child {
  margin-bottom: 0;
}

label.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  min-width: 0;
}

label.field > span {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--ink-dim);
}

select,
input[type="number"],
input[type="search"],
input[type="text"] {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border-radius: var(--radius-inner);
  border: 1px solid var(--gold-line);
  background: var(--input-bg);
  color: var(--ink);
  font-size: 1rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  transition: border-color var(--theme-color-dur) ease, box-shadow var(--theme-color-dur) ease,
    background-color var(--theme-color-dur) ease, color var(--theme-color-dur) ease,
    background var(--theme-color-dur) ease;
}

select:hover,
input:hover {
  border-color: var(--gold-line-strong);
}

select:focus-visible,
input:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
  border-color: var(--gold);
}

select:focus,
input:focus {
  outline: 2px solid var(--gold);
  outline-offset: 1px;
}

.seg {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  width: 100%;
}

.seg.seg-3 {
  grid-template-columns: 1fr 1fr 1fr;
}

.seg button {
  min-height: 48px;
  border-radius: var(--radius-inner);
  border: 1px solid var(--gold-line);
  background: var(--input-bg);
  color: var(--ink-dim);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform var(--dur) var(--ease), opacity var(--dur) var(--ease),
    background var(--theme-color-dur) ease, color var(--theme-color-dur) ease,
    border-color var(--theme-color-dur) ease, box-shadow var(--theme-color-dur) ease;
}

.seg button:hover {
  border-color: var(--gold-line-strong);
  color: var(--ink);
  opacity: 0.95;
}

.seg button:active {
  transform: scale(0.98);
}

.seg button:focus-visible {
  outline: 2px solid var(--gold-hi);
  outline-offset: 2px;
}

.seg button.active {
  background: linear-gradient(160deg, var(--gold-hi), var(--gold-lo));
  color: var(--text-on-gold);
  border-color: var(--gold-hi);
  box-shadow: var(--shadow-gold);
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  min-height: 40px;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--gold-line);
  background: var(--input-bg);
  color: var(--ink-dim);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform var(--dur) var(--ease), opacity var(--dur) var(--ease),
    background var(--theme-color-dur) ease, color var(--theme-color-dur) ease,
    border-color var(--theme-color-dur) ease;
}

.chip:hover {
  border-color: var(--gold-line-strong);
  color: var(--ink);
}

.chip:active {
  transform: scale(0.98);
}

.chip:focus-visible {
  outline: 2px solid var(--gold-hi);
  outline-offset: 2px;
}

.chip.active {
  background: linear-gradient(160deg, var(--gold-hi), var(--gold-lo));
  color: var(--text-on-gold);
  border-color: var(--gold-hi);
}

.hint {
  font-size: 0.72rem;
  color: var(--ink-dim);
  margin-top: 8px;
  line-height: 1.45;
}

.hint.warn {
  color: var(--danger);
}

/* -- Buttons -- */
.btn {
  min-height: 48px;
  border-radius: var(--radius-inner);
  border: none;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  padding: 0 14px;
  transition: transform var(--dur) var(--ease), opacity var(--dur) var(--ease),
    filter var(--dur) var(--ease), background var(--theme-color-dur) ease,
    border-color var(--theme-color-dur) ease, color var(--theme-color-dur) ease,
    box-shadow var(--theme-color-dur) ease;
}

.btn:hover {
  filter: brightness(1.05);
  opacity: 0.96;
}

.btn:active {
  transform: scale(0.98);
  filter: brightness(0.97);
}

.btn:focus-visible {
  outline: 2px solid var(--gold-hi);
  outline-offset: 2px;
}

.btn-primary {
  background: linear-gradient(160deg, var(--gold-hi), var(--gold-lo));
  color: var(--text-on-gold);
  box-shadow: var(--shadow-gold);
}

.btn-ghost {
  background: var(--btn-ghost-bg);
  border: 1px solid var(--gold-line-strong);
  color: var(--ink);
}

.btn-danger {
  background: transparent;
  border: 1px solid rgba(212, 90, 90, 0.5);
  color: var(--danger);
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}

.actions.full {
  grid-template-columns: 1fr;
}

/* -- Home: equal two-column tool grid -- */
.tool-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  align-items: stretch;
}

.tool-card {
  display: flex;
  flex-direction: column;
  text-decoration: none;
  color: inherit;
  position: relative;
  background: linear-gradient(165deg, var(--panel-outer-start) 0%, var(--panel-outer-end) 100%);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-outer);
  padding: 3px;
  box-shadow:
    0 0 0 3px var(--panel-bezel),
    0 0 0 4px var(--panel-bezel-gold),
    var(--shadow);
  min-height: 40px;
  transition: transform var(--dur) var(--ease), opacity var(--dur) var(--ease),
    border-color var(--theme-color-dur) ease, box-shadow var(--theme-color-dur) ease,
    background var(--theme-color-dur) ease, color var(--theme-color-dur) ease;
}

.tool-card::before {
  content: "";
  position: absolute;
  inset: 3px;
  border-radius: var(--radius-inner);
  background: var(--card);
  border: 1px solid var(--panel-inner-border);
  box-shadow: inset 0 1px 0 var(--inset-hi-soft);
  pointer-events: none;
  z-index: 0;
}

.tool-card > * {
  position: relative;
  z-index: 1;
}

.tool-card {
  padding: 14px 13px 12px;
}

.tool-card--wide {
  grid-column: 1 / -1;
}

.tool-card--feature {
  grid-column: 1 / -1;
  padding: 18px 16px 14px;
}

.tool-card--feature h2 {
  font-size: 1.2rem;
}

.tool-card--feature p {
  font-size: 0.82rem;
  max-width: 28em;
}

.tool-card:hover {
  transform: translateY(-2px);
  opacity: 0.98;
  border-color: var(--panel-border-hover);
  box-shadow:
    0 0 0 3px var(--panel-bezel),
    0 0 0 4px var(--panel-bezel-gold-hover),
    var(--tool-hover-shadow);
}

.tool-card:active {
  transform: scale(0.98);
  opacity: 0.94;
}

.tool-card:focus-visible {
  outline: 2px solid var(--gold-hi);
  outline-offset: 3px;
}

.tool-card h2 {
  margin: 0 0 6px;
  font-size: 0.98rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--gold-hi);
  line-height: 1.2;
}

.tool-card p {
  margin: 0 0 12px;
  font-size: 0.74rem;
  color: var(--ink-dim);
  line-height: 1.45;
  flex: 1;
}

.tool-card .go {
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--gold);
  margin-top: auto;
}

.disclaimer {
  margin-top: 16px;
  font-size: 0.62rem;
  color: var(--disclaimer);
  text-align: left;
  line-height: 1.55;
}

/* -- Check lists / yaku -- */
.check-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.check-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 12px;
  border-radius: var(--radius-inner);
  border: 1px solid var(--check-border);
  background: var(--check-bg);
  cursor: pointer;
  user-select: none;
  min-height: 40px;
  transition: border-color var(--theme-color-dur) ease, transform var(--dur) var(--ease),
    background-color var(--theme-color-dur) ease, background var(--theme-color-dur) ease,
    color var(--theme-color-dur) ease;
}

.check-item:hover {
  border-color: var(--gold-line-strong);
}

.check-item:active {
  transform: scale(0.99);
}

.check-item input {
  margin-top: 3px;
  width: 18px;
  height: 18px;
  accent-color: var(--gold);
  flex-shrink: 0;
}

.check-item .ci-body {
  flex: 1;
  min-width: 0;
}

.check-item .ci-name {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.01em;
}

.check-item .ci-meta {
  font-size: 0.72rem;
  color: var(--ink-dim);
  margin-top: 2px;
}

.check-item .ci-fu {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--gold);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.fu-total {
  text-align: center;
  padding: 8px 0;
}

.fu-total .raw {
  font-size: 0.8rem;
  color: var(--ink-dim);
}

.fu-total .rounded {
  font-size: 2.1rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--gold-hi);
  margin: 4px 0;
  font-variant-numeric: tabular-nums;
}

.fu-total .suggest {
  font-size: 0.85rem;
  color: var(--gold);
}

.yaku-item {
  padding: 12px 0;
  border-bottom: 1px solid var(--yaku-divider);
}

.yaku-item:last-child {
  border-bottom: none;
}

.yaku-item .yi-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.yaku-item .yi-name {
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: -0.01em;
}

.yaku-item .yi-han {
  font-size: 0.78rem;
  color: var(--gold-hi);
  font-weight: 700;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
}

.yaku-item .yi-desc {
  margin-top: 4px;
  font-size: 0.75rem;
  color: var(--ink-dim);
  line-height: 1.4;
}

.yaku-item .yi-tag {
  display: inline-block;
  margin-top: 4px;
  font-size: 0.65rem;
  letter-spacing: 0.06em;
  color: var(--gold);
  border: 1px solid var(--gold-line);
  border-radius: 4px;
  padding: 2px 8px;
}

.cat-head {
  margin: 14px 0 6px;
  font-size: 0.78rem;
  color: var(--gold);
  font-weight: 700;
  letter-spacing: 0.12em;
}

/* -- Score table -- */
.score-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -4px;
}

.score-table {
  border-collapse: collapse;
  width: 100%;
  min-width: 320px;
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
}

.score-table th,
.score-table td {
  border: 1px solid var(--table-border);
  padding: 7px 4px;
  text-align: center;
  white-space: nowrap;
}

.score-table th {
  background: var(--table-th-bg);
  color: var(--gold);
  font-weight: 700;
  letter-spacing: 0.04em;
  position: sticky;
  top: 0;
}

.score-table td.han-label {
  color: var(--gold);
  font-weight: 700;
  background: var(--table-han-bg);
}

.score-table td.clickable {
  cursor: pointer;
  color: var(--ink);
  transition: background var(--dur) var(--ease);
}

.score-table td.clickable:hover {
  background: var(--table-hover);
}

.score-table td.clickable:active {
  background: var(--table-active);
  transform: scale(0.98);
}

.score-table td.na {
  color: var(--table-na);
}

.score-table .limit-row td {
  background: var(--table-limit-bg);
  font-weight: 700;
  color: var(--gold-hi);
}

/* -- Result -- */
.result-card {
  text-align: center;
  padding: 18px 12px;
}

.result-card .limit {
  font-size: 0.82rem;
  color: var(--gold-hi);
  letter-spacing: 0.14em;
  min-height: 1.2em;
  font-weight: 700;
}

.result-card .points {
  font-size: 2.05rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--ink);
  margin: 8px 0 4px;
  line-height: 1.15;
  word-break: break-all;
  font-variant-numeric: tabular-nums;
}

.result-card .detail {
  font-size: 0.85rem;
  color: var(--ink-dim);
  line-height: 1.5;
  white-space: pre-line;
}

.result-card .meta {
  margin-top: 10px;
  font-size: 0.78rem;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
}

.canvas-wrap {
  margin-top: 12px;
  display: none;
  text-align: center;
}

.canvas-wrap.show {
  display: block;
}

#shareCanvas {
  width: 100%;
  max-width: 351px;
  height: auto;
  border-radius: var(--radius-inner);
  border: 1px solid var(--gold-line-strong);
  box-shadow: var(--shadow);
}

.footer-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

.footer-tools .btn {
  flex: 1;
  min-width: 140px;
  font-size: 0.8rem;
  min-height: 42px;
}

#selfTestOut {
  margin-top: 10px;
  font-size: 0.72rem;
  line-height: 1.45;
  white-space: pre-wrap;
  color: var(--ink-dim);
  max-height: 180px;
  overflow: auto;
  display: none;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-variant-numeric: tabular-nums;
}

#selfTestOut.show {
  display: block;
}

#selfTestOut.ok {
  color: var(--ok);
}

#selfTestOut.bad {
  color: var(--danger);
}

.qty-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}

.qty-row select {
  min-height: 40px;
  font-size: 0.85rem;
  flex: 1;
}

/* Phone: keep equal halves; only the featured card spans full width */
@media (max-width: 420px) {
  .tool-grid {
    gap: 8px;
  }

  .tool-card {
    padding: 12px 10px 10px;
  }

  .tool-card h2 {
    font-size: 0.9rem;
  }

  .tool-card p {
    font-size: 0.68rem;
    margin-bottom: 8px;
    line-height: 1.4;
  }

  .tool-card .go {
    font-size: 0.72rem;
  }

  .tool-card--feature {
    grid-column: 1 / -1;
    padding: 16px 14px 12px;
  }

  .tool-card--feature h2 {
    font-size: 1.12rem;
  }

  .tool-card--feature p {
    font-size: 0.78rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
    --bg-crossfade: 0.01ms;
    --theme-color-dur: 0.01ms;
  }

  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }

  .tool-card:hover,
  .topnav a:hover,
  .btn:hover {
    transform: none;
  }

  .tool-card:active,
  .btn:active,
  .seg button:active,
  .chip:active,
  .topnav a:active {
    transform: none;
  }
}

/* -- Self-drawn tiles (no official art) -- */
.tile-hand,
.tile-picker,
.tile-waits {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.tile {
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid rgba(40, 28, 12, 0.55);
  border-radius: 6px;
  width: 34px;
  height: 46px;
  padding: 2px 0 0;
  margin: 0;
  background: linear-gradient(165deg, #f7f1e4 0%, #e8dfcc 55%, #d9cfb8 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.7),
    0 2px 4px rgba(4, 28, 20, 0.35);
  color: #1a1208;
  cursor: pointer;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1;
  font-family: inherit;
  transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
  user-select: none;
}

.tile:hover {
  transform: translateY(-2px);
}

.tile:active {
  transform: scale(0.96);
}

.tile:focus-visible {
  outline: 2px solid var(--gold-hi);
  outline-offset: 2px;
}

.tile.is-selected,
.tile.is-pick {
  box-shadow:
    0 0 0 2px var(--gold-hi),
    0 4px 10px rgba(60, 48, 8, 0.35);
}

.tile.is-dim {
  opacity: 0.45;
}

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

.tile-num {
  font-size: 0.95rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.tile-suit {
  font-size: 0.55rem;
  font-weight: 700;
  margin-top: 1px;
  letter-spacing: 0.04em;
}

.tile-face {
  font-size: 0.85rem;
  font-weight: 800;
}

.tile--m .tile-num,
.tile--m .tile-suit {
  color: #1a1a1a;
}

.tile--p .tile-num,
.tile--p .tile-suit {
  color: #1a5a9a;
}

.tile--s .tile-num,
.tile--s .tile-suit {
  color: #1a7a3a;
}

.tile--z .tile-face {
  color: #8a1a1a;
}

.tile--z[data-code="z5"] .tile-face,
.tile--z[data-code="z6"] .tile-face {
  color: #1a7a3a;
}

.tile--z[data-code="z5"] .tile-face {
  color: #2a2a2a;
}

.tile-picker-block {
  margin-bottom: 10px;
}

.tile-picker-block .label {
  font-size: 0.68rem;
  color: var(--ink-dim);
  margin-bottom: 6px;
  letter-spacing: 0.08em;
}

.hand-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  font-size: 0.78rem;
  color: var(--ink-dim);
}

.hand-meta strong {
  color: var(--gold-hi);
  font-variant-numeric: tabular-nums;
}

.result-big {
  font-size: 1.65rem;
  font-weight: 800;
  color: var(--gold-hi);
  font-variant-numeric: tabular-nums;
  margin: 4px 0 8px;
}

.check-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 10px;
}

.check-grid label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--ink);
  min-height: 36px;
}

.check-grid input {
  width: 18px;
  height: 18px;
  accent-color: var(--gold);
}

.yaku-hit {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--yaku-hit-divider);
  font-size: 0.88rem;
}

.yaku-hit:last-child {
  border-bottom: none;
}

.yaku-hit .han {
  color: var(--gold);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.support-list {
  font-size: 0.72rem;
  color: var(--ink-dim);
  line-height: 1.55;
}

.support-list strong {
  color: var(--ink);
  font-weight: 600;
}

.feedback-ok {
  color: var(--ok);
  font-weight: 700;
}

.feedback-bad {
  color: var(--danger);
  font-weight: 700;
}

.ok { color: var(--ok); font-weight: 700; }
.bad { color: var(--danger); font-weight: 700; }
.hand-meta {
  margin-top: 8px;
  font-size: 0.8rem;
  color: var(--ink-dim);
}
.hand-meta strong {
  color: var(--gold-hi);
  font-variant-numeric: tabular-nums;
}
.tile.is-pick {
  box-shadow: 0 0 0 2px var(--danger), 0 4px 10px rgba(60, 20, 8, 0.35);
}

/* 赤宝 */
.tile--aka .tile-num,
.tile.tile--aka .tile-num {
  color: #e85d5d !important;
  font-weight: 800;
}
.tile--aka {
  box-shadow: inset 0 0 0 1px rgba(232, 93, 93, 0.45);
}

/* 内联提示（替代 alert） */
.toast-msg {
  margin-top: 8px;
  padding: 8px 12px;
  border-radius: var(--radius-inner, 11px);
  background: var(--toast-bad-bg);
  border: 1px solid var(--toast-bad-border);
  color: var(--toast-bad-ink);
  font-size: 0.85rem;
  display: none;
}
.toast-msg.show { display: block; }
.toast-msg.ok {
  background: var(--toast-ok-bg);
  border-color: var(--toast-ok-border);
  color: var(--toast-ok-ink);
}

/* 进张/切牌对比表 */
.compare-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  margin-top: 10px;
}
.compare-table th,
.compare-table td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--compare-border);
  text-align: left;
}
.compare-table th { color: var(--gold-hi, #d4b03a); font-weight: 600; }
.compare-table tr.is-best td { color: var(--ok, #5bbf82); font-weight: 600; }
.compare-table tr.is-pick td { background: rgba(212, 90, 90, 0.08); }

.stats-bar {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 0.85rem;
  color: var(--ink-dim, #b8ae98);
  margin-top: 8px;
}
.stats-bar strong { color: var(--gold-hi, #d4b03a); }

.fuuro-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
}
.fuuro-chip {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  padding: 4px 8px;
  border-radius: 8px;
  background: var(--fuuro-bg);
  border: 1px solid var(--fuuro-border);
  font-size: 0.8rem;
}
.num-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
}
.num-row label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.78rem;
  color: var(--ink-dim, #b8ae98);
}
.num-row input[type="number"] {
  width: 72px;
  min-height: 40px;
}


/* -- Theme toggle -- */
.theme-bar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 8px;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
  padding: 3px;
  border-radius: 999px;
  background: var(--btn-ghost-bg);
  border: 1px solid var(--gold-line);
}

.topnav .theme-toggle {
  margin-left: 0;
}

.theme-toggle button {
  appearance: none;
  -webkit-appearance: none;
  border: none;
  cursor: pointer;
  min-height: 32px;
  min-width: 36px;
  padding: 0 10px;
  border-radius: 999px;
  background: transparent;
  color: var(--ink-dim);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background var(--theme-color-dur) ease, color var(--theme-color-dur) ease,
    transform var(--dur) var(--ease), box-shadow var(--theme-color-dur) ease,
    opacity var(--theme-color-dur) ease;
}

.theme-toggle .theme-icon {
  display: block;
  flex-shrink: 0;
}

.theme-toggle button:disabled {
  cursor: wait;
}

.theme-toggle button:hover {
  color: var(--ink);
}

.theme-toggle button:focus-visible {
  outline: 2px solid var(--gold-hi);
  outline-offset: 1px;
}

.theme-toggle button.active {
  background: linear-gradient(160deg, var(--gold-hi), var(--gold-lo));
  color: var(--text-on-gold);
  box-shadow: var(--shadow-gold);
}

.theme-toggle button:active {
  transform: scale(0.98);
}

.topnav .crumb {
  padding-right: 6px;
}

/* 牌理测验选项区 */
.quiz-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.quiz-options .quiz-opt {
  cursor: pointer;
}
.quiz-options .btn {
  width: 100%;
}


/* -- Home SPA tool shell (iframe host) -- */
body.tool-open {
  overflow: hidden;
  height: 100dvh;
}

body.tool-open .app {
  max-width: none;
  width: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: 0;
}

/* Parent keeps the only illustrated background; iframe content stays clear of a second copy */
body.tool-open .tool-shell {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  margin: 0;
}

.tool-shell {
  display: flex;
  flex-direction: column;
  min-height: calc(100dvh - 12px);
  margin: 0;
}

.tool-shell[hidden] {
  display: none !important;
}

.tool-shell-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px 10px;
  position: sticky;
  top: 0;
  z-index: 5;
  flex: 0 0 auto;
  background: linear-gradient(180deg, color-mix(in srgb, var(--bg) 92%, transparent) 65%, transparent);
}

.tool-shell-back {
  flex: 0 0 auto;
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--gold);
  text-decoration: none;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--panel-border);
  background: var(--card);
}

.tool-shell-back:active {
  transform: scale(0.98);
}

.tool-shell-title {
  flex: 1;
  min-width: 0;
  font-size: 0.92rem;
  font-weight: 800;
  color: var(--gold-hi);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tool-shell-frame {
  flex: 1;
  width: 100%;
  min-height: 0;
  height: 100%;
  border: 0;
  border-radius: 0;
  background: transparent;
}

/* Tool pages loaded inside the home iframe */
html.embedded .bg-layer,
html.embedded .bg-veil,
html.embedded .bg-noise {
  display: none !important;
}

html.embedded,
html.embedded body {
  background: transparent !important;
  min-height: 100%;
}

html.embedded {
  height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-gutter: stable;
}

html.embedded body {
  /* Let the parent shell background show through; avoid a second illustrated layer */
  overflow-x: hidden;
  overflow-y: visible;
  min-height: 100%;
}

html.embedded .app {
  /* Still phone-first column, but no competing full-bleed art behind panels */
  background: transparent;
}

html.embedded .topnav > a:first-of-type {
  /* Shell already has「返回首页」 */
  visibility: hidden;
  pointer-events: none;
}

@media (min-width: 768px) {
  html.embedded .app {
    max-width: 520px;
  }
}

@media (min-width: 1100px) {
  html.embedded .app {
    max-width: 560px;
  }
}


/* -- Cross-tool carry banner -- */
.carry-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 0 12px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--panel-border);
  background: color-mix(in srgb, var(--gold) 14%, var(--card));
  color: var(--ink);
  font-size: 0.82rem;
  line-height: 1.35;
}

.carry-banner-msg {
  flex: 1;
  min-width: 0;
}

.carry-banner-back {
  flex: 0 0 auto;
  border: 1px solid var(--panel-border);
  background: var(--card);
  color: var(--gold);
  font-weight: 700;
  font-size: 0.78rem;
  border-radius: 999px;
  padding: 5px 10px;
  cursor: pointer;
}

.carry-banner-x {
  flex: 0 0 auto;
  border: 0;
  background: transparent;
  color: var(--ink-dim);
  font-size: 1.1rem;
  line-height: 1;
  padding: 2px 6px;
  cursor: pointer;
}


/* -- Premium polish layer (redesign skill) -- */
/* Design read: mahjong utility toy, preserve felt/gold brand, mobile-first product UI */

:root,
html[data-theme="night"],
html[data-theme="day"] {
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-spring: cubic-bezier(0.32, 0.72, 0, 1);
  --dur-fast: 160ms;
  --dur-med: 280ms;
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  font-family:
    "Noto Sans SC",
    "Source Han Sans SC",
    "PingFang SC",
    "Hiragino Sans GB",
    "Microsoft YaHei UI",
    "Microsoft YaHei",
    system-ui,
    -apple-system,
    sans-serif;
  letter-spacing: 0.01em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.app {
  padding-left: max(12px, env(safe-area-inset-left));
  padding-right: max(12px, env(safe-area-inset-right));
  padding-bottom: max(28px, env(safe-area-inset-bottom));
}

/* Typography presence */
.header {
  padding: 8px 2px 18px;
}

.header h1 {
  font-family:
    "Noto Serif SC",
    "Source Han Serif SC",
    "Songti SC",
    "STSong",
    "SimSun",
    serif;
  font-size: clamp(1.45rem, 5.2vw, 1.75rem);
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1.2;
  text-wrap: balance;
}

.header .sub,
.header .subtitle,
.header p.sub {
  margin-top: 8px;
  font-size: 0.8rem;
  line-height: 1.55;
  max-width: 34em;
  text-wrap: pretty;
  color: var(--ink-dim);
}

.badge {
  margin-top: 12px;
  padding: 5px 12px;
  border-radius: 999px;
  letter-spacing: 0.14em;
  font-size: 0.62rem;
  font-weight: 700;
  box-shadow: inset 0 1px 0 var(--inset-hi-soft, rgba(255, 255, 255, 0.08));
}

.section-title {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.68rem;
  letter-spacing: 0.16em;
  margin: 0 0 14px;
  padding: 4px 0;
  color: var(--gold);
  font-weight: 700;
}

.section-title::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--gold) 22%, transparent);
  flex: 0 0 auto;
}

/* Panels: deeper machine-bezel feel */
.panel {
  margin-bottom: 16px;
  border-radius: calc(var(--radius-outer) + 2px);
  transition:
    border-color var(--dur-med) var(--ease-out),
    box-shadow var(--dur-med) var(--ease-out),
    transform var(--dur-med) var(--ease-out);
}

.panel::before {
  border-radius: calc(var(--radius-inner) + 1px);
  box-shadow:
    inset 0 1px 0 var(--inset-hi-soft, rgba(255, 255, 255, 0.07)),
    inset 0 -1px 0 rgba(0, 0, 0, 0.12);
}

.panel:focus-within {
  border-color: var(--panel-border-hover, var(--gold-line-strong));
}

/* Forms */
label.field > span {
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: none;
}

select,
input[type="number"],
input[type="search"],
input[type="text"] {
  min-height: 50px;
  border-radius: 12px;
  padding: 11px 14px;
  transition:
    border-color var(--dur-fast) var(--ease-out),
    box-shadow var(--dur-fast) var(--ease-out),
    background-color var(--theme-color-dur) ease,
    color var(--theme-color-dur) ease,
    transform var(--dur-fast) var(--ease-out);
}

select {
  background-image:
    linear-gradient(45deg, transparent 50%, var(--gold) 50%),
    linear-gradient(135deg, var(--gold) 50%, transparent 50%);
  background-position:
    calc(100% - 18px) calc(50% - 2px),
    calc(100% - 12px) calc(50% - 2px);
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  padding-right: 36px;
}

select:focus-visible,
input:focus-visible {
  outline: none;
  border-color: var(--gold);
  box-shadow:
    0 0 0 3px color-mix(in srgb, var(--gold) 28%, transparent),
    inset 0 1px 0 var(--inset-hi-soft, rgba(255, 255, 255, 0.06));
}

.seg button,
.chip,
.btn {
  transition:
    transform var(--dur-med) var(--ease-spring),
    opacity var(--dur-fast) var(--ease-out),
    filter var(--dur-fast) var(--ease-out),
    background var(--theme-color-dur) ease,
    color var(--theme-color-dur) ease,
    border-color var(--theme-color-dur) ease,
    box-shadow var(--dur-med) var(--ease-out);
}

.seg button {
  min-height: 50px;
  border-radius: 12px;
}

.seg button.active {
  box-shadow:
    var(--shadow-gold),
    inset 0 1px 0 rgba(255, 255, 255, 0.22);
}

.seg button:active,
.chip:active,
.btn:active {
  transform: scale(0.975);
}

.btn {
  min-height: 50px;
  border-radius: 12px;
  letter-spacing: 0.04em;
}

.btn-primary {
  box-shadow:
    var(--shadow-gold),
    inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

.btn-primary:hover {
  filter: brightness(1.07);
  transform: translateY(-1px);
}

.btn-ghost:hover {
  border-color: var(--gold);
  color: var(--gold-hi, var(--gold));
}

.actions {
  gap: 10px;
  margin-top: 14px;
}

@media (max-width: 360px) {
  .actions {
    grid-template-columns: 1fr;
  }
}

/* Results */
.result-card {
  padding: 20px 14px 18px;
}

.result-card .limit {
  font-size: 0.78rem;
  letter-spacing: 0.18em;
}

.result-card .points {
  font-size: clamp(1.85rem, 7vw, 2.35rem);
  margin: 10px 0 6px;
  letter-spacing: -0.03em;
  color: var(--gold-hi, var(--gold));
  text-shadow: 0 2px 16px color-mix(in srgb, var(--gold) 25%, transparent);
}

.result-card .detail {
  font-size: 0.84rem;
  line-height: 1.55;
}

.result-card .meta {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed color-mix(in srgb, var(--gold) 28%, transparent);
}

/* Topnav */
.topnav {
  margin-bottom: 14px;
  padding: 6px;
  box-shadow:
    inset 0 1px 0 var(--inset-hi, rgba(255, 255, 255, 0.08)),
    var(--topnav-shadow);
}

.topnav a {
  min-height: 42px;
  padding: 8px 16px;
  letter-spacing: 0.02em;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.22);
}

.topnav .crumb {
  letter-spacing: 0.14em;
  font-size: 0.68rem;
}

/* Home tool cards */
.tool-card {
  min-height: 118px;
  border-radius: calc(var(--radius-outer) + 2px);
  transition:
    transform var(--dur-med) var(--ease-spring),
    box-shadow var(--dur-med) var(--ease-out),
    border-color var(--dur-med) var(--ease-out),
    opacity var(--dur-fast) var(--ease-out);
}

.tool-card:hover {
  transform: translateY(-3px);
}

.tool-card:active {
  transform: scale(0.985);
}

.tool-card h2 {
  font-family:
    "Noto Serif SC",
    "Source Han Serif SC",
    "Songti SC",
    "STSong",
    serif;
  letter-spacing: 0.02em;
}

.tool-card .go {
  letter-spacing: 0.12em;
  font-weight: 700;
}

.tool-card--feature {
  min-height: 132px;
}

/* Check / yaku rows */
.check-item,
.yaku-item {
  border-radius: 12px;
  transition: background var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out);
}

/* Tables */
.score-table th,
.score-table td {
  transition: background var(--dur-fast) var(--ease-out);
}

.score-table td.clickable:hover,
.score-table td.clickable:focus-visible {
  background: var(--table-hover);
  outline: none;
}

/* Soft entrance for tool content (respect reduced motion) */
@media (prefers-reduced-motion: no-preference) {
  .app > .header,
  .app > .panel,
  .app > .result-card,
  .app > .tool-grid,
  .app > .disclaimer {
    animation: rise-in 480ms var(--ease-out) both;
  }

  .app > .panel:nth-of-type(1) { animation-delay: 40ms; }
  .app > .panel:nth-of-type(2) { animation-delay: 80ms; }
  .app > .panel:nth-of-type(3) { animation-delay: 120ms; }
  .app > .panel:nth-of-type(4) { animation-delay: 160ms; }
  .app > .result-card { animation-delay: 100ms; }
  .app > .tool-grid { animation-delay: 60ms; }
}

@keyframes rise-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .app > .header,
  .app > .panel,
  .app > .result-card,
  .app > .tool-grid,
  .app > .disclaimer {
    animation: none;
  }

  html {
    scroll-behavior: auto;
  }
}

/* Desktop tool pages: a bit more room without leaving mobile layout */
@media (min-width: 768px) {
  .app {
    max-width: 460px;
  }

  html.embedded .app {
    max-width: 520px;
  }
}

@media (min-width: 1100px) {
  .app {
    max-width: 480px;
  }

  html.embedded .app {
    max-width: 560px;
  }
}

/* -- 和風層 (riichi / Japanese) -- */
/* Felt green + gold kept; indigo/washi/seigaiha/shoji/seal on top. */

:root,
html[data-theme="night"] {
  --felt: #0a2e28;
  --felt-deep: #061a1c;
  --felt-mid: #0f3d36;
  --felt-light: #1a5248;
  --gold: #c4a35a;
  --gold-hi: #d4b86a;
  --gold-lo: #8f7340;
  --gold-line: rgba(196, 163, 90, 0.34);
  --gold-line-strong: rgba(196, 163, 90, 0.52);
  --gold-bright: var(--gold-hi);
  --amber: var(--gold);
  --ink: #f2ebe0;
  --ink-dim: #a8a090;
  --card: rgba(8, 28, 30, 0.9);
  --seal: #c45c4a;
  --washi: rgba(242, 235, 224, 0.05);
  --shoji: rgba(196, 163, 90, 0.3);
  --shoji-inner: rgba(242, 235, 224, 0.07);
  --panel-border: rgba(196, 163, 90, 0.28);
  --panel-border-hover: rgba(196, 163, 90, 0.48);
  --panel-inner-border: rgba(196, 163, 90, 0.16);
  --panel-bezel: rgba(6, 24, 28, 0.94);
  --panel-bezel-gold: rgba(196, 163, 90, 0.14);
  --font-display: "Noto Serif SC", "Source Han Serif SC", "Songti SC", "STSong", serif;
  --font-body: "Noto Sans SC", "Source Han Sans SC", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
}

html[data-theme="day"] {
  --felt: #d5e2d8;
  --felt-deep: #f4efe4;
  --felt-mid: #e4eee6;
  --felt-light: #c3d6c8;
  --gold: #9a7420;
  --gold-hi: #b08928;
  --gold-lo: #7a5c18;
  --gold-line: rgba(154, 116, 32, 0.36);
  --gold-line-strong: rgba(154, 116, 32, 0.55);
  --gold-bright: var(--gold-hi);
  --amber: var(--gold);
  --ink: #1c2420;
  --ink-dim: #5a655c;
  --card: rgba(255, 252, 246, 0.95);
  --seal: #b54336;
  --washi: rgba(90, 70, 40, 0.035);
  --shoji: rgba(90, 110, 95, 0.3);
  --shoji-inner: rgba(255, 255, 255, 0.5);
  --panel-border: rgba(90, 110, 95, 0.3);
  --panel-border-hover: rgba(154, 116, 32, 0.5);
  --panel-inner-border: rgba(90, 110, 95, 0.2);
  --panel-bezel: rgba(210, 200, 180, 0.9);
  --panel-bezel-gold: rgba(154, 116, 32, 0.16);
  --font-display: "Noto Serif SC", "Source Han Serif SC", "Songti SC", "STSong", serif;
  --font-body: "Noto Sans SC", "Source Han Sans SC", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
}

body {
  font-family: var(--font-body);
}

/* Seigaiha on ::after so grain ::before stays */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0.12;
  background-image:
    radial-gradient(circle at 50% 100%, transparent 58%, color-mix(in srgb, var(--gold) 50%, transparent) 59.5%, transparent 62%),
    radial-gradient(circle at 0% 100%, transparent 58%, color-mix(in srgb, var(--gold) 40%, transparent) 59.5%, transparent 62%),
    radial-gradient(circle at 100% 100%, transparent 58%, color-mix(in srgb, var(--gold) 40%, transparent) 59.5%, transparent 62%);
  background-size: 52px 26px;
  background-repeat: repeat;
  background-position: 0 0, 26px 0, 26px 0;
  mix-blend-mode: soft-light;
}

html[data-theme="day"] body::after {
  opacity: 0.14;
  mix-blend-mode: multiply;
}

/* .bg-stack must stay position:fixed (see earlier rule).
   Only lift .app above the fixed backdrop + seigaiha. */
.app {
  position: relative;
  z-index: 1;
}

.bg-stack {
  position: fixed;
  inset: 0;
  z-index: 0;
}

.header h1,
.tool-card h2,
.panel h2,
.section-title,
.result-card .points {
  font-family: var(--font-display);
}

.header h1 {
  letter-spacing: 0.12em;
  font-weight: 600;
}

.header .sub,
.header p.sub {
  letter-spacing: 0.06em;
}

/* 印鑑-style badge */
.badge {
  border-radius: 3px;
  border: 1.5px solid var(--seal);
  color: var(--seal);
  background: color-mix(in srgb, var(--seal) 12%, transparent);
  letter-spacing: 0.22em;
  font-family: var(--font-display);
  font-weight: 700;
  box-shadow: none;
  padding: 4px 10px;
}

/* Shoji double frame */
.panel,
.tool-card,
.result-card {
  border: 1px solid var(--shoji);
  border-radius: 10px;
  box-shadow:
    inset 0 0 0 1px var(--shoji-inner),
    var(--shadow, 0 10px 28px rgba(4, 28, 20, 0.45));
  background-image: linear-gradient(var(--washi), var(--washi));
}

.tool-card--feature {
  border-color: color-mix(in srgb, var(--gold) 50%, var(--seal) 25%);
  box-shadow:
    inset 0 0 0 1px var(--shoji-inner),
    inset 3px 0 0 0 var(--seal),
    var(--shadow, 0 10px 28px rgba(4, 28, 20, 0.45));
}

/* Corner brackets on home header */
.header {
  position: relative;
  padding-top: 16px;
  padding-bottom: 4px;
}

.header::before,
.header::after {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  border-color: var(--gold-line-strong);
  border-style: solid;
  pointer-events: none;
  opacity: 0.8;
}

.header::before {
  top: 0;
  left: 0;
  border-width: 2px 0 0 2px;
}

.header::after {
  top: 0;
  right: 0;
  border-width: 2px 2px 0 0;
}

.tool-card .go {
  font-family: var(--font-display);
  letter-spacing: 0.18em;
  color: var(--gold-hi);
}

.btn-primary {
  border-radius: 6px;
  letter-spacing: 0.08em;
}

.btn-ghost {
  border-radius: 6px;
}

@media (prefers-reduced-motion: reduce) {
  body::after {
    opacity: 0.07;
  }
}

/* -- Desktop airy layout (web) -- */
/* Phone stays dense; tablet/desktop get width, gaps, and breathing room. */

@media (min-width: 768px) {
  body {
    padding: 28px 28px 56px;
    align-items: flex-start;
  }

  .app {
    max-width: 720px;
  }

  .header {
    padding: 12px 4px 28px;
  }

  .header h1 {
    font-size: clamp(1.7rem, 2.4vw, 2rem);
    letter-spacing: 0.14em;
  }

  .header .sub,
  .header p.sub {
    margin-top: 10px;
    font-size: 0.88rem;
    max-width: 40em;
  }

  .badge {
    margin-top: 14px;
  }

  .tool-grid {
    gap: 16px;
  }

  .tool-card {
    padding: 18px 16px 14px;
    min-height: 132px;
  }

  .tool-card h2 {
    font-size: 1.05rem;
    margin-bottom: 8px;
  }

  .tool-card p {
    font-size: 0.8rem;
    line-height: 1.5;
    margin-bottom: 12px;
  }

  .tool-card--feature {
    padding: 22px 20px 16px;
    min-height: 148px;
  }

  .tool-card--feature h2 {
    font-size: 1.35rem;
  }

  .tool-card--feature p {
    font-size: 0.9rem;
    max-width: 36em;
  }

  .disclaimer {
    margin-top: 22px;
    line-height: 1.65;
  }

  /* Tool iframe pages: readable column, not phone-narrow */
  html.embedded body {
    padding: 20px 24px 40px;
    justify-content: center;
  }

  html.embedded .app {
    max-width: 640px;
  }

  .panel {
    margin-bottom: 18px;
  }

  .tool-shell-bar {
    padding: 12px 18px 14px;
    max-width: 720px;
  }
}

@media (min-width: 1100px) {
  body {
    padding: 36px 40px 72px;
    padding-left: max(40px, calc((100vw - 1100px) / 2));
    padding-right: 40px;
  }

  .app {
    max-width: 900px;
  }

  .header {
    padding: 16px 6px 32px;
  }

  .tool-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 18px;
  }

  .tool-card--feature {
    grid-column: 1 / -1;
  }

  .tool-card {
    min-height: 148px;
    padding: 20px 18px 16px;
  }

  .tool-card h2 {
    font-size: 1.08rem;
  }

  .tool-card p {
    font-size: 0.82rem;
  }

  html.embedded body {
    padding: 28px 32px 48px;
  }

  html.embedded .app {
    max-width: 720px;
  }

  .tool-shell-bar {
    max-width: 900px;
    padding: 14px 22px 16px;
  }

  body.tool-open .tool-shell-bar {
    margin: 0 auto;
    width: 100%;
  }
}

/* Keep phone home width on small screens (undo accidental widen) */
@media (max-width: 767px) {
  .app {
    max-width: 375px;
  }
}


/* Disabled primary actions (e.g. judge → score before ready) */
.btn:disabled,
.btn[disabled],
.btn[aria-disabled='true'] {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  filter: none;
  pointer-events: none;
}

/* -- Typography refresh + UI polish -- */
:root,
html[data-theme="night"],
html[data-theme="day"] {
  --font-display: "Noto Serif SC", "Source Han Serif SC", "Songti SC", "STSong", serif;
  --font-body: "Noto Sans SC", "Source Han Sans SC", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
}

html {
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-body);
  font-weight: 400;
  line-height: 1.55;
  letter-spacing: 0.01em;
}

.header h1,
.tool-card h2,
.panel h2,
.section-title,
.result-card .points,
.tool-shell-title,
.crumb {
  font-family: var(--font-display);
  font-feature-settings: "kern" 1, "liga" 1;
}

.header h1 {
  font-weight: 700;
  letter-spacing: 0.16em;
  line-height: 1.25;
  font-size: clamp(1.55rem, 4.8vw, 1.9rem);
}

.header .sub,
.header p.sub {
  font-family: var(--font-body);
  font-weight: 400;
  letter-spacing: 0.08em;
  line-height: 1.6;
  opacity: 0.92;
}

.badge {
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: 0.28em;
}

.section-title {
  font-weight: 700;
  letter-spacing: 0.18em;
  font-size: 0.78rem;
}

.tool-card h2 {
  font-weight: 700;
  letter-spacing: 0.06em;
  line-height: 1.35;
}

.tool-card p {
  font-family: var(--font-body);
  line-height: 1.55;
  letter-spacing: 0.02em;
}

.tool-card .go {
  font-family: var(--font-display);
  letter-spacing: 0.22em;
}

label.field > span,
.field-label,
.seg-label {
  font-family: var(--font-body);
  font-weight: 500;
  letter-spacing: 0.12em;
  font-size: 0.72rem;
}

select,
input[type="number"],
input[type="text"],
input[type="search"] {
  font-family: var(--font-body);
  font-weight: 500;
  letter-spacing: 0.02em;
}

.btn,
.seg button,
.chip {
  font-family: var(--font-body);
  font-weight: 600;
  letter-spacing: 0.06em;
}

.btn-primary {
  letter-spacing: 0.12em;
}

.result-card .points,
.result-big,
.points-main,
#hanLabel {
  font-family: var(--font-display);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
  font-weight: 700;
}

.result-card .meta,
.detail,
.hint,
.disclaimer {
  font-family: var(--font-body);
  line-height: 1.6;
}

/* Slightly airier chrome */
.header {
  padding-bottom: 22px;
}

.panel {
  margin-bottom: 18px;
}

.tool-card {
  transition: transform 220ms var(--ease, cubic-bezier(0.22, 1, 0.36, 1)),
    box-shadow 220ms ease, border-color 220ms ease;
}

@media (min-width: 768px) {
  .header h1 {
    letter-spacing: 0.18em;
  }
  .tool-card p {
    font-size: 0.84rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .tool-card {
    transition: none;
  }
}

/* Force local Noto (subset) — last word on cascade */
html, body {
  font-family: "Noto Sans SC", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif !important;
}
.header h1,
.tool-card h2,
.panel h2,
.section-title,
.tool-shell-title,
.crumb,
.badge,
.tool-card .go,
.result-card .points,
.result-big,
.points-main {
  font-family: "Noto Serif SC", "Songti SC", "STSong", serif !important;
}

/* -- Balanced layout: show character art, not a skinny left rail -- */
/* Slightly left of center + mid width; leave the right silhouette uncovered. */

@media (min-width: 768px) {
  body {
    justify-content: center;
    align-items: flex-start;
    /* Extra right padding shifts the column left without parking it on the edge */
    padding: 28px max(14vw, 64px) 56px 28px;
  }

  body:not(.tool-open) .app {
    max-width: 560px;
    width: 100%;
    margin-left: auto;
    margin-right: auto;
  }

  body:not(.tool-open) .tool-grid {
    grid-template-columns: 1fr 1fr;
    gap: 14px;
  }

  body:not(.tool-open) .tool-card--feature {
    grid-column: 1 / -1;
  }

  /* Tool shell: full-bleed so iframe scrollbar is on the far right of the viewport.
     Bar + embedded tools keep the left-biased ~560px column. */
  body.tool-open {
    justify-content: flex-start;
    padding: 0;
  }

  body.tool-open .app {
    max-width: none;
    width: 100%;
    margin: 0;
    height: 100dvh;
  }

  body.tool-open .tool-shell-bar {
    max-width: 560px;
    width: calc(100% - max(12vw, 48px) - 20px);
    margin: 0 0 0 20px;
    box-sizing: border-box;
  }

  html.embedded body {
    justify-content: center;
    padding: 20px max(12vw, 48px) 40px 24px;
  }

  html.embedded .app {
    max-width: 560px;
    margin-left: auto;
    margin-right: auto;
  }
}

@media (min-width: 1100px) {
  body {
    padding: 36px max(18vw, 96px) 72px 48px;
  }

  body:not(.tool-open) .app {
    max-width: 600px;
  }

  body.tool-open {
    padding: 0;
  }

  body.tool-open .app {
    max-width: none;
  }

  body.tool-open .tool-shell-bar {
    max-width: 600px;
    width: calc(100% - max(16vw, 80px) - 32px);
    margin: 0 0 0 32px;
  }

  html.embedded .app {
    max-width: 600px;
  }

  .bg-layer.bg-night,
  .bg-layer.bg-day {
    background-position: center, center, right 28%;
  }
}

@media (max-width: 767px) {
  body {
    justify-content: center;
    padding: 14px 12px 48px;
  }

  .app {
    max-width: 375px;
    margin-left: auto;
    margin-right: auto;
  }
}

/* -- Site footer link -- */
.site-link-wrap {
  margin: 14px 0 8px;
  text-align: left;
}
.site-link {
  color: var(--gold-hi);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-decoration: none;
  border-bottom: 1px solid color-mix(in srgb, var(--gold) 45%, transparent);
  padding-bottom: 1px;
}
.site-link:active {
  opacity: 0.85;
}

.site-author {
  margin: 16px 0 6px;
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  color: var(--ink-dim);
  text-align: left;
}

.site-author-link {
  color: inherit;
  text-decoration: none;
  border-bottom: 1px solid color-mix(in srgb, currentColor 35%, transparent);
}
.site-author-link:hover,
.site-author-link:focus-visible {
  color: var(--accent, #c9a86c);
  border-bottom-color: currentColor;
}

/* -- Cohesive polish: embedded chrome, density, utilities -- */

/* Hide duplicate tool chrome inside home shell iframe */
html.embedded .topnav,
html.embedded .header {
  display: none;
}

html.embedded body::after {
  display: none !important;
}

html.embedded .app {
  padding-top: 2px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
}

html.embedded .disclaimer {
  margin-top: 10px;
  font-size: 0.68rem;
  line-height: 1.5;
  opacity: 0.9;
}

html.embedded .carry-banner {
  margin-top: 4px;
}

/* Utility: replace common inline styles */
.mt-0 { margin-top: 0 !important; }
.mt-xs { margin-top: 4px; }
.mt-sm { margin-top: 8px; }
.mt-md { margin-top: 12px; }
.field-grow { flex: 1; min-width: 0; }
.scroll-x {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.dimmed { opacity: 0.45; }
.check-inline {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  min-height: 44px;
  margin-bottom: 8px;
  cursor: pointer;
  font-size: 0.84rem;
  color: var(--ink);
}
.btn-compact {
  min-height: 36px !important;
  height: auto;
  padding: 6px 12px !important;
  font-size: 0.8rem;
  letter-spacing: 0.04em;
}
.btn-sm {
  min-height: 40px;
  padding: 6px 10px;
  font-size: 0.8rem;
  letter-spacing: 0.03em;
}
.hand-meta .btn-compact {
  flex: 0 0 auto;
}

/* Seg: auto columns by child count */
.seg.seg-3,
.seg:has(> :nth-child(3):last-child) {
  grid-template-columns: repeat(3, 1fr);
}
.seg.seg-4,
.seg:has(> :nth-child(4):last-child) {
  grid-template-columns: repeat(4, 1fr);
}
.seg.seg-5,
.seg:has(> :nth-child(5):last-child) {
  grid-template-columns: repeat(5, 1fr);
}

.chip-row {
  margin-top: 10px;
}

/* Result hierarchy */
.result-card {
  border-color: color-mix(in srgb, var(--gold) 42%, var(--shoji));
  box-shadow:
    inset 0 0 0 1px var(--shoji-inner),
    0 0 0 1px color-mix(in srgb, var(--gold) 18%, transparent),
    var(--shadow, 0 10px 28px rgba(4, 28, 20, 0.45));
}

.result-card .points {
  font-size: clamp(1.95rem, 7.2vw, 2.45rem);
  line-height: 1.15;
  margin: 8px 0 4px;
}

.result-card .limit {
  opacity: 0.95;
}

.result-card .detail {
  color: var(--ink);
  opacity: 0.92;
}

.result-card .meta {
  font-size: 0.78rem;
  color: var(--ink-dim);
  opacity: 0.95;
}

.result-big {
  font-size: clamp(1.55rem, 6vw, 1.9rem);
  margin: 2px 0 10px;
  line-height: 1.2;
}

.fu-total .rounded {
  font-size: clamp(1.6rem, 6.5vw, 2rem);
  font-weight: 800;
  color: var(--gold-hi, var(--gold));
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

.fu-total .raw,
.fu-total .suggest {
  font-size: 0.78rem;
  color: var(--ink-dim);
}

/* Score table: sticky first col + nicer cells */
.score-table-wrap {
  margin: 0;
  border-radius: 8px;
  border: 1px solid var(--panel-inner-border, var(--gold-line));
}

.score-table th,
.score-table td {
  padding: 9px 6px;
}

.score-table th:first-child,
.score-table td.han-label {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--table-han-bg, var(--card));
  box-shadow: 4px 0 8px -4px rgba(0, 0, 0, 0.35);
}

.score-table th:first-child {
  z-index: 3;
  background: var(--table-th-bg, var(--card));
}

/* Tile hands: wrap + touch */
.tile-hand,
.tile-waits {
  gap: 6px;
  row-gap: 8px;
}

.tile {
  min-width: 34px;
  min-height: 46px;
  touch-action: manipulation;
}

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

@media (max-width: 380px) {
  .tile {
    width: 32px;
    height: 44px;
    min-width: 32px;
    min-height: 44px;
  }
}

/* Check grid / fuuro / stats */
.check-grid label {
  min-height: 44px;
}

.fuuro-row .btn-sm {
  flex: 0 0 auto;
}

.stats-bar {
  gap: 10px 14px;
  padding: 10px 12px;
  margin-top: 12px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--gold) 8%, var(--card));
  border: 1px solid color-mix(in srgb, var(--gold) 22%, transparent);
  font-size: 0.82rem;
  line-height: 1.4;
}

.quiz-options {
  margin-top: 12px;
}

.quiz-options .btn {
  min-height: 44px;
}

/* PT players toggle prominence */
#playersSeg {
  max-width: 280px;
}

#playersSeg button {
  font-size: 1rem;
  font-weight: 700;
}

/* Yaku list spacing */
#yakuList .yaku-item,
.yaku-item {
  margin-bottom: 8px;
}

#yakuList .yaku-item:last-child,
.yaku-item:last-child {
  margin-bottom: 0;
}

/* Pay / ryukyoku tables inside result */
.result-card .pay-table,
#tableWrap table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
}

#tableWrap th,
#tableWrap td {
  padding: 8px 6px;
  border-bottom: 1px solid color-mix(in srgb, var(--gold) 18%, transparent);
  text-align: left;
}

/* Actions: 3 buttons tidy */
.actions:has(> :nth-child(3):last-child) {
  grid-template-columns: 1fr 1fr;
}
.actions:has(> :nth-child(3):last-child) > :last-child {
  grid-column: 1 / -1;
}
.actions:has(> :nth-child(4)) {
  grid-template-columns: 1fr 1fr;
}

/* Mobile denser (still ≥44px controls) */
@media (max-width: 767px) {
  .panel {
    margin-bottom: 12px;
    padding: 12px 12px 14px;
  }

  .section-title {
    margin-bottom: 10px;
    font-size: 0.72rem;
  }

  .header {
    padding: 6px 2px 14px;
  }

  .header h1 {
    font-size: clamp(1.28rem, 5vw, 1.5rem);
    letter-spacing: 0.1em;
  }

  .header .sub,
  .header p.sub {
    margin-top: 6px;
    font-size: 0.74rem;
    line-height: 1.45;
    max-width: none;
  }

  .badge {
    margin-top: 8px;
    padding: 3px 8px;
    letter-spacing: 0.16em;
    font-size: 0.58rem;
  }

  .seg {
    gap: 6px;
  }

  .seg button,
  .chip,
  .btn:not(.btn-compact):not(.btn-sm) {
    min-height: 44px;
  }

  select,
  input[type="number"],
  input[type="search"],
  input[type="text"] {
    min-height: 44px;
    padding: 9px 12px;
  }

  .row {
    margin-bottom: 10px;
    gap: 6px;
  }

  .result-card {
    padding: 16px 12px 14px;
  }

  .tool-card {
    min-height: 108px;
    padding: 14px 12px 12px;
  }

  .tool-card p {
    font-size: 0.72rem;
    line-height: 1.4;
    margin-bottom: 8px;
  }

  .tool-card--feature {
    min-height: 118px;
  }

  .tool-grid {
    gap: 8px;
  }

  .seg:has(> :nth-child(5):last-child) button {
    font-size: 0.78rem;
    padding: 0 2px;
  }

  .seg:has(> :nth-child(4):last-child) button {
    font-size: 0.82rem;
    padding: 0 4px;
  }

  .num-row {
    gap: 8px;
  }

  .num-row input[type="number"] {
    width: 64px;
    min-height: 40px;
  }

  .check-grid {
    gap: 4px 8px;
  }

  .topnav {
    margin-bottom: 10px;
  }
}

/* Desktop: comfortable, not sparse; result primary */
@media (min-width: 768px) {
  .panel {
    margin-bottom: 14px;
    padding: 16px 16px 18px;
  }

  .result-card {
    padding: 22px 18px 20px;
  }

  .seg button,
  .btn:not(.btn-compact):not(.btn-sm) {
    min-height: 48px;
  }

  select,
  input[type="number"],
  input[type="search"],
  input[type="text"] {
    min-height: 48px;
  }

  .header .sub,
  .header p.sub {
    max-width: 36em;
  }

  html.embedded .result-card {
    position: relative;
  }

  .tile {
    width: 36px;
    height: 48px;
    min-width: 36px;
    min-height: 48px;
  }
}

/* Standalone tool pages: slightly compact header (shell already titles when embedded) */
.app > .header {
  padding-bottom: 12px;
}

.app > .header .sub {
  margin-bottom: 0;
}

/* div.field (quick controls) mirrors label.field */
div.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
div.field > span {
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.12em;
  color: var(--ink-dim);
}

/* Home: keep page scroll on the viewport so the scrollbar stays on the far right */
@media (min-width: 768px) {
  html {
    overflow-x: hidden;
    overflow-y: auto;
  }
  body:not(.tool-open) {
    overflow: visible;
    min-height: 100dvh;
  }
}
