/* ladiside — 第六版 眾聲霓虹 */

/* ---------- 自架字體（SIL OFL 1.1，授權檔在 fonts/licenses） ---------- */
/* 首頁背景用的裁切版：只含背景出現的字，載入很快 */
@font-face { font-family: 'Mantou Sans Sub'; src: url(fonts/mantou-sub.woff) format('woff'); font-display: swap; }
@font-face { font-family: 'YuPearl Sub'; src: url(fonts/yupearl-Light-sub.woff) format('woff'); font-weight: 300; font-display: swap; }
@font-face { font-family: 'YuPearl Sub'; src: url(fonts/yupearl-Medium-sub.woff) format('woff'); font-weight: 500; font-display: swap; }
@font-face { font-family: 'YuPearl Sub'; src: url(fonts/yupearl-SemiBold-sub.woff) format('woff'); font-weight: 600; font-display: swap; }
/* 字體設定用的完整版：只有使用者選了才會下載 */
@font-face { font-family: 'Mantou Sans Full'; src: url(fonts/mantou-full.woff2) format('woff2'); font-display: swap; }
@font-face { font-family: 'YuPearl Full'; src: url(fonts/yupearl-full.woff2) format('woff2'); font-display: swap; }
@font-face { font-family: 'ChenYu Web'; src: url(fonts/chenyu-full.woff2) format('woff2'); font-display: swap; }
@font-face { font-family: 'Naikai Web'; src: url(fonts/naikai-full.woff2) format('woff2'); font-display: swap; }
@font-face { font-family: 'Cubic 11 Web'; src: url(fonts/cubic11.woff2) format('woff2'); font-display: swap; }

:root {
  --violet: #3B1C8C;
  --night: #120634;
  --panel: #22104F;
  --pink: #FF8AD8;
  --yellow: #FFD36E;
  --cyan: #7DF0FF;
  --text: #FFFFFF;
  --dim: #C9BEF0;
  --warn: #FFB0A8;
  --ink: #2A0E66;
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);
  --ease-drawer: cubic-bezier(0.32, 0.72, 0, 1);
  --ease-wind: cubic-bezier(0.6, -0.5, 0.35, 1);
  --ui: 'Noto Sans TC', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: #0B0420;
  display: flex; align-items: center; justify-content: center;
  min-height: 100dvh;
  font-family: var(--ui);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; transition: transform 160ms var(--ease-out); }
button:active { transform: scale(0.96); }
button:focus-visible { outline: 2px solid var(--cyan); outline-offset: 3px; }
input:focus-visible { outline: 2px solid var(--pink); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.app {
  position: relative;
  width: 100%;
  height: 100dvh;
  overflow: hidden;
  background: var(--violet);
  transition: background-color 500ms var(--ease-in-out);
}
.app[data-phase="chat"] { background: var(--night); }

/* ---------- 首頁 ---------- */
.home { position: absolute; inset: 0; }
.home[hidden] { display: none; }
.words { position: absolute; inset: 0; pointer-events: none; }
.w {
  position: absolute; left: 50%; top: 50%; white-space: nowrap;
  transition: transform 720ms var(--ease-wind), opacity 520ms ease, filter 520ms ease;
}
.app.no-anim .w { transition: none; }
.w-in { animation: wordIn 600ms var(--ease-out) both; }
.w-txt { display: block; line-height: 1; animation: floatA 4s ease-in-out infinite alternate; }

.bar {
  position: absolute; top: 0; left: 0; right: 0; height: 64px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 12px 0 24px;
  transition: opacity 280ms ease;
}
.brand { display: flex; align-items: baseline; gap: 8px; }
.brand b { font-size: 17px; font-weight: 900; letter-spacing: 0.04em; }
.brand small { font-size: 13px; font-weight: 500; color: var(--dim); }
.icon-btn { width: 44px; height: 44px; border-radius: 22px; display: flex; align-items: center; justify-content: center; color: var(--text); }
.icon-btn.muted { color: var(--dim); }

.cta {
  position: absolute; left: 50%; top: 50%;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  transform: translate(-50%, -32px);
  transition: transform 520ms var(--ease-wind) 260ms, opacity 300ms ease 260ms;
}
.start {
  width: 188px; height: 64px; border-radius: 32px;
  background: var(--yellow); color: var(--ink);
  font-size: 19px; font-weight: 900;
  box-shadow: 0 0 0 3px var(--violet), 0 0 0 5px var(--pink), 0 0 36px rgba(255,138,216,0.55);
}
.secret-hint { margin: 0; font-size: 13px; font-weight: 500; color: var(--cyan); }

/* 按下開始：字被吸進中心、按鈕旋轉縮小 */
.app[data-inward] .bar { opacity: 0; pointer-events: none; }
.app[data-inward] .cta {
  transform: translate(-50%, -32px) scale(0.1) rotate(45deg); opacity: 0; pointer-events: none;
  transition: transform 520ms var(--ease-wind) 240ms, opacity 300ms ease 460ms;
}

/* ---------- 配對中（Loading A：字的漩渦） ---------- */
.portal {
  position: absolute; inset: 0; background: var(--night);
  clip-path: polygon(50% 50%, 50% 50%, 50% 50%, 50% 50%);
  transition: clip-path 760ms var(--ease-in-out);
  pointer-events: none;
}
.portal.open { clip-path: polygon(50% -60%, 160% 50%, 50% 160%, -60% 50%); pointer-events: auto; }
.portal > * { visibility: hidden; }
.portal.open > * { visibility: visible; }
.swirl { position: absolute; left: 50%; top: 42%; width: 0; height: 0; animation: orbit 28s linear infinite; }
.sw { position: absolute; left: 0; top: 0; }
.sw-flow { position: absolute; left: 0; top: 0; animation: inflow 5s cubic-bezier(0.55, 0, 0.85, 0.45) infinite; }
.sw-back { animation: orbitBack 28s linear infinite; }
.sw-txt { display: block; transform: translate(-50%, -50%); white-space: nowrap; line-height: 1; }
.halo { position: absolute; left: 50%; top: 42%; width: 120px; height: 120px; border-radius: 50%; background: var(--pink); filter: blur(34px); animation: halo 2.4s ease-in-out infinite; }
.core { position: absolute; left: 50%; top: 42%; width: 18px; height: 18px; border-radius: 50%; background: var(--yellow); box-shadow: 0 0 24px 8px rgba(255,211,110,0.6); animation: core 1.6s ease-in-out infinite; }
.status { position: absolute; left: 0; right: 0; top: 66%; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.portal.open .status { animation: enter 420ms 300ms var(--ease-out) both; }
.status-title { margin: 0; font-size: 32px; font-weight: 900; letter-spacing: -0.02em; }
.clock { margin: 0; font-size: 15px; font-weight: 500; color: var(--cyan); font-variant-numeric: tabular-nums; }
.ghost-btn { height: 60px; border: 2px solid var(--pink); border-radius: 30px; color: var(--pink); font-size: 17px; font-weight: 700; }
.cancel { position: absolute; left: 22px; right: 22px; bottom: 40px; }
.portal.open .cancel { animation: enter 420ms 420ms var(--ease-out) both; }

/* ---------- 對話中 ---------- */
.chat { position: absolute; inset: 0; display: flex; flex-direction: column; animation: enter 360ms var(--ease-out); }
.chat[hidden] { display: none; }
.chat-bar { height: 64px; flex-shrink: 0; display: grid; grid-template-columns: 88px minmax(0, 1fr) 88px; align-items: center; padding: 0 8px; }
.text-btn { justify-self: start; height: 44px; padding: 0 12px; color: var(--dim); font-size: 15px; font-weight: 500; }
.chat-bar .icon-btn { justify-self: end; }
.online { display: flex; align-items: center; justify-content: center; gap: 8px; font-size: 15px; font-weight: 700; }
.diamond { width: 8px; height: 8px; transform: rotate(45deg); background: var(--cyan); box-shadow: 0 0 10px var(--cyan); }
.log { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column-reverse; }
.msgs { display: flex; flex-direction: column; gap: 10px; padding: 16px; }
.m { display: flex; flex-direction: column; gap: 6px; animation: enter 220ms var(--ease-out); }
.m.them { align-items: flex-start; }
.m.me { align-items: flex-end; gap: 4px; }
.bubble { max-width: 80%; padding: 12px 16px; font-size: 16px; line-height: 1.55; overflow-wrap: anywhere; }
.them .bubble { border-radius: 22px 22px 22px 6px; background: rgba(255,255,255,0.08); border: 1px solid rgba(125,240,255,0.25); }
.me .bubble { border-radius: 22px 22px 6px 22px; background: var(--pink); color: #2A0B2E; font-weight: 500; box-shadow: 0 0 20px rgba(255,138,216,0.35); }
.warn { margin: 0 0 0 6px; max-width: 82%; font-size: 12px; line-height: 1.65; color: var(--warn); font-weight: 500; }
.status-line { font-size: 11px; color: var(--dim); margin-right: 6px; }
.sys { margin: 8px 0; text-align: center; font-size: 12px; color: var(--dim); }
.typing { align-self: flex-start; display: flex; gap: 5px; padding: 16px 18px; border-radius: 22px 22px 22px 6px; background: rgba(255,255,255,0.08); border: 1px solid rgba(125,240,255,0.25); }
.typing span { width: 7px; height: 7px; border-radius: 4px; animation: dot 1.2s infinite; }
.typing span:nth-child(1) { background: var(--pink); }
.typing span:nth-child(2) { background: var(--yellow); animation-delay: 0.15s; }
.typing span:nth-child(3) { background: var(--cyan); animation-delay: 0.3s; }
.composer { flex-shrink: 0; display: flex; align-items: center; gap: 8px; padding: 10px 12px calc(24px + env(safe-area-inset-bottom)) 12px; }
.composer input { flex: 1; min-width: 0; height: 52px; padding: 0 18px; border: 1px solid rgba(255,255,255,0.14); border-radius: 26px; background: rgba(255,255,255,0.06); color: var(--text); font: inherit; font-size: 16px; }
.composer input::placeholder { color: #9C8CCB; }
.send { width: 52px; height: 52px; flex-shrink: 0; border-radius: 26px; background: var(--yellow); color: var(--ink); display: flex; align-items: center; justify-content: center; transition: opacity 150ms ease, transform 160ms var(--ease-out); }
.send:disabled { opacity: 0.35; cursor: default; }

/* ---------- 結束 ---------- */
.ended { position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: flex-end; gap: 10px; padding: 0 22px 40px 22px; }
.ended[hidden] { display: none; }
.done { font-size: 180px; font-weight: 900; line-height: 1; letter-spacing: -0.06em; margin-left: -10px; color: var(--yellow); text-shadow: 0 0 40px rgba(255,211,110,0.4); animation: rise 600ms var(--ease-out) both; }
.end-text { margin: 0 0 18px 0; font-size: 16px; line-height: 1.6; animation: rise 500ms 80ms var(--ease-out) both; }
.big-btn { height: 72px; border-radius: 36px; background: var(--yellow); color: var(--ink); font-size: 20px; font-weight: 900; }
.big-btn.small { height: 56px; font-size: 17px; font-weight: 700; width: 100%; }
.link-btn { height: 44px; font-size: 15px; text-decoration: underline; text-underline-offset: 4px; }

/* ---------- 浮層 ---------- */
.layer { position: absolute; inset: 0; z-index: 10; }
.layer[hidden] { display: none; }
.scrim { position: absolute; inset: 0; width: 100%; height: 100%; background: rgba(10,3,30,0.55); }
.scrim.clear { background: transparent; }
.scrim:active { transform: none; }
.menu { position: absolute; top: 60px; right: 12px; width: 208px; padding: 6px; border-radius: 20px; background: var(--panel); border: 1px solid rgba(255,138,216,0.35); box-shadow: 0 18px 48px rgba(0,0,0,0.45); display: flex; flex-direction: column; transform-origin: top right; animation: pop 180ms var(--ease-out); }
.menu button { height: 46px; padding: 0 14px; border-radius: 14px; font-size: 15px; font-weight: 500; text-align: left; }
.menu .danger { color: var(--warn); }
.sheet { position: absolute; left: 0; right: 0; bottom: 0; padding: 24px 22px calc(32px + env(safe-area-inset-bottom)) 22px; border-radius: 28px 28px 0 0; background: var(--panel); border-top: 1px solid rgba(255,138,216,0.35); display: flex; flex-direction: column; gap: 16px; animation: sheetUp 320ms var(--ease-drawer); }
.sheet h2, .fonts h2 { margin: 0; font-size: 28px; font-weight: 900; letter-spacing: -0.02em; }
.field { display: flex; flex-direction: column; gap: 8px; font-size: 14px; font-weight: 500; color: var(--dim); }
.field input { height: 50px; padding: 0 18px; border: 1px solid rgba(255,255,255,0.14); border-radius: 25px; background: var(--night); color: var(--text); font: inherit; font-size: 16px; font-weight: 400; }
.note { margin: -8px 0 0 0; font-size: 12px; line-height: 1.6; color: var(--dim); }
.row { display: flex; align-items: center; justify-content: space-between; min-height: 44px; font-size: 16px; font-weight: 500; }
.row input { width: 22px; height: 22px; accent-color: var(--pink); }
.row-btn { display: flex; align-items: center; justify-content: space-between; min-height: 52px; padding: 0 18px; border-radius: 26px; background: var(--night); font-size: 16px; font-weight: 500; text-align: left; }
.dim { font-size: 14px; color: var(--dim); }

.fonts { position: absolute; inset: 0; background: var(--panel); display: flex; flex-direction: column; animation: sheetUp 320ms var(--ease-drawer); }
.fonts-bar { height: 64px; flex-shrink: 0; display: grid; grid-template-columns: 88px minmax(0, 1fr) 88px; align-items: center; padding: 0 8px; }
.fonts-bar h2 { font-size: 17px; text-align: center; letter-spacing: 0; }
.preview { flex-shrink: 0; margin: 0 16px 12px 16px; padding: 18px 20px; border-radius: 22px; background: var(--night); }
.preview p { margin: 0; font-size: 22px; line-height: 1.5; }
.preview .en { margin-top: 4px; color: var(--yellow); line-height: 1.4; }
.font-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 4px 16px 16px 16px; }
.group { margin: 8px 4px 10px 4px; font-size: 13px; font-weight: 700; color: var(--dim); }
.group:not(:first-child) { margin-top: 20px; }
.font-scroll .note { margin: 18px 4px 0 4px; }
.font-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.font-opt { min-height: 72px; padding: 10px 14px; border-radius: 18px; background: rgba(255,255,255,0.06); display: flex; flex-direction: column; align-items: flex-start; justify-content: center; gap: 4px; text-align: left; }
.font-opt[aria-pressed="true"] { background: var(--yellow); color: var(--ink); }
.font-opt .sample { font-size: 21px; line-height: 1.2; }
.font-opt .name { font-size: 12px; font-weight: 500; opacity: 0.8; font-family: var(--ui); }
.fonts-foot { flex-shrink: 0; padding: 8px 16px calc(28px + env(safe-area-inset-bottom)) 16px; }

/* ---------- 電腦版（寬度 900px 以上） ---------- */
@media (min-width: 900px) {
  .bar { height: 80px; padding: 0 28px 0 40px; }
  .brand b { font-size: 22px; }
  .cta { transform: translate(-50%, -38px); }
  .app[data-inward] .cta { transform: translate(-50%, -38px) scale(0.1) rotate(45deg); }
  .start { width: 240px; height: 76px; border-radius: 38px; font-size: 22px; }
  .secret-hint { font-size: 15px; }

  .swirl, .halo, .core { scale: 1.3; }
  .status { top: 72%; }
  .status-title { font-size: 40px; }
  .clock { font-size: 17px; }
  .cancel { left: calc(50% - 160px); right: calc(50% - 160px); bottom: 56px; }

  .chat-bar { height: 72px; padding: 0 20px; }
  .msgs { width: 100%; max-width: 760px; margin: 0 auto; padding: 28px 24px; gap: 12px; }
  .bubble { max-width: 68%; }
  .warn { max-width: 68%; }
  .composer { width: 100%; max-width: 792px; margin: 0 auto; padding: 12px 16px 36px 16px; }
  .menu { top: 64px; right: 20px; }

  .ended { justify-content: center; padding: 0 max(32px, calc(50% - 300px)); }
  .done { font-size: 220px; }
  .end-text { font-size: 18px; }

  .sheet {
    left: 50%; top: 50%; right: auto; bottom: auto; width: 440px;
    translate: -50% -50%;
    padding: 28px 28px 28px 28px;
    border-radius: 28px; border: 1px solid rgba(255,138,216,0.35);
    box-shadow: 0 30px 90px rgba(0,0,0,0.5);
    animation: pop 200ms var(--ease-out);
  }
  #fontLayer { background: rgba(10,3,30,0.55); }
  .fonts {
    left: 50%; top: 50%; right: auto; bottom: auto;
    width: 680px; height: min(800px, 88dvh);
    translate: -50% -50%;
    border-radius: 28px; border: 1px solid rgba(255,138,216,0.35); overflow: hidden;
    box-shadow: 0 30px 90px rgba(0,0,0,0.5);
    animation: pop 200ms var(--ease-out);
  }
  .font-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .fonts-foot { padding-bottom: 20px; }
}

/* 有滑鼠的裝置：滑過時的回饋 */
@media (hover: hover) and (pointer: fine) {
  .start:hover { box-shadow: 0 0 0 3px var(--violet), 0 0 0 5px var(--pink), 0 0 52px rgba(255,138,216,0.8); }
  .big-btn:hover, .send:not(:disabled):hover { filter: brightness(1.06); }
  .ghost-btn:hover { background: rgba(255,138,216,0.1); }
  .icon-btn:hover, .text-btn:hover { background: rgba(255,255,255,0.08); border-radius: 22px; }
  .menu button:hover, .row-btn:hover, .font-opt:not([aria-pressed="true"]):hover { background: rgba(255,255,255,0.1); }
}

/* ---------- 動態 ---------- */
@keyframes enter { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes rise { from { opacity: 0; transform: translateY(40%); } to { opacity: 1; transform: none; } }
@keyframes wordIn { from { opacity: 0; transform: scale(0.9); } to { opacity: 1; transform: none; } }
@keyframes floatA { from { transform: translate(0, 0); } to { transform: translate(7px, -11px); } }
@keyframes floatB { from { transform: translate(0, 0); } to { transform: translate(-9px, 7px); } }
@keyframes floatC { from { transform: translate(0, 0); } to { transform: translate(6px, 10px); } }
@keyframes orbit { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
@keyframes orbitBack { from { transform: rotate(0deg); } to { transform: rotate(-360deg); } }
@keyframes inflow { 0% { transform: translateX(200px); opacity: 0; } 12% { opacity: 1; } 78% { opacity: 0.95; } 100% { transform: translateX(6px) scale(0.15); opacity: 0; } }
@keyframes core { 0%, 100% { transform: translate(-50%, -50%) scale(1); } 50% { transform: translate(-50%, -50%) scale(1.25); } }
@keyframes halo { 0%, 100% { transform: translate(-50%, -50%) scale(0.9); opacity: 0.35; } 50% { transform: translate(-50%, -50%) scale(1.15); opacity: 0.6; } }
@keyframes dot { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: none; } }
@keyframes pop { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
