/* ============================================================
   狸尾經典遊戲櫃 — 公寓遊戲間設計系統（2026-08-14 全面重設計）
   概念：狸尾公寓的遊戲間 —— 暖黃燈光、木桌、四隻室友陪你開局
   取代：Win95 復古桌面＋太空船霓虹（科技感）舊設計
   ============================================================ */
:root {
  color-scheme: dark;
  /* 暖調基底（對齊狸尾公寓 IP：紙色/墨褐/珊瑚） */
  --bg:        #1d150f;
  --bg-2:      #241a13;
  --panel:     #2c2118;
  --panel-hi:  #3a2c1f;
  --line:      rgba(242, 200, 91, 0.16);
  --line-hi:   rgba(242, 200, 91, 0.45);
  --cream:     #f5ead2;
  --cream-dim: #b0987a;
  --gold:      #f2c85b;
  --coral:     #e8785e;
  --amber:     #e8a13a;
  /* 角色色（小面積點綴） */
  --shiba:  #c07a52;
  --otter:  #3aa89e;
  --cat:    #9b72aa;
  --raccoon:#9a6b4a;
  --card-w: clamp(52px, 7.2vw, 92px);
  --card-h: calc(var(--card-w) * 1.4);
  font-family: "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  font-weight: 700;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body {
  color: var(--cream);
  background:
    radial-gradient(1000px 520px at 88% -8%, rgba(242,200,91,0.09), transparent 60%),
    radial-gradient(760px 480px at -8% 108%, rgba(232,120,94,0.08), transparent 55%),
    linear-gradient(180deg, var(--bg-2) 0%, var(--bg) 100%);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
button { font: inherit; color: inherit; }
button:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ═══ 外殼：頂欄 + 內容 ═══ */
.app-shell { width: 100%; height: 100dvh; display: grid; grid-template-rows: 56px minmax(0, 1fr); }

.system-bar {
  z-index: 20;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 6px max(10px, env(safe-area-inset-right)) 6px max(10px, env(safe-area-inset-left));
  background: linear-gradient(180deg, rgba(58,44,31,.96), rgba(36,26,19,.96));
  border-bottom: 1px solid var(--line);
}
.start-button, .system-actions button, .game-toolbar button, .result-actions button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(74,56,40,.9), rgba(52,39,28,.9));
  box-shadow: 0 1px 0 rgba(255,255,255,.04) inset;
  cursor: pointer;
  transition: border-color .15s ease, transform .1s ease;
}
.start-button:hover, .system-actions button:hover, .game-toolbar button:hover, .result-actions button:hover {
  border-color: var(--line-hi);
}
.start-button:active, .system-actions button:active, .game-toolbar button:active, .result-actions button:active,
.game-toolbar button.is-selected {
  transform: translateY(1px);
  border-color: var(--gold);
}
.start-button { display: flex; align-items: center; gap: 8px; padding: 3px 14px; font-size: 17px; }
.arcade-mark { width: 22px; height: 22px; border-radius: 7px; background: var(--gold); display: grid; place-items: center; color: #241a13; font-size: 13px; font-weight: 900; }
.system-title {
  min-width: 0;
  align-self: stretch;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  color: var(--cream);
  font-size: 19px;
  letter-spacing: .03em;
}
.active-avatar { flex: 0 0 34px; width: 34px; height: 34px; overflow: hidden; background: rgb(255 255 255 / .08); border: 1px solid var(--line); border-radius: 10px; }
.active-avatar img { width: 100%; height: 100%; object-fit: contain; transform: scale(1.12); transform-origin: 50% 18%; }
.system-title strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.system-live {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: .76rem; font-weight: 700; letter-spacing: .18em;
  color: var(--cream-dim);
  padding: 5px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  white-space: nowrap;
}
.system-live i { width: 7px; height: 7px; border-radius: 50%; background: var(--coral); box-shadow: 0 0 8px rgba(232,120,94,.9); }
.system-actions { display: flex; gap: 6px; }
.system-actions button { width: 44px; font-size: 20px; padding: 0; }

/* ═══ 畫面容器 ═══ */
.screen { grid-row: 2; min-height: 0; display: none; }
.screen.is-active { display: flex; }

/* ═══ 遊戲間開場（launcher） ═══ */
.launcher-screen {
  position: relative;
  isolation: isolate;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--bg);
}
/* 場景 hero：公寓遊戲間插畫，暖色漸層覆蓋（不用霓虹、不用冷色） */
.launcher-hero {
  position: relative;
  isolation: isolate;
  min-height: clamp(250px, 42vh, 400px);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: clamp(18px, 3.4vw, 40px) clamp(16px, 5vw, 64px) clamp(18px, 3vw, 34px);
  overflow: hidden;
}
.launcher-hero::before {
  content: "";
  position: absolute; inset: 0; z-index: -2;
  background: url("../assets/art/game-room.webp") center 22% / cover no-repeat;
  transform: scale(1.02);
}
.launcher-hero::after {
  content: "";
  position: absolute; inset: 0; z-index: -1;
  background:
    linear-gradient(180deg, rgba(29,21,15,.42) 0%, rgba(29,21,15,.18) 42%, rgba(29,21,15,.98) 100%),
    linear-gradient(90deg, rgba(29,21,15,.62) 0%, transparent 62%);
}
.launcher-hero > * { position: relative; z-index: 1; }
.cabinet-label {
  margin: 0 0 6px;
  font-size: clamp(.86rem, 1.6vw, 1.05rem);
  letter-spacing: .22em;
  color: var(--gold);
  display: inline-flex; align-items: center; gap: 10px;
}
.cabinet-label .signal-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--coral); box-shadow: 0 0 10px rgba(232,120,94,.8); }
.launcher-copy h1, .launcher-hero h1 {
  margin: 0;
  font-size: clamp(2.4rem, 6.4vw, 4.4rem);
  font-weight: 900;
  line-height: 1.02;
  letter-spacing: .01em;
  text-shadow: 0 2px 22px rgba(0,0,0,.55);
}
.launcher-hero > p:last-of-type {
  margin: 12px 0 0;
  font-size: clamp(1rem, 2vw, 1.25rem);
  font-weight: 500;
  color: #e8d9bd;
  text-shadow: 0 1px 12px rgba(0,0,0,.6);
}

/* 四款遊戲：單欄垂直機台列（不是並排卡片） */
.game-list {
  display: flex;
  flex-direction: column;
  gap: clamp(10px, 1.6vw, 14px);
  padding: clamp(14px, 2.4vw, 26px) clamp(16px, 5vw, 64px) 6px;
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
}
.game-row {
  display: flex;
  align-items: center;
  gap: clamp(12px, 2vw, 20px);
  width: 100%;
  text-align: left;
  padding: clamp(10px, 1.6vw, 16px);
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(58,44,31,.9), rgba(44,33,24,.9));
  border: 1px solid var(--line);
  cursor: pointer;
  transition: transform .15s ease, border-color .15s ease, background .15s ease;
}
.game-row:hover { transform: translateY(-2px); border-color: var(--line-hi); background: linear-gradient(180deg, rgba(70,52,38,.95), rgba(56,42,32,.95)); }
.game-row:active { transform: translateY(0); }
.row-art {
  flex: 0 0 auto;
  width: clamp(72px, 9vw, 104px); height: clamp(72px, 9vw, 104px);
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--bg);
}
.row-art img { width: 100%; height: 100%; object-fit: cover; display: block; }
.row-copy { min-width: 0; flex: 1 1 auto; }
.row-copy strong {
  display: block;
  font-size: clamp(1.15rem, 2.6vw, 1.55rem);
  font-weight: 900;
  letter-spacing: .02em;
}
.row-copy small {
  display: block;
  margin-top: 3px;
  color: var(--cream-dim);
  font-size: clamp(.85rem, 1.6vw, .98rem);
  font-weight: 500;
}
.row-chip {
  flex: 0 0 auto;
  font-size: clamp(.8rem, 1.5vw, .92rem);
  font-weight: 800;
  color: #241a13;
  background: var(--gold);
  padding: 8px 16px;
  border-radius: 999px;
  white-space: nowrap;
  transition: transform .15s ease, background .15s ease;
}
.game-row:hover .row-chip { background: #ffd97a; }
.game-row:active .row-chip { transform: scale(.96); }

/* 底部戰績 */
.launcher-stats {
  display: flex;
  gap: clamp(10px, 2vw, 18px);
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
  padding: clamp(14px, 2.4vw, 24px) clamp(16px, 5vw, 64px) clamp(20px, 3vw, 34px);
}
.launcher-stats > div {
  flex: 1 1 0;
  min-width: 0;
  background: linear-gradient(180deg, rgba(44,33,24,.85), rgba(36,26,19,.85));
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: clamp(10px, 1.6vw, 16px);
  text-align: center;
}
.launcher-stats strong {
  display: block;
  font-size: clamp(1.5rem, 3.2vw, 2.1rem);
  font-weight: 900;
  color: var(--gold);
  line-height: 1.1;
}
.launcher-stats span {
  display: block;
  margin-top: 4px;
  font-size: clamp(.72rem, 1.3vw, .82rem);
  font-weight: 600;
  letter-spacing: .12em;
  color: var(--cream-dim);
}

/* ═══ 遊戲畫面共用 ═══ */
.game-screen {
  flex-direction: column;
  gap: clamp(8px, 1.4vw, 14px);
  padding: clamp(10px, 1.8vw, 20px) clamp(10px, 2.4vw, 28px) clamp(12px, 2vw, 24px);
  min-height: 0;
  background: var(--bg);
}
.game-toolbar {
  display: flex;
  align-items: center;
  gap: clamp(10px, 2vw, 18px);
  flex-wrap: wrap;
  max-width: 980px;
  width: 100%;
  margin: 0 auto;
  padding: clamp(10px, 1.4vw, 14px) clamp(12px, 1.8vw, 18px);
  background: linear-gradient(180deg, rgba(58,44,31,.92), rgba(44,33,24,.92));
  border: 1px solid var(--line);
  border-radius: 16px;
}
.game-heading { display: flex; align-items: center; gap: 12px; min-width: 0; }
.heading-icon {
  flex: 0 0 44px; width: 44px; height: 44px;
  overflow: hidden; border-radius: 12px;
  background: rgb(255 255 255 / .07); border: 1px solid var(--line);
}
.heading-icon img { width: 100%; height: 100%; object-fit: contain; transform: scale(1.12); transform-origin: 50% 18%; }
.game-heading h2 { margin: 0; font-size: clamp(1.15rem, 2.4vw, 1.5rem); font-weight: 900; }
.game-heading p { margin: 2px 0 0; font-size: clamp(.78rem, 1.4vw, .9rem); color: var(--cream-dim); font-weight: 500; }
.toolbar-metrics {
  display: flex;
  align-items: center;
  gap: clamp(8px, 1.6vw, 16px);
  margin-left: auto;
}
.toolbar-metrics > div {
  text-align: center;
  min-width: clamp(54px, 8vw, 76px);
  padding: 6px 10px;
  background: rgba(0,0,0,.22);
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,.05);
}
.toolbar-metrics span { display: block; font-size: .68rem; letter-spacing: .1em; color: var(--cream-dim); font-weight: 600; }
.toolbar-metrics strong { display: block; font-size: clamp(1.1rem, 2.2vw, 1.5rem); font-weight: 900; color: var(--cream); font-variant-numeric: tabular-nums; }
.face-button {
  width: clamp(44px, 6vw, 54px); height: clamp(44px, 6vw, 54px);
  font-size: clamp(1.3rem, 2.4vw, 1.7rem);
  border-radius: 12px;
  display: grid; place-items: center;
  padding: 0;
}
.difficulty-tabs {
  display: flex;
  gap: 6px;
  background: rgba(0,0,0,.25);
  padding: 5px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,.05);
}
.difficulty-tabs button {
  min-height: 34px;
  padding: 0 14px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--cream-dim);
  font-size: .85rem;
  font-weight: 700;
  cursor: pointer;
}
.difficulty-tabs button.is-selected {
  background: linear-gradient(180deg, rgba(242,200,91,.22), rgba(232,161,58,.18));
  color: var(--gold);
  box-shadow: inset 0 0 0 1px var(--line-hi);
}
.play-surface {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  max-width: 980px;
  width: 100%;
  margin: 0 auto;
  padding: clamp(8px, 1.4vw, 14px);
  background:
    radial-gradient(560px 360px at 50% 40%, rgba(242,200,91,.05), transparent 70%),
    linear-gradient(180deg, rgba(44,33,24,.9), rgba(29,21,15,.9));
  border: 1px solid var(--line);
  border-radius: 18px;
}
.play-surface canvas { width: 100%; height: 100%; display: block; }
.touch-help {
  text-align: center;
  color: var(--cream-dim);
  font-size: clamp(.82rem, 1.5vw, .95rem);
  font-weight: 500;
  padding: 2px 0 4px;
}
.touch-help strong { color: var(--gold); font-weight: 800; }
.game-actions { display: flex; gap: 8px; }
.game-actions button, .result-actions button {
  min-height: 42px;
  padding: 0 18px;
  border-radius: 12px;
  font-size: .95rem;
  font-weight: 800;
}
.primary-action {
  background: linear-gradient(180deg, #f2c85b, #e8a13a) !important;
  color: #241a13 !important;
  border-color: transparent !important;
}
.primary-action:hover { filter: brightness(1.06); }

/* ═══ 結算視窗 ═══ */
.result-overlay {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  background: rgba(15,10,7,.72);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}
.result-window {
  width: min(440px, 100%);
  background: linear-gradient(180deg, #33271c, #241a13);
  border: 1px solid var(--line-hi);
  border-radius: 20px;
  box-shadow: 0 24px 70px rgba(0,0,0,.55), 0 0 0 1px rgba(0,0,0,.4);
  overflow: hidden;
}
.result-titlebar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  background: rgba(0,0,0,.25);
  border-bottom: 1px solid var(--line);
}
.result-titlebar strong { font-size: .95rem; letter-spacing: .06em; color: var(--cream); }
.result-titlebar button {
  width: 34px; height: 34px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: transparent;
  color: var(--cream-dim);
  font-size: 1.1rem;
  cursor: pointer;
}
.result-titlebar button:hover { color: var(--coral); border-color: var(--coral); }
.result-content { padding: clamp(20px, 4vw, 30px); text-align: center; }
.result-icon {
  display: inline-grid; place-items: center;
  width: 84px; height: 84px;
  border-radius: 22px;
  background: rgb(255 255 255 / .07);
  border: 1px solid var(--line);
  overflow: hidden;
}
.result-icon img { width: 100%; height: 100%; object-fit: contain; transform: scale(1.12); transform-origin: 50% 18%; }
.result-content h2 { margin: 14px 0 0; font-size: clamp(1.5rem, 4vw, 1.9rem); font-weight: 900; }
.result-content > p { margin: 6px 0 0; color: var(--cream-dim); font-size: .95rem; font-weight: 500; }
.result-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 18px 0;
}
.result-metrics > div {
  background: rgba(0,0,0,.25);
  border: 1px solid rgba(255,255,255,.05);
  border-radius: 12px;
  padding: 10px 6px;
}
.result-metrics span { display: block; font-size: .68rem; letter-spacing: .08em; color: var(--cream-dim); font-weight: 600; }
.result-metrics strong { display: block; margin-top: 2px; font-size: 1.2rem; font-weight: 900; color: var(--gold); font-variant-numeric: tabular-nums; }
.result-actions { display: flex; gap: 10px; justify-content: center; }

/* ═══ 手機 ═══ */
@media (max-width: 600px) {
  .app-shell { grid-template-rows: 52px minmax(0, 1fr); }
  .system-title { font-size: 16px; padding: 0 8px; }
  .system-live { display: none; }
  .game-list, .launcher-stats { padding-left: 14px; padding-right: 14px; }
  .launcher-hero { min-height: 240px; padding: 16px 14px 20px; }
  .row-art { width: 68px; height: 68px; border-radius: 12px; }
  .row-chip { padding: 7px 12px; }
  .game-toolbar { gap: 8px; }
  .toolbar-metrics { margin-left: 0; }
  .result-metrics { grid-template-columns: repeat(3, 1fr); }
}
