:root {
  --bg: #f5f2eb; --fg: #2a2520; --muted: #8a8278;
  --accent: #3d6b5e; --accent-light: #e8f0ec;
  --warn: #b85c38; --border: #d9d3c7; --card-bg: #fffdf8;
  --danger: #c0392b; --danger-light: #fdf0ef;
  --gold: #a68b2c;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: 'DM Mono', monospace; background: var(--bg); color: var(--fg);
  min-height: 100vh; padding: 2rem 1rem; line-height: 1.6;
}
.container { max-width: 700px; margin: 0 auto; }
header { text-align: center; margin-bottom: 2.5rem; padding-bottom: 2rem; border-bottom: 1px solid var(--border); }
h1 {
  font-family: 'Fraunces', serif; font-weight: 300; font-size: 2.4rem;
  letter-spacing: -0.02em; margin-bottom: 0.5rem;
}
.subtitle {
  color: var(--muted); font-size: 0.8rem; font-weight: 300;
  letter-spacing: 0.05em; text-transform: uppercase;
}

/* Loading */
.loading { text-align: center; padding: 3rem 0; }
.loading-dots { display: inline-flex; gap: 0.4rem; margin-bottom: 1rem; }
.loading-dots span {
  width: 6px; height: 6px; border-radius: 50%; background: var(--muted);
  animation: pulse 1.2s ease-in-out infinite;
}
.loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.loading-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes pulse {
  0%,100% { opacity:.3; transform:scale(.8); }
  50% { opacity:1; transform:scale(1.2); }
}
.loading-text { color: var(--muted); font-size: 0.8rem; font-weight: 300; }
.progress-bar {
  width: 100%; max-width: 200px; height: 3px; background: var(--border);
  border-radius: 2px; margin: 0.75rem auto 0; overflow: hidden;
}
.progress-fill {
  height: 100%; background: var(--accent); border-radius: 2px;
  transition: width 0.3s; width: 0%;
}

@keyframes fadeIn {
  from { opacity:0; transform:translateY(10px); }
  to { opacity:1; transform:translateY(0); }
}
@keyframes chipIn {
  from { opacity:0; transform:scale(.9); }
  to { opacity:1; transform:scale(1); }
}

/* Config toggle */
.config-toggle { text-align: center; margin-bottom: 2rem; }
.config-toggle-btn {
  font-family: 'DM Mono', monospace; font-size: 0.72rem;
  text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted);
  background: none; border: 1px solid var(--border); border-radius: 6px;
  padding: 0.45rem 1rem; cursor: pointer; transition: all 0.2s;
}
.config-toggle-btn:hover { border-color: var(--accent); color: var(--accent); }
.config-toggle-btn.open { background: var(--fg); color: var(--bg); border-color: var(--fg); }

/* Config panel */
.config-panel {
  display: none; margin-bottom: 2rem; padding: 1.5rem;
  background: var(--card-bg); border: 1px solid var(--border);
  border-radius: 10px; animation: slideDown 0.3s ease;
}
.config-panel.open { display: block; }
@keyframes slideDown {
  from { opacity:0; transform:translateY(-8px); }
  to { opacity:1; transform:translateY(0); }
}

.section-label {
  font-size: 0.68rem; text-transform: uppercase;
  letter-spacing: 0.1em; color: var(--muted); margin-bottom: 0.5rem;
}
.presets { margin-bottom: 1.25rem; }
.preset-btns { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.preset-btn {
  font-family: 'DM Mono', monospace; font-size: 0.68rem;
  padding: 0.35rem 0.65rem; background: var(--bg);
  border: 1px solid var(--border); border-radius: 5px;
  color: var(--fg); cursor: pointer; transition: all 0.15s;
}
.preset-btn:hover { border-color: var(--accent); background: var(--accent-light); }

.basket-section { margin-bottom: 1.25rem; }
.basket-items { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-bottom: 0.75rem; }
.basket-chip {
  display: inline-flex; align-items: center; gap: 0.3rem;
  background: var(--bg); border: 1px solid var(--border); border-radius: 5px;
  padding: 0.3rem 0.4rem 0.3rem 0.6rem; font-size: 0.75rem;
  font-family: 'DM Mono', monospace; font-weight: 500;
  animation: chipIn 0.2s ease;
}
.chip-region { font-size: 0.82rem; }
.chip-name { font-size: 0.62rem; color: var(--muted); font-weight: 300; }
.chip-remove {
  background: none; border: none; color: var(--muted); cursor: pointer;
  font-size: 0.95rem; line-height: 1; padding: 0 0.1rem; border-radius: 3px;
}
.chip-remove:hover { color: var(--danger); background: var(--danger-light); }

.add-row { display: flex; gap: 0.4rem; }
.add-input {
  flex: 1; font-family: 'DM Mono', monospace; font-size: 0.8rem;
  padding: 0.45rem 0.6rem; border: 1px solid var(--border); border-radius: 5px;
  background: var(--bg); color: var(--fg); outline: none; text-transform: uppercase;
}
.add-input:focus { border-color: var(--accent); }
.add-input::placeholder { color: var(--border); text-transform: none; }

.small-btn {
  font-family: 'DM Mono', monospace; font-size: 0.75rem;
  padding: 0.45rem 0.8rem; border: none; border-radius: 5px;
  cursor: pointer; white-space: nowrap;
}
.small-btn:hover { opacity: 0.85; }
.small-btn.dark { background: var(--fg); color: var(--bg); }
.small-btn.green { background: var(--accent); color: #fff; }

.basket-msg {
  font-size: 0.7rem; color: var(--muted); margin-top: 0.4rem;
  font-weight: 300; min-height: 1.1em;
}
.basket-msg.error { color: var(--danger); }

.share-section { margin-bottom: 1.25rem; }
.share-row { display: flex; gap: 0.4rem; }
.share-url {
  flex: 1; font-family: 'DM Mono', monospace; font-size: 0.68rem;
  padding: 0.45rem; border: 1px solid var(--border); border-radius: 4px;
  background: var(--bg); color: var(--muted); outline: none;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.config-apply { text-align: center; margin-top: 1rem; }

/* Nav */
.nav-links { display: flex; justify-content: center; gap: 1.5rem; margin-bottom: 2rem; }
.nav-links a {
  font-size: 0.72rem; color: var(--accent); text-decoration: underline;
  text-underline-offset: 3px;
}
.nav-links a:hover { opacity: 0.7; }
.back-link { display: block; text-align: center; margin-bottom: 2rem; }
.back-link a {
  font-size: 0.72rem; color: var(--accent); text-decoration: underline;
  text-underline-offset: 3px;
}

/* Recommendation */
.recommendation {
  background: var(--card-bg); border: 1px solid var(--border); border-radius: 12px;
  padding: 2rem; margin-bottom: 2rem; text-align: center;
  animation: fadeIn 0.6s ease;
}
.rec-label {
  font-size: 0.7rem; text-transform: uppercase;
  letter-spacing: 0.1em; color: var(--muted); margin-bottom: 1rem;
}
.rec-ticker {
  font-family: 'Fraunces', serif; font-size: 3rem;
  font-weight: 700; color: var(--accent); margin-bottom: 0.25rem;
}
.rec-name { font-size: 0.85rem; color: var(--muted); margin-bottom: 1.5rem; font-weight: 300; }
.rec-reason {
  font-size: 0.8rem; color: var(--fg); background: var(--accent-light);
  display: inline-block; padding: 0.5rem 1rem; border-radius: 6px;
}

/* Ranking */
.ranking { margin-bottom: 2rem; }
.ranking-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 1rem; cursor: pointer; user-select: none;
}
.ranking-title {
  font-size: 0.7rem; text-transform: uppercase;
  letter-spacing: 0.1em; color: var(--muted);
}
.ranking-toggle {
  font-size: 0.7rem; color: var(--muted); text-decoration: underline;
  text-underline-offset: 2px;
}
.ranking-list { display: none; }
.ranking-list.open { display: block; }
.rank-item {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.65rem 0.75rem; border-bottom: 1px solid var(--border);
  animation: fadeIn 0.4s ease both; font-size: 0.8rem;
}
.rank-item:last-child { border-bottom: none; }
.rank-item:first-child {
  background: var(--accent-light); border-radius: 6px;
  border-bottom: none; margin-bottom: 0.25rem;
}
.rank-num { font-size: 0.7rem; color: var(--muted); width: 1.5rem; text-align: right; flex-shrink: 0; }
.rank-ticker { font-weight: 500; width: 3.5rem; flex-shrink: 0; }
.rank-name {
  font-size: 0.7rem; color: var(--muted); font-weight: 300; flex: 1;
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.rank-bar-container {
  width: 50px; height: 4px; background: var(--border);
  border-radius: 2px; overflow: hidden; flex-shrink: 0;
}
.rank-bar { height: 100%; border-radius: 2px; transition: width 0.6s ease; }
.rank-bar.under { background: var(--accent); }
.rank-bar.over { background: var(--warn); }
.rank-score { font-size: 0.78rem; font-weight: 500; width: 3.5rem; text-align: right; flex-shrink: 0; }
.rank-score.negative { color: var(--accent); }
.rank-score.positive { color: var(--warn); }

/* Simulation results */
.result-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 2rem; }
.result-card {
  background: var(--card-bg); border: 1px solid var(--border); border-radius: 10px;
  padding: 1.5rem 1rem; text-align: center; animation: fadeIn 0.5s ease both;
}
.result-card.highlight { border-color: var(--accent); background: var(--accent-light); }
.rc-label {
  font-size: 0.65rem; text-transform: uppercase;
  letter-spacing: 0.1em; color: var(--muted); margin-bottom: 0.5rem;
}
.rc-value { font-family: 'Fraunces', serif; font-size: 2rem; font-weight: 700; }
.rc-value.green { color: var(--accent); }
.rc-value.orange { color: var(--warn); }
.rc-sub { font-size: 0.7rem; color: var(--muted); margin-top: 0.3rem; font-weight: 300; }

.comparison { margin-bottom: 2rem; }
.comp-label {
  font-size: 0.68rem; text-transform: uppercase;
  letter-spacing: 0.1em; color: var(--muted); margin-bottom: 0.75rem;
}
.comp-row { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 0.6rem; font-size: 0.8rem; }
.comp-name { width: 120px; flex-shrink: 0; font-weight: 400; font-size: 0.75rem; }
.comp-bar-wrap { flex: 1; height: 20px; background: var(--border); border-radius: 4px; overflow: hidden; }
.comp-bar { height: 100%; border-radius: 4px; transition: width 1s ease; min-width: 2px; }
.comp-bar.strat { background: var(--accent); }
.comp-bar.bench { background: var(--gold); }
.comp-bar.equal { background: var(--muted); }
.comp-val { width: 80px; text-align: right; font-weight: 500; font-size: 0.8rem; flex-shrink: 0; }

.alloc-section { margin-bottom: 2rem; }
.alloc-header {
  font-size: 0.68rem; text-transform: uppercase;
  letter-spacing: 0.1em; color: var(--muted); margin-bottom: 0.75rem;
}
.alloc-item {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.45rem 0; border-bottom: 1px solid var(--border); font-size: 0.78rem;
}
.alloc-item:last-child { border-bottom: none; }
.alloc-ticker { width: 40px; font-weight: 500; flex-shrink: 0; }
.alloc-region { width: 24px; flex-shrink: 0; }
.alloc-bar-wrap { flex: 1; height: 8px; background: var(--border); border-radius: 4px; overflow: hidden; }
.alloc-bar { height: 100%; background: var(--accent); border-radius: 4px; transition: width 0.8s ease; }
.alloc-pct { width: 40px; text-align: right; font-weight: 400; color: var(--muted); font-size: 0.72rem; flex-shrink: 0; }
.alloc-val { width: 70px; text-align: right; font-weight: 500; flex-shrink: 0; }

.log-section { margin-bottom: 2rem; }
.log-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 0.75rem; cursor: pointer; user-select: none;
}
.log-title {
  font-size: 0.68rem; text-transform: uppercase;
  letter-spacing: 0.1em; color: var(--muted);
}
.log-toggle {
  font-size: 0.68rem; color: var(--muted); text-decoration: underline;
  text-underline-offset: 2px;
}
.log-list { display: none; }
.log-list.open { display: block; }
.log-item {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--border);
  font-size: 0.72rem; animation: fadeIn 0.3s ease both;
}
.log-item:last-child { border-bottom: none; }
.log-date { width: 65px; color: var(--muted); font-weight: 300; flex-shrink: 0; }
.log-ticker { width: 40px; font-weight: 500; flex-shrink: 0; }
.log-region { width: 24px; text-align: center; flex-shrink: 0; }
.log-score { width: 50px; text-align: right; color: var(--accent); flex-shrink: 0; }
.log-amount { flex: 1; text-align: right; color: var(--muted); font-weight: 300; }

.sim-info { text-align: center; margin-bottom: 1.5rem; font-size: 0.72rem; color: var(--muted); font-weight: 300; }

/* Error */
.error-box { text-align: center; padding: 2rem; color: var(--warn); font-size: 0.85rem; }
.error-detail { color: var(--muted); font-size: 0.75rem; margin-top: 0.5rem; font-weight: 300; }
.retry-btn {
  margin-top: 1rem; font-family: 'DM Mono', monospace; font-size: 0.8rem;
  padding: 0.5rem 1.5rem; background: var(--fg); color: var(--bg);
  border: none; border-radius: 6px; cursor: pointer;
}
.retry-btn:hover { opacity: 0.85; }

/* Footer */
footer { text-align: center; padding-top: 2rem; border-top: 1px solid var(--border); margin-top: 2rem; }
.timestamp { font-size: 0.7rem; color: var(--muted); font-weight: 300; }
.methodology {
  margin-top: 1rem; font-size: 0.7rem; color: var(--muted);
  font-weight: 300; line-height: 1.8; cursor: pointer;
}
.methodology-detail {
  display: none; text-align: left; margin-top: 0.75rem; padding: 1rem;
  background: var(--card-bg); border-radius: 6px; border: 1px solid var(--border);
}
.methodology-detail.open { display: block; }
.disclaimer {
  margin-top: 1rem; font-size: 0.62rem; color: var(--muted);
  font-weight: 300; font-style: italic; line-height: 1.6;
  max-width: 480px; margin-left: auto; margin-right: auto;
}

@media (max-width: 480px) {
  h1 { font-size: 1.8rem; }
  .rec-ticker { font-size: 2.4rem; }
  .rank-name { display: none; }
  .result-grid { grid-template-columns: 1fr; }
  .rc-value { font-size: 1.6rem; }
  .comp-name { width: 80px; font-size: 0.68rem; }
  .log-score { display: none; }
}
