:root {
  color-scheme: dark;
  --ink: #f2edf5;
  --muted: #b9afc0;
  --dim: #887e90;
  --purple: #c8afe2;
  --purple-dim: #9175ad;
  --green: #8ebca2;
  --red: #d49a9c;
  --panel: rgba(24, 18, 29, .78);
  --surface2: rgba(255, 255, 255, .032);
  --line: rgba(230, 220, 240, .09);
}

* { box-sizing: border-box; }

html { min-height: 100%; background: #070409; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at 78% 4%, rgba(200, 175, 226, .12), transparent 32%),
    linear-gradient(165deg, #1c1424 0%, #100a16 58%, #070409 100%);
  font-family: ui-rounded, "SF Pro Rounded", "Noto Sans TC", system-ui, sans-serif;
}

button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; color: inherit; }
[hidden] { display: none !important; }

.app-shell {
  position: relative;
  width: min(100%, 520px);
  min-height: 100vh;
  min-height: 100dvh;
  margin: auto;
  display: flex;
  flex-direction: column;
  background: rgba(7, 4, 9, .3);
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 5;
  min-height: 72px;
  padding: 13px 17px max(13px, env(safe-area-inset-top));
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  background: rgba(7, 4, 9, .74);
  backdrop-filter: blur(18px);
}

.brand { display: flex; align-items: center; gap: 9px; text-decoration: none; }
.brand-mark {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 1px solid rgba(200, 175, 226, .25);
  border-radius: 13px;
  color: var(--purple);
  background: rgba(200, 175, 226, .075);
  font-weight: 900;
}
.brand > span:last-child { display: grid; }
.brand b { letter-spacing: .1em; font-size: 14px; }
.brand small { margin-top: 1px; color: var(--muted); font-size: 9px; letter-spacing: .1em; }

.header-player { display: flex; align-items: center; gap: 9px; }
.sim-chip {
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--purple);
  background: rgba(5, 3, 8, .3);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .06em;
}

.avatar, .large-avatar {
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 13px;
  color: var(--purple);
  background: rgba(200, 175, 226, .075);
  border: 1px solid rgba(200, 175, 226, .22);
  image-rendering: pixelated;
}
.avatar { width: 38px; height: 38px; padding: 4px; cursor: pointer; }
.large-avatar { width: 56px; height: 56px; padding: 6px; border-radius: 15px; }
.pixel-face, .player-image {
  grid-area: 1 / 1;
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 5px;
  image-rendering: pixelated;
}
.pixel-face {
  background:
    linear-gradient(#150f1c 0 0) 0 0/100% 25% no-repeat,
    linear-gradient(#070409 0 0) 22% 50%/18% 16% no-repeat,
    linear-gradient(#070409 0 0) 78% 50%/18% 16% no-repeat,
    linear-gradient(#c38d91 0 0) 50% 78%/28% 10% no-repeat,
    linear-gradient(135deg, var(--purple), var(--purple-dim));
}
.player-image { object-fit: cover; }

.system-message { margin: auto; padding: 40px 22px; color: var(--muted); text-align: center; line-height: 1.7; }
.system-message.error { color: var(--red); }

main { flex: 1; }
.view { position: relative; z-index: 1; padding: 23px 17px 31px; }

.title-row, .block-title { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.kicker { margin: 0 0 6px; color: var(--purple); font-size: 10px; font-weight: 800; letter-spacing: .15em; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(24px, 7vw, 31px); line-height: 1.18; letter-spacing: -.045em; }
h2 { margin-bottom: 0; font-size: 18px; }
.title-row > span, .sync-state { color: var(--purple); font-size: 10px; font-weight: 800; letter-spacing: .05em; }

.asset-card {
  position: relative;
  min-height: 195px;
  margin-top: 18px;
  padding: 19px;
  overflow: hidden;
  border: 1px solid rgba(200, 175, 226, .16);
  border-radius: 26px;
  background:
    radial-gradient(circle at 88% 6%, rgba(200, 175, 226, .17), transparent 38%),
    linear-gradient(145deg, rgba(83, 60, 105, .3), rgba(20, 13, 28, .6)),
    #120b19;
  box-shadow: 0 18px 52px rgba(0, 0, 0, .28), inset 0 1px rgba(255, 255, 255, .035);
}
.asset-top { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; }
.asset-top button, .block-title button {
  padding: 0;
  border: 0;
  color: var(--purple);
  background: transparent;
  font-size: 10px;
  font-weight: 800;
  cursor: pointer;
}
.asset-card strong { display: block; margin-top: 14px; font-size: 30px; font-variant-numeric: tabular-nums; letter-spacing: -.03em; }
.asset-meta { margin-top: 9px; display: flex; justify-content: space-between; color: var(--purple); font-size: 11px; }
.asset-meta small { color: var(--muted); font-size: 9px; }
.pixel-bars { position: absolute; right: 16px; bottom: 15px; left: 16px; height: 48px; display: flex; align-items: flex-end; gap: 5px; opacity: .45; }
.pixel-bars i { flex: 1; background: linear-gradient(var(--purple), var(--purple-dim)); border-radius: 3px 3px 0 0; }
.pixel-bars i:nth-child(1) { height: 22%; }
.pixel-bars i:nth-child(2) { height: 39%; }
.pixel-bars i:nth-child(3) { height: 31%; }
.pixel-bars i:nth-child(4) { height: 52%; }
.pixel-bars i:nth-child(5) { height: 44%; }
.pixel-bars i:nth-child(6) { height: 68%; }
.pixel-bars i:nth-child(7) { height: 63%; }
.pixel-bars i:nth-child(8) { height: 83%; }

.quick-grid { margin-top: 12px; display: grid; grid-template-columns: repeat(2, 1fr); gap: 9px; }
.quick {
  min-height: 102px;
  padding: 15px;
  display: grid;
  gap: 3px;
  text-align: left;
  text-decoration: none;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
  backdrop-filter: blur(18px);
  cursor: pointer;
}
.quick span { color: var(--purple); font-size: 19px; }
.quick b { margin-top: 7px; font-size: 12px; }
.quick small { color: var(--dim); font-size: 9px; }
.quick.primary { border-color: rgba(200, 175, 226, .23); background: linear-gradient(145deg, rgba(200, 175, 226, .11), var(--panel)); }
.quick.primary span { color: var(--purple); }
.quick.disabled { opacity: .42; cursor: not-allowed; }

.block { margin-top: 26px; }
.block-title { margin-bottom: 10px; }
.stock-list, .holding-list, .order-list { display: grid; gap: 7px; }
.stock-row {
  width: 100%;
  padding: 11px 12px;
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: rgba(255, 255, 255, .018);
  text-align: left;
  cursor: pointer;
}
.stock-symbol {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 11px;
  color: #1b1620;
  background: #c9b2df;
  font-weight: 800;
  font-size: 10px;
}
.stock-copy { min-width: 0; display: grid; gap: 3px; }
.stock-copy b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; }
.stock-copy small { color: var(--dim); font-size: 9px; }
.stock-quote { display: grid; gap: 3px; text-align: right; font-variant-numeric: tabular-nums; }
.stock-quote b { font-size: 11px; }
.stock-quote small { color: var(--red); font-size: 9px; font-weight: 700; }
.stock-quote small.down { color: var(--green); }
.stock-quote small.flat { color: var(--dim); }

.simulation-banner {
  margin-top: 15px;
  padding: 13px;
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 10px;
  border: 1px solid rgba(200, 175, 226, .19);
  border-radius: 15px;
  background: linear-gradient(135deg, rgba(200, 175, 226, .075), rgba(255, 255, 255, .018));
}
.simulation-banner > span { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 10px; color: #1b1620; background: #c9b2df; }
.simulation-banner div { display: grid; gap: 3px; }
.simulation-banner b { color: var(--purple); font-size: 10px; }
.simulation-banner p { margin: 0; color: var(--muted); font-size: 10px; line-height: 1.6; }

.search {
  margin: 14px 0 12px;
  padding: 0 13px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: rgba(255, 255, 255, .026);
}
.search input { width: 100%; min-height: 46px; border: 0; outline: 0; color: var(--ink); background: transparent; font-size: 16px; }
.sector-tabs { margin-bottom: 12px; display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.sector-tabs button {
  flex: none;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: transparent;
  font-size: 10px;
  cursor: pointer;
}
.sector-tabs button.active { color: #1b1620; border-color: #c9b2df; background: #c9b2df; font-weight: 800; }

.summary {
  margin: 19px 0 13px;
  padding: 16px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 13px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
  backdrop-filter: blur(18px);
}
.summary div { display: grid; gap: 4px; }
.summary small { color: var(--dim); font-size: 9px; }
.summary b { font-size: 14px; font-variant-numeric: tabular-nums; }
.holding {
  margin-bottom: 9px;
  padding: 14px;
  display: grid;
  gap: 11px;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: rgba(255, 255, 255, .018);
}
.holding-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.holding-heading b { font-size: 12px; }
.holding-heading span { color: var(--muted); font-size: 10px; font-weight: 700; }
.holding-metrics { display: grid; grid-template-columns: 1fr 1fr 1.35fr; gap: 7px; }
.holding-metrics > span { min-width: 0; display: grid; gap: 4px; padding: 9px; border-radius: 11px; background: rgba(255, 255, 255, .027); }
.holding-metrics small { color: var(--dim); font-size: 8px; white-space: nowrap; }
.holding-metrics b { overflow: hidden; font-size: 10px; font-variant-numeric: tabular-nums; text-overflow: ellipsis; white-space: nowrap; }
.holding-pnl { padding-top: 10px; display: flex; align-items: center; justify-content: space-between; gap: 12px; border-top: 1px solid var(--line); }
.holding-pnl > small { color: var(--muted); font-size: 9px; }
.holding-pnl strong { display: flex; align-items: center; justify-content: flex-end; gap: 7px; font-size: 11px; font-variant-numeric: tabular-nums; }
.holding-pnl em { padding: 4px 7px; border-radius: 999px; font-size: 9px; font-style: normal; }
.holding-pnl.gain { color: var(--red); }
.holding-pnl.loss { color: var(--green); }
.holding-pnl.flat { color: var(--dim); }
.holding-pnl.gain em { color: #f3e9ed; background: rgba(212, 154, 156, .18); }
.holding-pnl.loss em { color: #e9f2ec; background: rgba(142, 188, 162, .17); }
.holding-pnl.flat em { background: rgba(255, 255, 255, .05); }
.portfolio-sync { display: grid; justify-items: end; gap: 5px; }
.portfolio-sync span { color: var(--purple); font-size: 8px; font-weight: 800; white-space: nowrap; }
.portfolio-sync button { padding: 4px 7px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); background: rgba(255, 255, 255, .026); font-size: 8px; cursor: pointer; }
.portfolio-sync button:disabled { opacity: .55; cursor: wait; }
.portfolio-note { margin: 10px 2px 0; color: var(--dim); font-size: 8px; line-height: 1.6; }
.order-row { padding: 12px 2px; display: flex; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--line); }
.order-row div { display: grid; gap: 3px; }
.order-row div:last-child { text-align: right; }
.order-row b { font-size: 11px; }
.order-row small { color: var(--dim); font-size: 9px; }
.order-row em { color: var(--purple); font-size: 9px; font-style: normal; font-weight: 700; }
.order-row em.done { color: var(--green); }
.order-row em.failed { color: var(--red); }
.empty { padding: 20px 8px; color: var(--dim); font-size: 11px; text-align: center; }

.identity {
  margin: 19px 0 23px;
  padding: 17px;
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr) auto;
  align-items: center;
  gap: 11px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--panel);
  backdrop-filter: blur(18px);
}
.identity > div { min-width: 0; display: grid; gap: 3px; }
.identity b { font-size: 14px; }
.identity small { overflow: hidden; color: var(--dim); font-size: 9px; text-overflow: ellipsis; white-space: nowrap; }
.identity > span:last-child { color: var(--purple); font-size: 9px; font-weight: 800; }

.settings > a, .settings > div {
  min-height: 64px;
  padding: 10px 1px;
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--line);
  text-decoration: none;
}
.settings i { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 11px; color: var(--purple); background: rgba(200, 175, 226, .075); font-style: normal; }
.settings span { display: grid; gap: 3px; }
.settings b { font-size: 11px; }
.settings small, .settings em { color: var(--dim); font-size: 9px; font-style: normal; }

.bottom-nav {
  position: sticky;
  bottom: 0;
  z-index: 4;
  min-height: 68px;
  padding: 7px 9px max(7px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border-top: 1px solid var(--line);
  background: rgba(7, 4, 9, .86);
  backdrop-filter: blur(18px);
}
.bottom-nav button { padding: 5px; display: grid; place-items: center; gap: 2px; border: 0; color: var(--dim); background: transparent; font-size: 9px; cursor: pointer; }
.bottom-nav span { font-size: 18px; }
.bottom-nav button.active { color: var(--purple); }

.dialog-backdrop {
  position: fixed;
  z-index: 10;
  inset: 0;
  padding: 16px;
  display: grid;
  place-items: center;
  background: rgba(4, 2, 6, .78);
  backdrop-filter: blur(7px);
}
.dialog {
  position: relative;
  width: min(100%, 420px);
  max-height: calc(100vh - 32px);
  padding: 22px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: linear-gradient(165deg, #1c1424, #0f0912);
  box-shadow: 0 24px 70px rgba(0, 0, 0, .4);
}
.dialog-close { position: absolute; top: 11px; right: 11px; width: 36px; height: 36px; border: 0; border-radius: 11px; color: var(--muted); background: rgba(255, 255, 255, .05); cursor: pointer; }
.trade-title { margin-bottom: 14px; display: flex; justify-content: space-between; gap: 10px; }
.trade-title h2 { margin-bottom: 3px; }
.trade-title small { color: var(--dim); font-size: 9px; }
.trade-title strong { font-size: 19px; font-variant-numeric: tabular-nums; }
.segmented { margin-bottom: 13px; padding: 3px; display: grid; grid-template-columns: 1fr 1fr; gap: 3px; border-radius: 12px; background: rgba(255, 255, 255, .04); }
.segmented button { min-height: 40px; border: 0; border-radius: 10px; color: var(--muted); background: transparent; font-weight: 700; cursor: pointer; }
.segmented button.active { color: #1b1620; background: #c9b2df; font-weight: 800; }
.dialog label { display: grid; gap: 6px; color: var(--muted); font-size: 10px; font-weight: 800; }
.dialog input {
  width: 100%;
  min-height: 46px;
  padding: 10px 13px;
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: 0;
  color: var(--ink);
  background: rgba(3, 14, 15, .42);
  font-size: 16px;
}
.dialog input:focus { border-color: var(--purple); box-shadow: 0 0 0 3px rgba(200, 175, 226, .09); }
.estimate { margin-top: 12px; padding: 11px 0; display: flex; justify-content: space-between; border-block: 1px solid var(--line); font-size: 11px; }
.estimate b { font-variant-numeric: tabular-nums; }
.order-warning { margin-top: 11px; padding: 10px 12px; display: grid; gap: 3px; border-radius: 12px; border-left: 3px solid var(--purple); background: rgba(200, 175, 226, .06); }
.order-warning b { color: var(--purple); font-size: 9px; }
.order-warning span { color: var(--muted); font-size: 9px; line-height: 1.5; }
.dialog label.consent { margin-top: 11px; grid-template-columns: 16px 1fr; align-items: start; gap: 7px; line-height: 1.5; cursor: pointer; }
.dialog label.consent input { width: 15px; min-height: 15px; margin: 0; accent-color: var(--purple); }
.submit-order { width: 100%; min-height: 48px; margin-top: 13px; border: 0; border-radius: 14px; color: #1b1620; background: #c9b2df; font-weight: 800; cursor: pointer; }
.submit-order:disabled { color: #9b93a8; background: rgba(255, 255, 255, .06); cursor: not-allowed; }
.dialog-message { min-height: 16px; margin: 8px 0 0; color: var(--red); font-size: 10px; text-align: center; }

.toast {
  position: fixed;
  z-index: 20;
  right: 16px;
  bottom: 82px;
  left: 16px;
  max-width: 420px;
  margin: auto;
  padding: 12px 15px;
  border-radius: 14px;
  color: #1b1620;
  background: #c9b2df;
  text-align: center;
  font-size: 11px;
  font-weight: 800;
  box-shadow: 0 14px 36px rgba(0, 0, 0, .24);
}

@media (min-width: 650px) {
  body { padding: 18px; }
  .app-shell { min-height: 850px; border: 1px solid var(--line); border-radius: 32px; overflow: hidden; }
  .bottom-nav { position: static; }
}

@media (max-width: 380px) {
  .sim-chip { display: none; }
  .view { padding-inline: 13px; }
  .identity { grid-template-columns: 50px minmax(0, 1fr); }
  .identity > span:last-child { grid-column: 2; }
  .large-avatar { width: 50px; height: 50px; }
  .holding-metrics { grid-template-columns: 1fr 1fr; }
  .holding-metrics > span:last-child { grid-column: 1 / -1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
