:root {
  color-scheme: dark;
  --bg: #0a0d11;
  --surface: rgba(21, 25, 31, 0.86);
  --surface-2: rgba(255, 255, 255, 0.04);
  --text: #f7f7f4;
  --muted: #a7acb4;
  --line: rgba(255, 255, 255, 0.08);
  --gold: #efc766;
  --gold-bright: #ffe7a1;
  --green: #5bd18d;
  --red: #ff7d7d;
  --radius-xl: 28px;
  --radius-lg: 20px;
  --shadow: 0 24px 70px rgba(0,0,0,.35);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background:
    radial-gradient(circle at 85% -10%, rgba(239,199,102,.14), transparent 30%),
    radial-gradient(circle at 0% 20%, rgba(91,209,141,.06), transparent 26%),
    linear-gradient(180deg, #10141a 0%, var(--bg) 42%);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
a { color: inherit; }

.app-shell {
  width: min(100%, 760px);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 18px calc(32px + env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 4px 2px 16px;
}
.eyebrow {
  margin: 0 0 5px;
  color: var(--gold);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .18em;
}
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 28px; letter-spacing: -.03em; }
h2 { margin-bottom: 0; font-size: 20px; letter-spacing: -.02em; }
.section-subtitle {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.icon-button, .close-button {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: rgba(255,255,255,.045);
  backdrop-filter: blur(14px);
  color: var(--text);
  cursor: pointer;
}
.icon-button svg { width: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.icon-button:active, .close-button:active { transform: scale(.96); }

.notice-card {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  padding: 14px 16px;
  border: 1px solid rgba(239,199,102,.16);
  border-radius: 18px;
  background: linear-gradient(145deg, rgba(239,199,102,.10), rgba(255,255,255,.03));
  backdrop-filter: blur(12px);
}
.notice-card[hidden] { display: none; }
.notice-icon {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(239,199,102,.16);
  color: var(--gold-bright);
  font-weight: 900;
  font-size: 16px;
}
.notice-icon.error {
  background: rgba(255,125,125,.14);
  color: var(--red);
}
.notice-card strong { display: block; font-size: 14px; }
.notice-card p { margin: 3px 0 0; color: #d0d4db; font-size: 13px; line-height: 1.45; }
.error-card {
  margin-top: 16px;
  margin-bottom: 0;
  border-color: rgba(255,125,125,.18);
  background: rgba(255,125,125,.07);
}

.hero-card {
  position: relative;
  overflow: hidden;
  isolation: isolate;
  padding: 28px 22px 22px;
  border: 1px solid rgba(239,199,102,.22);
  border-radius: var(--radius-xl);
  background:
    radial-gradient(circle at 100% 0%, rgba(239,199,102,.18) 0%, rgba(239,199,102,.08) 24%, transparent 48%),
    linear-gradient(145deg, #282216 0%, #181b20 56%, #12161c 100%);
  background-clip: padding-box;
  box-shadow: var(--shadow);
}
.hero-topline {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.hero-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  padding: 0 12px;
  border-radius: 999px;
  background: rgba(255,255,255,.08);
  color: #f0e5c3;
  font-size: 12px;
  font-weight: 750;
}
.hero-label { margin-bottom: 8px; color: #d4c9ab; font-size: 15px; }
.hero-value {
  margin: 2px 0 0;
  font-size: clamp(42px, 12vw, 68px);
  font-weight: 780;
  line-height: 1.02;
  letter-spacing: -.055em;
  font-variant-numeric: tabular-nums;
}

.profit-strip {
  display: grid;
  grid-template-columns: minmax(0, .9fr) minmax(0, 1.1fr);
  gap: 1px;
  overflow: hidden;
  margin-top: 22px;
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 16px;
  background: rgba(255,255,255,.08);
}
.profit-cost,
.profit-result {
  min-width: 0;
  padding: 13px 14px;
  background: rgba(12,15,19,.48);
}
.profit-cost > span,
.profit-result > span {
  display: block;
  margin-bottom: 6px;
  color: #aeb4bd;
  font-size: 11px;
  font-weight: 650;
}
.profit-cost strong {
  display: block;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.profit-result > div {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}
.profit-result strong {
  font-size: 18px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.profit-result em {
  font-size: 12px;
  font-style: normal;
  font-weight: 800;
  white-space: nowrap;
}
.profit-result.positive strong,
.profit-result.positive em { color: var(--green); }
.profit-result.negative strong,
.profit-result.negative em { color: var(--red); }
.profit-result.neutral strong,
.profit-result.neutral em { color: var(--text); }
.hero-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  margin-top: 22px;
  color: var(--muted);
  font-size: 12px;
}
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 10px;
  border-radius: 999px;
  background: rgba(255,255,255,.06);
  color: #d8dbe0;
  font-weight: 650;
}
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--gold); box-shadow: 0 0 0 4px rgba(239,199,102,.10); }
.status-pill.online .status-dot { background: var(--green); box-shadow: 0 0 0 4px rgba(91,209,141,.10); }
.status-pill.error .status-dot { background: var(--red); box-shadow: 0 0 0 4px rgba(255,125,125,.10); }

.primary-action-row {
  display: flex;
  justify-content: flex-end;
  margin: 14px 0 0;
}
.refresh-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid rgba(239,199,102,.20);
  border-radius: 999px;
  background: linear-gradient(145deg, rgba(239,199,102,.11), rgba(255,255,255,.03));
  color: var(--gold-bright);
  font-size: 14px;
  font-weight: 750;
  cursor: pointer;
}
.refresh-chip svg { width: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.refresh-chip.loading svg { animation: spin .8s linear infinite; }
.refresh-chip:disabled { opacity: .65; cursor: default; }
@keyframes spin { to { transform: rotate(360deg); } }

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 12px;
}
.mini-stat {
  padding: 14px 14px 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: linear-gradient(145deg, rgba(255,255,255,.055), rgba(255,255,255,.025));
  backdrop-filter: blur(10px);
}
.mini-stat-label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
}
.mini-stat strong {
  display: block;
  font-size: 26px;
  letter-spacing: -.03em;
}

.section-block { margin-top: 30px; }
.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin: 0 3px 14px;
}

.holdings-list { display: grid; gap: 12px; }
.holding-card {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  min-height: 96px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: linear-gradient(145deg, rgba(255,255,255,.055), rgba(255,255,255,.025));
}
.bar-visual {
  display: grid;
  place-items: center;
  width: 58px;
  height: 44px;
  border-radius: 10px;
  background: linear-gradient(135deg, #fff0a7 0%, #dcae40 42%, #956a13 100%);
  color: #4c3504;
  box-shadow: inset 0 1px 1px rgba(255,255,255,.65), 0 8px 18px rgba(192,138,25,.16);
  transform: perspective(120px) rotateX(5deg) rotateY(-7deg);
}
.bar-visual.small { width: 52px; height: 38px; justify-self: center; }
.bar-visual span { font-size: 11px; font-weight: 900; letter-spacing: .04em; }
.holding-main { min-width: 0; }
.holding-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 5px;
}
.holding-main h3 { margin-bottom: 0; font-size: 16px; }
.holding-main p { margin-bottom: 0; color: var(--muted); font-size: 13px; }
.holding-qty {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: rgba(255,255,255,.05);
  color: #dadfe8;
  font-size: 12px;
  font-weight: 700;
}
.holding-card > strong {
  font-size: 19px;
  letter-spacing: -.025em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.history-heading { align-items: center; }
.history-count {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255,255,255,.035);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
.history-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background: linear-gradient(145deg, rgba(255,255,255,.055), rgba(255,255,255,.022));
}
.history-summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 18px 18px 0;
}
.history-summary > div {
  min-width: 0;
  padding: 14px;
  border-radius: 16px;
  background: rgba(255,255,255,.035);
}
.history-summary span {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}
.history-summary strong {
  display: block;
  font-size: 18px;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
}
.history-summary strong.positive { color: var(--green); }
.history-summary strong.negative { color: var(--red); }
.history-summary strong.neutral { color: var(--text); }

.chart-wrap {
  position: relative;
  min-height: 240px;
  margin: 14px 10px 0;
  padding: 10px 8px 0;
}
.chart-wrap svg {
  display: block;
  width: 100%;
  height: 240px;
  overflow: visible;
}
.chart-grid-line {
  stroke: rgba(255,255,255,.07);
  stroke-width: 1;
}
.chart-area { fill: url(#historyAreaGradient); }
.chart-line {
  fill: none;
  stroke: var(--gold);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 5px 9px rgba(239,199,102,.18));
}
.chart-point {
  fill: #15181d;
  stroke: var(--gold-bright);
  stroke-width: 3;
}
.chart-label {
  fill: #8f959e;
  font-size: 12px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", sans-serif;
}
.chart-value-label {
  fill: #d8dbe0;
  font-size: 12px;
  font-weight: 700;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", sans-serif;
}
.chart-empty {
  display: grid;
  place-items: center;
  align-content: center;
  min-height: 220px;
  padding: 30px;
  text-align: center;
}
.chart-empty[hidden] { display: none; }
.chart-empty strong { margin-bottom: 8px; font-size: 16px; }
.chart-empty span { max-width: 390px; color: var(--muted); font-size: 13px; line-height: 1.5; }

.history-list {
  display: grid;
  gap: 0;
  margin: 4px 18px 0;
  border-top: 1px solid var(--line);
}
.history-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 12px;
  min-height: 54px;
  border-bottom: 1px solid var(--line);
}
.history-row:last-child { border-bottom: 0; }
.history-date { color: #d8dbe0; font-size: 13px; font-weight: 650; }
.history-row-value { font-size: 14px; font-weight: 750; font-variant-numeric: tabular-nums; white-space: nowrap; }
.history-row-change {
  min-width: 66px;
  text-align: right;
  font-size: 12px;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.history-row-change.positive { color: var(--green); }
.history-row-change.negative { color: var(--red); }
.history-row-change.neutral { color: var(--muted); }
.history-note {
  margin: 12px 18px 18px;
  color: #777d86;
  font-size: 11px;
  line-height: 1.5;
}

footer { margin: 30px 5px 0; color: #777d86; font-size: 12px; line-height: 1.5; }
footer p { margin-bottom: 8px; }
footer a { color: #aab0ba; text-underline-offset: 3px; }

.settings-dialog {
  width: min(calc(100% - 24px), 560px);
  max-height: calc(100dvh - 24px);
  margin: auto auto max(12px, env(safe-area-inset-bottom));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 28px;
  background: #171a20;
  color: var(--text);
  box-shadow: 0 30px 90px rgba(0,0,0,.6);
}
.settings-dialog::backdrop { background: rgba(0,0,0,.66); backdrop-filter: blur(8px); }
.settings-dialog form { padding: 22px; }
.dialog-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
.dialog-header h2 { font-size: 24px; }
.close-button { border: 0; background: rgba(255,255,255,.06); font-size: 29px; line-height: 1; }
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 0;
  border-top: 1px solid var(--line);
}
.setting-row strong, .setting-row span { display: block; }
.setting-row strong { margin-bottom: 4px; font-size: 16px; }
.setting-row span { color: var(--muted); font-size: 12px; }
.stepper { display: grid; grid-template-columns: 38px 52px 38px; align-items: center; overflow: hidden; border: 1px solid var(--line); border-radius: 13px; background: rgba(255,255,255,.04); }
.stepper button { height: 42px; border: 0; background: transparent; color: var(--gold-bright); font-size: 23px; cursor: pointer; }
.stepper input { width: 52px; height: 42px; border: 0; border-left: 1px solid var(--line); border-right: 1px solid var(--line); outline: 0; background: rgba(0,0,0,.13); color: var(--text); text-align: center; font-weight: 750; appearance: textfield; }
.stepper input::-webkit-outer-spin-button, .stepper input::-webkit-inner-spin-button { appearance: none; margin: 0; }

.investment-setting {
  align-items: center;
}
.money-input {
  display: flex;
  align-items: center;
  overflow: hidden;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: rgba(255,255,255,.04);
}
.money-input input {
  width: 112px;
  height: 44px;
  padding: 0 10px;
  border: 0;
  outline: 0;
  background: rgba(0,0,0,.13);
  color: var(--text);
  text-align: right;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
  appearance: textfield;
}
.money-input input::-webkit-outer-spin-button,
.money-input input::-webkit-inner-spin-button { appearance: none; margin: 0; }
.money-input span {
  padding: 0 11px;
  color: var(--gold-bright);
  font-size: 13px;
  font-weight: 750;
}
.primary-button { width: 100%; min-height: 52px; margin-top: 18px; border: 0; border-radius: 15px; background: linear-gradient(135deg, #f5d57c, #d9a936); color: #2b1d00; font-weight: 850; cursor: pointer; box-shadow: 0 12px 26px rgba(217,169,54,.15); }
.primary-button:active { transform: translateY(1px); }

@media (min-width: 650px) {
  .app-shell { padding-left: 26px; padding-right: 26px; }
  .settings-dialog { margin: auto; }
}

@media (max-width: 540px) {
  .primary-action-row { justify-content: stretch; }
  .refresh-chip { width: 100%; }
  .summary-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .mini-stat { padding: 13px 10px 14px; }
  .mini-stat-label { min-height: 30px; font-size: 11px; }
  .mini-stat strong { font-size: 24px; }
  .history-summary { grid-template-columns: 1fr; }
  .history-latest { display: none; }
}

@media (max-width: 420px) {
  .profit-strip {
    grid-template-columns: 1fr;
  }
  .profit-cost,
  .profit-result {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
  }
  .profit-cost > span,
  .profit-result > span {
    margin-bottom: 0;
  }
  .investment-setting {
    align-items: stretch;
    flex-direction: column;
  }
  .money-input {
    width: 100%;
  }
  .money-input input {
    flex: 1 1 auto;
    width: auto;
  }
  .hero-card { padding: 24px 18px 20px; }
  .hero-badge { padding: 0 10px; font-size: 11px; }
  .hero-value { font-size: clamp(39px, 12.5vw, 52px); }
  .holding-card {
    grid-template-columns: 52px minmax(0,1fr);
    align-items: start;
  }
  .holding-card > strong {
    grid-column: 2;
    margin-top: 3px;
    font-size: 18px;
  }
  .bar-visual { width: 52px; }
  .history-row {
    grid-template-columns: minmax(0, 1fr) auto;
  }
  .history-row-change {
    grid-column: 2;
    font-size: 11px;
  }
}

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