:root {
  --bg: #0a0814;
  --panel: #12101c;
  --pink: #ff6b9d;
  --gold: #ffd56a;
  --text: #f2eef8;
  --muted: #8b849c;
  --border: rgba(255, 107, 157, 0.45);
  --play-bg: #100818;
  --font: "Microsoft JhengHei", "微軟正黑體", "Noto Sans TC", "PingFang TC",
    "Segoe UI", sans-serif;
  --mono: "Cascadia Mono", "Consolas", "Microsoft JhengHei", monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  min-height: 100%;
  background:
    radial-gradient(ellipse at 30% 20%, #2a1030 0%, transparent 50%),
    radial-gradient(ellipse at 80% 80%, #1a1035 0%, transparent 45%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
}

#app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px 16px 32px;
}

.top-bar {
  text-align: center;
  margin-bottom: 12px;
}

.top-bar h1 {
  font-size: 1.75rem;
  letter-spacing: 0.28em;
  color: var(--pink);
  text-shadow: 0 0 18px rgba(255, 107, 157, 0.45);
}

.subtitle {
  color: var(--muted);
  font-size: 0.95rem;
  margin-top: 6px;
  letter-spacing: 0.12em;
}

.subtitle.sub2 {
  font-size: 0.78rem;
  margin-top: 4px;
  letter-spacing: 0.06em;
  color: #6e6780;
}

#game-wrap {
  display: grid;
  grid-template-columns: 640px 250px;
  gap: 12px;
  justify-content: center;
  position: relative;
  margin: 0 auto;
  width: fit-content;
}

#game {
  display: block;
  width: 640px;
  height: 720px;
  background: var(--play-bg);
  border: 2px solid var(--border);
  border-radius: 6px;
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.04),
    0 12px 40px rgba(0, 0, 0, 0.55),
    0 0 30px rgba(255, 80, 140, 0.12);
}

#hud {
  background: linear-gradient(180deg, #1a1528 0%, #100e18 100%);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  padding: 16px 14px 12px;
  min-height: 720px;
}

.hud-title {
  font-size: 0.85rem;
  letter-spacing: 0.35em;
  color: var(--pink);
  text-align: center;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

/* 左右對齊的狀態列 */
.hud-row {
  display: grid;
  grid-template-columns: 4.5em 1fr;
  align-items: baseline;
  column-gap: 10px;
  margin-bottom: 11px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.hud-row .label {
  font-size: 0.82rem;
  color: var(--muted);
  letter-spacing: 0.06em;
  text-align: justify;
  text-align-last: justify;
}

.hud-row .value {
  font-family: var(--mono);
  font-size: 0.98rem;
  font-variant-numeric: tabular-nums;
  color: var(--gold);
  text-align: right;
  letter-spacing: 0.04em;
}

.hud-row .stars {
  letter-spacing: 0.12em;
  color: var(--pink);
  font-family: var(--font);
}

.hud-row.muted .value {
  color: var(--muted);
  font-size: 0.9rem;
}

.help {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.65;
}

.help-title {
  color: var(--text);
  letter-spacing: 0.2em;
  margin-bottom: 8px;
  font-size: 0.8rem;
}

.help-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 6px;
  margin-bottom: 6px;
}

.help-desc {
  margin-left: 4px;
  color: var(--muted);
}

.help-note {
  margin-top: 10px;
  font-size: 0.72rem;
  line-height: 1.5;
  color: #6e6780;
}

.help kbd {
  display: inline-block;
  min-width: 1.8em;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.08);
  color: #ddd;
  font-family: var(--font);
  font-size: 0.72rem;
  text-align: center;
}

/* 覆蓋選單 */
.overlay {
  position: absolute;
  left: 0;
  top: 0;
  width: 640px;
  height: 720px;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 5;
}

.overlay.hidden { display: none; }

.overlay-box {
  width: min(420px, 88%);
  padding: 24px 28px;
  background: rgba(8, 6, 16, 0.9);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  line-height: 1.65;
  font-size: 0.95rem;
  text-align: left;
  color: var(--text);
  white-space: normal;
}

.overlay-box .title {
  color: var(--gold);
  font-size: 1.3rem;
  margin-bottom: 12px;
  letter-spacing: 0.2em;
  text-align: center;
  border-bottom: 1px solid rgba(255, 213, 106, 0.25);
  padding-bottom: 10px;
}

.overlay-box .accent {
  color: var(--pink);
  text-align: center;
  letter-spacing: 0.12em;
  margin-bottom: 10px;
}

.overlay-box .dim {
  color: var(--muted);
  font-size: 0.86rem;
}

.overlay-box .center {
  text-align: center;
}

.overlay-box .menu-list {
  margin: 8px 0 14px;
}

.overlay-box .menu-item {
  display: grid;
  grid-template-columns: 2.2em 1fr;
  column-gap: 10px;
  padding: 5px 0;
  align-items: baseline;
}

.overlay-box .menu-item .key {
  color: var(--gold);
  font-family: var(--mono);
  text-align: center;
}

.overlay-box .menu-item .txt {
  color: var(--text);
}

.overlay-box .menu-item.active .txt {
  color: var(--pink);
}

/* 結算／狀態表：標籤對齊 */
.overlay-box .stat-table {
  width: 100%;
  border-collapse: collapse;
  margin: 6px 0 12px;
  font-size: 0.92rem;
}

.overlay-box .stat-table td {
  padding: 5px 0;
  vertical-align: baseline;
}

.overlay-box .stat-table td.k {
  width: 6.5em;
  color: var(--muted);
  letter-spacing: 0.08em;
  white-space: nowrap;
}

.overlay-box .stat-table td.v {
  text-align: right;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  color: var(--gold);
  letter-spacing: 0.03em;
}

.overlay-box .hint {
  margin-top: 12px;
  text-align: center;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.7;
}

/* —— 對話：立繪 + 對話框 —— */
.overlay.dialogue-mode {
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 28px;
  background: linear-gradient(to top, rgba(0,0,0,0.55) 0%, transparent 55%);
}

.overlay.dialogue-mode .overlay-box {
  width: min(600px, 96%);
  max-width: 600px;
  padding: 0;
  background: transparent;
  border: none;
  box-shadow: none;
}

.dialog-stage {
  position: relative;
  width: 100%;
  min-height: 380px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.portrait {
  position: absolute;
  /* 與 dialog-panel 底部對齊（同為 dialog-stage 底邊） */
  bottom: 0;
  /* 立繪顯示大小：改 width / height 即可放大縮小 */
  width: 250px;
  height: 420px;
  pointer-events: none;
  transition: opacity 0.2s, filter 0.2s;
  z-index: 1;
}

.portrait.face-left {
  left: -8px;
}

.portrait.face-right {
  right: -8px;
}

.portrait img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: bottom center;
  filter: drop-shadow(0 4px 12px rgba(0,0,0,0.55));
}

.portrait.face-right img {
  transform: scaleX(-1); /* 預設圖面右，右側角色可水平翻轉；有專用右向圖可拿掉 */
}

.portrait.dimmed {
  opacity: 0.35;
  filter: grayscale(0.4);
}

.portrait.placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  background: linear-gradient(180deg, rgba(40,30,50,0.2) 10%, rgba(20,15,30,0.95) 100%);
  border: 1px dashed rgba(255,255,255,0.25);
  border-radius: 8px 8px 0 0;
}

.portrait .ph-body {
  width: 120px;
  height: 190px;
  border-radius: 60px 60px 16px 16px;
  background: var(--pc, #888);
  opacity: 0.85;
  margin-bottom: 8px;
  box-shadow: inset 0 -20px 0 rgba(0,0,0,0.15);
}

.portrait .ph-name {
  color: #fff;
  font-size: 0.85rem;
  letter-spacing: 0.08em;
  margin-bottom: 4px;
}

.portrait .ph-hint {
  color: rgba(255,255,255,0.45);
  font-size: 0.62rem;
  text-align: center;
  line-height: 1.35;
  padding: 0 8px 10px;
  word-break: break-all;
}

.dialog-panel {
  position: relative;
  z-index: 2;
  width: 100%;
  background: rgba(8, 6, 16, 0.92);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 18px 12px;
  box-shadow: 0 8px 28px rgba(0,0,0,0.45);
}

.dialog-speaker {
  color: var(--pink);
  letter-spacing: 0.12em;
  margin-bottom: 8px;
  font-size: 0.95rem;
}

.dialog-body {
  line-height: 1.75;
  min-height: 3.2em;
  color: var(--text);
}

.overlay-box .dialog-speaker {
  color: var(--pink);
  letter-spacing: 0.12em;
  margin-bottom: 8px;
  font-size: 0.95rem;
}

.overlay-box .dialog-body {
  line-height: 1.75;
  min-height: 3.2em;
}

.foot {
  text-align: center;
  margin-top: 14px;
  color: var(--muted);
  font-size: 0.8rem;
  letter-spacing: 0.04em;
}

/* —— Discord 帳號列 / 排行榜 —— */
.account-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 10px;
  min-height: 36px;
}

.acc-user {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-size: 0.88rem;
}

.acc-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--border);
}

.acc-avatar.ph {
  display: inline-block;
  background: #3a2a48;
}

.acc-name {
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.acc-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: rgba(255, 107, 157, 0.15);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.8rem;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  letter-spacing: 0.04em;
}

.acc-btn:hover {
  background: rgba(255, 107, 157, 0.28);
}

.acc-btn.ghost {
  background: transparent;
  color: var(--muted);
}

.acc-btn.discord {
  background: #5865f2;
  border-color: #4752c4;
  color: #fff;
}

.acc-btn.discord:hover {
  background: #4752c4;
}

.acc-hint {
  font-size: 0.75rem;
  color: var(--muted);
}

.lb-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  margin: 8px 0 10px;
}

.lb-tab {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(0, 0, 0, 0.25);
  color: var(--muted);
  font-family: var(--font);
  font-size: 0.75rem;
  padding: 4px 10px;
  border-radius: 999px;
  cursor: pointer;
}

.lb-tab.active {
  color: #fff;
  border-color: var(--pink);
  background: rgba(255, 107, 157, 0.25);
}

.lb-wrap {
  max-height: 280px;
  overflow: auto;
  margin: 6px 0 10px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
}

.lb-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}

.lb-table th,
.lb-table td {
  padding: 6px 8px;
  text-align: left;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.lb-table th {
  color: var(--muted);
  position: sticky;
  top: 0;
  background: rgba(12, 8, 20, 0.95);
}

.lb-place {
  width: 2em;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
}

.lb-score {
  font-variant-numeric: tabular-nums;
  color: #ffe8f0;
}

.lb-user {
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lb-av {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  flex-shrink: 0;
}

.lb-av.ph {
  display: inline-block;
  background: #3a2a48;
}

.lb-meta {
  color: var(--muted);
  white-space: nowrap;
}

.lb-ex {
  color: #ff6b9d;
  font-weight: bold;
  font-size: 0.7rem;
}

.overlay-box code {
  font-family: var(--mono);
  font-size: 0.85em;
  color: var(--gold);
}

@media (max-width: 920px) {
  #game-wrap {
    grid-template-columns: 1fr;
    width: min(100%, 640px);
  }
  #game {
    width: 100%;
    height: auto;
    aspect-ratio: 640 / 720;
  }
  #hud { min-height: auto; }
  .overlay {
    width: 100%;
    height: 100%;
  }
}
