@font-face {
  font-family: "GL-MahjongTile";
  src:
    url("https://cdn.jsdelivr.net/gh/Gutenberg-Labo/DingbatFonts@main/fonts/ttf/GL-MahjongTile.ttf") format("truetype"),
    url("https://raw.githubusercontent.com/Gutenberg-Labo/DingbatFonts/main/fonts/ttf/GL-MahjongTile.ttf") format("truetype"),
    url("/fonts/GL-MahjongTile.ttf?local=1") format("truetype");
  font-weight: normal;
  font-style: normal;
  font-display: swap;
  unicode-range: U+1F000-1F02F;
}

@font-face {
  font-family: "I.MahjongTW";
  src:
    url("https://cdn.jsdelivr.net/gh/SyaoranHinata/I.Mahjong@main/I.MahjongTW.otf") format("opentype"),
    url("https://raw.githubusercontent.com/SyaoranHinata/I.Mahjong/main/I.MahjongTW.otf") format("opentype"),
    url("/fonts/I.MahjongTW.otf?local=1") format("opentype");
  font-weight: normal;
  font-style: normal;
  font-display: swap;
  unicode-range: U+1F000-1F02F;
}

@font-face {
  font-family: "I.MahjongHK";
  src:
    url("https://cdn.jsdelivr.net/gh/SyaoranHinata/I.Mahjong@main/I.MahjongHK.otf") format("opentype"),
    url("https://raw.githubusercontent.com/SyaoranHinata/I.Mahjong/main/I.MahjongHK.otf") format("opentype"),
    url("/fonts/I.MahjongHK.otf?local=1") format("opentype");
  font-weight: normal;
  font-style: normal;
  font-display: swap;
  unicode-range: U+1F000-1F02F;
}

@font-face {
  font-family: "I.MahjongJP";
  src:
    url("https://cdn.jsdelivr.net/gh/SyaoranHinata/I.Mahjong@main/I.MahjongJP.otf") format("opentype"),
    url("https://raw.githubusercontent.com/SyaoranHinata/I.Mahjong/main/I.MahjongJP.otf") format("opentype"),
    url("/fonts/I.MahjongJP.otf?local=1") format("opentype");
  font-weight: normal;
  font-style: normal;
  font-display: swap;
  unicode-range: U+1F000-1F02F;
}

@font-face {
  font-family: "I.MahjongCAN";
  src:
    url("https://cdn.jsdelivr.net/gh/SyaoranHinata/I.Mahjong@main/I.MahjongCAN.otf") format("opentype"),
    url("https://raw.githubusercontent.com/SyaoranHinata/I.Mahjong/main/I.MahjongCAN.otf") format("opentype"),
    url("/fonts/I.MahjongCAN.otf?local=1") format("opentype");
  font-weight: normal;
  font-style: normal;
  font-display: swap;
  unicode-range: U+1F000-1F02F;
}

@font-face {
  font-family: "Riichi-Mahjong-Colorful";
  src:
    url("https://cdn.jsdelivr.net/gh/rutopio/mahjong-font@base-ui/preprocess/fonts/Riichi-Mahjong-Colorful.woff2") format("woff2"),
    url("https://raw.githubusercontent.com/rutopio/mahjong-font/base-ui/preprocess/fonts/Riichi-Mahjong-Colorful.woff2") format("woff2"),
    url("/fonts/Riichi-Mahjong-Colorful.woff2?local=1") format("woff2"),
    url("/fonts/Riichi-Mahjong-Colorful.otf?local=1") format("opentype");
  font-weight: normal;
  font-style: normal;
  font-display: swap;
  unicode-range: U+1F000-1F02F;
}

@font-face {
  font-family: "Riichi-Mahjong-Monochrome";
  src:
    url("https://cdn.jsdelivr.net/gh/rutopio/mahjong-font@base-ui/preprocess/fonts/Riichi-Mahjong-Monochrome.woff2") format("woff2"),
    url("https://raw.githubusercontent.com/rutopio/mahjong-font/base-ui/preprocess/fonts/Riichi-Mahjong-Monochrome.woff2") format("woff2"),
    url("/fonts/Riichi-Mahjong-Monochrome.woff2?local=1") format("woff2"),
    url("/fonts/Riichi-Mahjong-Monochrome.otf?local=1") format("opentype");
  font-weight: normal;
  font-style: normal;
  font-display: swap;
  unicode-range: U+1F000-1F02F;
}

@font-face {
  font-family: "NotoSansSymbols2-Mahjong";
  src:
    url("https://fonts.gstatic.com/s/notosanssymbols2/v25/I_uyMoGduATTei9eI8daxVHDyfisHr71-vrgfE71.woff2") format("woff2"),
    url("https://cdn.jsdelivr.net/gh/google/fonts@main/ofl/notosanssymbols2/NotoSansSymbols2-Regular.ttf") format("truetype"),
    url("/fonts/NotoSansSymbols2-Regular.ttf?local=1") format("truetype");
  font-weight: normal;
  font-style: normal;
  font-display: swap;
  unicode-range: U+1F000-1F02F;
}

@font-face {
  font-family: "Symbola-Mahjong";
  src:
    url("https://cdn.jsdelivr.net/gh/ffevotte/emacs.d@master/share/fonts/Symbola_hint.ttf") format("truetype"),
    url("https://raw.githubusercontent.com/ffevotte/emacs.d/master/share/fonts/Symbola_hint.ttf") format("truetype"),
    url("/fonts/Symbola.ttf?local=1") format("truetype");
  font-weight: normal;
  font-style: normal;
  font-display: swap;
  unicode-range: U+1F000-1F02F;
}

@font-face {
  font-family: "FreeSerif-Mahjong";
  src:
    url("https://cdn.jsdelivr.net/gh/BLavery/lib_oled96@master/FreeSerif.ttf") format("truetype"),
    url("https://raw.githubusercontent.com/BLavery/lib_oled96/master/FreeSerif.ttf") format("truetype"),
    url("/fonts/FreeSerif.ttf?local=1") format("truetype");
  font-weight: normal;
  font-style: normal;
  font-display: swap;
  unicode-range: U+1F000-1F02F;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  height: 100dvh;
  background: #000000;
  color: #f1f5f9;
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, -apple-system, sans-serif;
  overflow: hidden;
}

#app-shell {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  background: #000000;
}

#app-shell.topbar-hidden #top-bar {
  display: none !important;
}

/* ============================================================
   TOP HEADER BAR (Matches Android Top Action Bar)
   ============================================================ */
#top-bar {
  position: relative;
  z-index: 120;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 44px;
  padding: 0 12px;
  background: #141920;
  border-bottom: 1px solid #26303d;
  flex-shrink: 0;
  gap: 8px;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.title-text {
  font-size: 16px;
  font-weight: 800;
  color: #38bdf8;
  white-space: nowrap;
}

.money-badge {
  font-size: 13px;
  font-weight: 700;
  color: #fde047;
  background: rgba(250, 204, 21, 0.14);
  border: 1px solid rgba(250, 204, 21, 0.35);
  padding: 2px 8px;
  border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.mode-badge {
  font-size: 12px;
  font-weight: 600;
  color: #86efac;
  background: rgba(34, 197, 94, 0.14);
  border: 1px solid rgba(34, 197, 94, 0.35);
  padding: 2px 8px;
  border-radius: 4px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
}

.top-actions::-webkit-scrollbar {
  display: none;
}

.top-btn {
  height: 30px;
  padding: 0 12px;
  border: none;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 700;
  color: #ffffff;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: filter 0.12s ease, transform 0.08s ease;
}

.top-btn:hover {
  filter: brightness(1.14);
}

.top-btn:active {
  transform: translateY(1px);
}

.btn-blue   { background: #1976d2; }
.btn-green  { background: #2e7d32; }
.btn-orange { background: #ef6c00; }
.btn-purple { background: #6a1b9a; }
.btn-teal   { background: #00796b; }
.btn-indigo { background: #3949ab; }
.btn-slate  { background: #37474f; }
.btn-hide-bar {
  background: #1e293b;
  border: 1px solid #475569;
  color: #93c5fd;
  padding: 0 10px;
}

.hidden {
  display: none !important;
}

/* ============================================================
   MAIN TERMINAL CANVAS & OVERLAY CONTROL BAR
   ============================================================ */
#board-stage {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  width: 100%;
  background: #000000;
  overflow: hidden;
  position: relative;
}

#canvas-wrap {
  position: relative;
  width: 100%;
  height: 100%;
  background: #000000;
}

#board-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

#gameplay-control-bar {
  position: absolute;
  top: 76%;
  left: 15%;
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 10;
}

.nav-btn-group,
.act-btn-group {
  display: flex;
  align-items: center;
  gap: 5px;
}

.ctrl-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 5px;
  font-weight: 800;
  color: #ffffff;
  cursor: pointer;
  transition: transform 0.08s ease, filter 0.12s ease, opacity 0.15s ease;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.65);
}

.ctrl-btn:hover {
  filter: brightness(1.18);
}

.ctrl-btn:active {
  transform: scale(0.96);
}

.nav-btn {
  background: #334155;
  min-width: 54px;
  height: 38px;
  font-size: 16px;
}

.ok-btn {
  background: #0284c7;
  min-width: 58px;
  height: 38px;
  font-size: 17px;
}

.act-btn {
  min-width: 48px;
  height: 38px;
  font-size: 16px;
  opacity: 0.35;
}

.act-btn:disabled {
  opacity: 0.25;
  filter: grayscale(0.45);
  cursor: not-allowed;
  transform: none;
}

.act-btn.active-option {
  opacity: 0.85;
}

.act-btn.selected-option {
  opacity: 1.0;
  outline: 2px solid #fde047;
  box-shadow: 0 0 12px rgba(250, 204, 21, 0.6);
}

.act-pass { background: #546e7a; }
.act-eat  { background: #2e7d32; }
.act-pong { background: #1565c0; }
.act-kang { background: #6a1b9a; }
.act-hu   { background: #c62828; }

.show-topbar-btn {
  position: absolute;
  top: 76%;
  right: 16px;
  z-index: 15;
  background: rgba(15, 23, 42, 0.92);
  border: 1px solid rgba(56, 189, 248, 0.65);
  color: #38bdf8;
  padding: 0 10px;
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

/* ============================================================
   MODALS (HOST / JOIN / WAITING / SETTINGS)
   ============================================================ */
.modal-backdrop {
  position: fixed;
  top: 44px;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}

#app-shell.topbar-hidden .modal-backdrop {
  top: 0;
}

#app-shell.topbar-hidden #toast-container {
  top: 12px;
}

#modal-settings {
  z-index: 130;
}

#modal-google-font {
  z-index: 150;
}

#modal-tai-rules {
  z-index: 160;
}

.tai-rules-card {
  max-width: 680px;
}

.tai-rules-body {
  gap: 10px;
  user-select: text;
  -webkit-user-select: text;
}

.tai-section-title {
  font-size: 13px;
  font-weight: 800;
  color: #38bdf8;
  border-left: 3px solid #38bdf8;
  padding-left: 8px;
  margin-top: 4px;
}

.tai-rules-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
  background: #0d131c;
  border: 1px solid #243244;
  border-radius: 7px;
  padding: 8px 10px;
}

.tai-rule-row {
  display: grid;
  grid-template-columns: 128px 72px 1fr;
  align-items: baseline;
  gap: 8px;
  font-size: 13px;
  line-height: 1.45;
  padding: 3px 0;
  border-bottom: 1px dashed rgba(51, 65, 85, 0.45);
}

.tai-rule-row:last-child {
  border-bottom: none;
}

.tai-name {
  font-weight: 700;
  color: #f8fafc;
}

.tai-badge {
  display: inline-block;
  text-align: center;
  font-size: 12px;
  font-weight: 800;
  color: #fde047;
  background: rgba(250, 204, 21, 0.14);
  border: 1px solid rgba(250, 204, 21, 0.35);
  border-radius: 4px;
  padding: 1px 6px;
  white-space: nowrap;
}

.tai-desc {
  color: #cbd5e1;
  font-size: 12.5px;
}

.tai-formula-box {
  background: #101926;
  border: 1px solid #2d435e;
  border-radius: 7px;
  padding: 10px 12px;
  font-size: 12.5px;
  line-height: 1.6;
  color: #e2e8f0;
}

.tai-formula-box code {
  color: #fde047;
  font-weight: 700;
}

@media (max-width: 560px) {
  .tai-rule-row {
    grid-template-columns: 1fr auto;
    row-gap: 2px;
  }
  .tai-desc {
    grid-column: 1 / -1;
  }
}

.gf-ext-link {
  font-size: 12.5px;
  font-weight: 700;
  color: #38bdf8;
  text-decoration: none;
  white-space: nowrap;
}

.gf-ext-link:hover {
  text-decoration: underline;
}

.google-font-list {
  max-height: 280px;
}

.gf-preset-item {
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.gf-preset-item:hover {
  background: #172231;
  border-color: #38bdf8;
}

.gf-preset-item.gf-active {
  border-color: #22c55e;
  background: #102419;
}

.gf-badge {
  font-size: 12px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  background: #1e293b;
  color: #93c5fd;
  white-space: nowrap;
}

.gf-preset-item.gf-active .gf-badge {
  background: #16a34a;
  color: #ffffff;
}

#modal-boss-config {
  z-index: 10005;
}

.hidden,
.modal-backdrop.hidden {
  display: none !important;
}

.modal-card {
  width: 100%;
  max-width: 520px;
  background: #161d26;
  border: 1px solid #2e3c4f;
  border-radius: 10px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.85);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: 92vh;
}

.modal-header {
  padding: 14px 18px;
  background: #1e2836;
  border-bottom: 1px solid #2e3c4f;
}

.modal-header h2 {
  font-size: 17px;
  font-weight: 800;
  color: #f8fafc;
}

.modal-body {
  padding: 16px 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-footer {
  padding: 12px 18px;
  background: #121820;
  border-top: 1px solid #263242;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.info-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #0f141b;
  padding: 8px 12px;
  border-radius: 6px;
  border: 1px solid #243040;
  font-size: 13px;
}

.info-row code {
  color: #38bdf8;
  font-weight: 700;
  font-size: 14px;
}

.relay-box {
  background: #101722;
  border: 1px solid #283a52;
  border-radius: 8px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field-label {
  font-size: 12.5px;
  font-weight: 700;
  color: #93c5fd;
}

.input-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.inline-tag {
  font-size: 12px;
  color: #94a3b8;
  white-space: nowrap;
}

input[type="text"],
select {
  flex: 1;
  min-width: 0;
  height: 36px;
  padding: 0 10px;
  background: #0b0f17;
  border: 1px solid #334155;
  border-radius: 6px;
  color: #f8fafc;
  font-size: 14px;
  user-select: text;
  -webkit-user-select: text;
}

input[type="text"]:focus,
select:focus {
  outline: none;
  border-color: #38bdf8;
}

.room-code-input {
  font-size: 18px !important;
  font-weight: 800;
  letter-spacing: 3px;
  text-align: center;
  color: #fde047 !important;
}

.room-code-banner {
  background: rgba(250, 204, 21, 0.12);
  border: 1px solid rgba(250, 204, 21, 0.4);
  color: #fde047;
  padding: 9px 12px;
  border-radius: 6px;
  font-size: 15px;
  font-weight: 800;
  text-align: center;
}

.form-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 14px;
}

.form-row > label {
  white-space: nowrap;
  flex-shrink: 0;
}

.font-settings-block {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.font-actions-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.font-action-btn {
  flex: 1;
  padding: 0 10px;
  font-size: 13px;
}

.radio-group {
  display: flex;
  align-items: center;
  gap: 16px;
}

.seats-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: #0d1219;
  padding: 10px;
  border-radius: 6px;
  border: 1px solid #232f3e;
}

.seat-item {
  font-size: 14px;
  padding: 6px 10px;
  border-radius: 4px;
  background: #141c26;
  color: #cbd5e1;
  font-weight: 600;
}

.seat-item.seat-host {
  color: #fde047;
  border-left: 3px solid #eab308;
}

.seat-item.seat-human {
  color: #4ade80;
  border-left: 3px solid #22c55e;
}

.seat-item.seat-bot {
  color: #94a3b8;
  border-left: 3px solid #475569;
}

.subtle-status {
  font-size: 12.5px;
  color: #94a3b8;
  text-align: center;
}

.wait-my-sit {
  font-size: 15px;
  font-weight: 800;
  color: #4ade80;
  text-align: center;
}

.section-divider {
  font-size: 12px;
  font-weight: 700;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 4px;
  border-bottom: 1px solid #263242;
  padding-bottom: 4px;
}

.lan-rooms-list {
  max-height: 130px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.lan-room-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #0f151e;
  border: 1px solid #263447;
  border-radius: 6px;
  padding: 8px 12px;
}

.lan-room-title {
  font-size: 14px;
  font-weight: 700;
  color: #f8fafc;
}

.lan-room-sub {
  font-size: 12px;
  color: #94a3b8;
}

.empty-rooms {
  font-size: 13px;
  color: #64748b;
  text-align: center;
  padding: 12px 0;
}

.messages-log {
  height: 130px;
  overflow-y: auto;
  background: #090d12;
  border: 1px solid #243040;
  border-radius: 6px;
  padding: 8px 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.5;
  color: #cbd5e1;
  user-select: text;
  -webkit-user-select: text;
}

.help-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 12px;
  font-size: 12.5px;
  color: #cbd5e1;
}

kbd {
  background: #263242;
  border: 1px solid #475569;
  border-radius: 3px;
  padding: 1px 5px;
  font-size: 11.5px;
  color: #fde047;
}

.btn-primary,
.btn-secondary,
.btn-cancel {
  height: 36px;
  padding: 0 16px;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.btn-primary {
  background: #16a34a;
  color: #ffffff;
}

.btn-secondary {
  background: #0284c7;
  color: #ffffff;
}

.btn-cancel {
  background: #334155;
  color: #e2e8f0;
}

.btn-primary:hover,
.btn-secondary:hover,
.btn-cancel:hover {
  filter: brightness(1.12);
}

/* ============================================================
   TOAST NOTIFICATIONS
   ============================================================ */
#toast-container {
  position: fixed;
  top: 56px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast-item {
  background: rgba(20, 26, 35, 0.96);
  border: 1px solid #38bdf8;
  color: #f8fafc;
  padding: 9px 18px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 700;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.75);
}

.toast-item.toast-warn {
  border-color: #f59e0b;
  color: #fde047;
  background: rgba(45, 26, 8, 0.96);
}
