:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface2: #243044;
  --border: #2d3f56;
  --text: #e8edf4;
  --muted: #8b9cb3;
  --accent: #3d9eff;
  --accent-dim: #2a6db8;
  --green: #3dd68c;
  --red: #f07178;
  --gold: #ffc857;
  --health: #3dd68c;
  --health-low: #f07178;
  --font: "Noto Sans KR", sans-serif;
  --mono: "JetBrains Mono", monospace;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font);
  background: var(--bg);
  background-image:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(61, 158, 255, 0.12), transparent),
    radial-gradient(ellipse 60% 40% at 100% 100%, rgba(61, 214, 140, 0.06), transparent);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

.header {
  text-align: center;
  margin-bottom: 1.5rem;
}

.header h1 {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.subtitle {
  color: var(--muted);
  margin-top: 0.35rem;
  font-size: 0.95rem;
}

.subtitle strong {
  color: var(--gold);
}

.stats-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.65rem 0.85rem;
  margin-bottom: 1rem;
}

.stats-compact .stats-row-main {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.65rem;
}

.stats-compact .stats-row-status {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin-top: 0.45rem;
  padding-top: 0.45rem;
  border-top: 1px solid var(--border);
  min-height: 1.5rem;
}

.stats-compact .stats-row-status > .stat-label {
  flex-shrink: 0;
  font-size: 0.7rem;
  color: var(--muted);
  text-transform: uppercase;
}

.stat-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.8rem;
  white-space: nowrap;
}

.stat-pill strong {
  font-family: var(--mono);
  font-size: 0.95rem;
}

.stat-pill strong.money {
  color: var(--green);
}

.stat-pill strong.highlight {
  color: var(--gold);
}

.stat-pill-bar .mini-bar {
  width: 48px;
  height: 6px;
  background: var(--surface2);
  border-radius: 3px;
  overflow: hidden;
  display: inline-block;
  vertical-align: middle;
}

.stat-pill-bar .mini-bar span {
  display: block;
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s ease, background 0.35s ease;
}

.stat-pill-goal .mini-bar-goal {
  width: 56px;
}

.stat-pill strong.small {
  font-size: 0.8rem;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.stat-label {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat-value {
  font-family: var(--mono);
  font-size: 1.25rem;
  font-weight: 600;
}

.stat-value.money {
  color: var(--green);
  display: inline-block;
  transition: color 0.3s ease, transform 0.3s ease;
}

.stat-value.money.cash-animate-up,
.stat-pill strong.money.cash-animate-up {
  animation: cash-up 0.65s ease;
  color: #6effb8;
}

.stat-value.money.cash-animate-down,
.stat-pill strong.money.cash-animate-down {
  animation: cash-down 0.65s ease;
  color: #ff9aa0;
}

.stat-value.money.cash-animate-pulse,
.stat-pill strong.money.cash-animate-pulse {
  animation: cash-pulse 0.5s ease;
}

@keyframes cash-up {
  0% { transform: scale(1); }
  35% { transform: scale(1.12); }
  100% { transform: scale(1); }
}

@keyframes cash-down {
  0% { transform: scale(1); }
  35% { transform: scale(0.92); }
  100% { transform: scale(1); }
}

@keyframes cash-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.65; }
}

.stat-value.highlight {
  color: var(--gold);
  font-size: 1.4rem;
}

.stat-unit {
  font-size: 0.8rem;
  color: var(--muted);
}

.health-bar {
  background: linear-gradient(90deg, var(--health-low), var(--health));
}

.hunger-bar {
  background: linear-gradient(90deg, #8b9cb3, #c4a574);
}

.goal-bar {
  background: linear-gradient(90deg, var(--accent-dim), var(--gold));
  width: 0.1%;
  transition: width 0.3s ease;
}

.status-list {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.3rem;
  overflow-x: auto;
  flex: 1;
  min-width: 0;
  align-items: center;
  scrollbar-width: thin;
}

.status-none {
  font-size: 0.8rem;
  color: var(--muted);
}

.status-chip {
  font-size: 0.68rem;
  font-weight: 600;
  padding: 0.15rem 0.4rem;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  flex-shrink: 0;
  cursor: pointer;
}

.status-chip:hover {
  filter: brightness(1.1);
}

.event-popup-card.status-card {
  border-color: var(--accent);
}

.event-popup-card.status-card.debuff-card {
  border-color: var(--red);
}

.status-chip.buff {
  background: rgba(61, 214, 140, 0.18);
  color: var(--green);
  border: 1px solid rgba(61, 214, 140, 0.35);
}

.status-chip.debuff {
  background: rgba(240, 113, 120, 0.18);
  color: var(--red);
  border: 1px solid rgba(240, 113, 120, 0.35);
}

.health-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--health-low), var(--health));
  border-radius: 4px;
  transition: width 0.3s ease;
}

.stat-value.small {
  font-size: 0.85rem;
}

.life-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
}

.life-panel h2,
.stocks-panel h2,
.chart-panel h2,
.portfolio-panel h2 {
  font-size: 1rem;
  margin-bottom: 0.6rem;
  color: var(--muted);
}

.life-hint {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.75rem;
}

.life-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.btn {
  font-family: var(--font);
  font-size: 0.875rem;
  font-weight: 600;
  padding: 0.55rem 1rem;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.15s;
}

.btn:hover:not(:disabled) {
  transform: translateY(-1px);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-food {
  background: #3d5a3d;
  color: #c8e6c8;
}

.btn-health {
  background: #3d4a6a;
  color: #c8d4f0;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-next-day {
  margin-left: auto;
}

.btn-cost {
  font-weight: 400;
  opacity: 0.85;
  font-size: 0.8rem;
}

.news {
  font-size: 0.9rem;
  padding: 0.6rem 0.75rem;
  background: var(--surface2);
  border-radius: 8px;
  border-left: 3px solid var(--accent);
}

.event-banner {
  margin-top: 0.5rem;
  font-size: 0.88rem;
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  font-weight: 600;
}

.event-banner.hidden {
  display: none;
}

.event-banner.event-good {
  background: rgba(61, 214, 140, 0.15);
  border-left: 3px solid var(--green);
  color: var(--green);
}

.event-banner.event-bad {
  background: rgba(240, 113, 120, 0.15);
  border-left: 3px solid var(--red);
  color: var(--red);
}

.event-banner.event-neutral {
  background: rgba(61, 158, 255, 0.12);
  border-left: 3px solid var(--accent);
  color: var(--accent);
}

.event-popup {
  position: fixed;
  inset: 0;
  z-index: 150;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  animation: fade-in 0.2s ease;
}

.event-popup.hidden {
  display: none;
}

.event-popup-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1.5rem 1.75rem;
  max-width: 340px;
  width: 100%;
  text-align: center;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
}

.event-popup-image {
  font-size: 4.5rem;
  line-height: 1;
  margin-bottom: 0.75rem;
  min-height: 4.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.event-popup-image img {
  width: 88px;
  height: 88px;
  object-fit: contain;
}

.event-popup-title {
  font-size: 1.15rem;
  margin-bottom: 0.5rem;
}

.event-popup-desc {
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 1.25rem;
  line-height: 1.55;
}

.event-popup .btn-primary {
  width: 100%;
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.stock-card.delisted-flash {
  animation: flash-delist 0.6s ease;
}

@keyframes flash-delist {
  0%, 100% { border-color: var(--border); }
  50% { border-color: var(--red); box-shadow: 0 0 12px rgba(240, 113, 120, 0.4); }
}

.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  padding: 0.75rem 1.25rem;
  background: #2a1a1a;
  border: 1px solid var(--red);
  color: #ffc8c8;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 600;
  max-width: 90%;
  text-align: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  animation: toast-in 0.25s ease;
}

.toast.hidden {
  display: none;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

.stocks-panel.panel-disabled {
  position: relative;
}

.stocks-panel.panel-disabled::after {
  content: "거래 불가 (게임 종료)";
  position: absolute;
  inset: 0;
  background: rgba(15, 20, 25, 0.72);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: var(--muted);
  z-index: 5;
  pointer-events: none;
}

.trade-block {
  position: relative;
  display: flex;
  gap: 0.4rem;
  align-items: center;
  flex-wrap: wrap;
  padding: 0.35rem 0.4rem;
  border-radius: 8px;
  transition: opacity 0.2s;
}

.trade-block.trade-disabled {
  opacity: 0.38;
  pointer-events: none;
  filter: grayscale(0.4);
}

.trade-block.trade-disabled::after {
  content: attr(data-disabled-reason);
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--muted);
  background: rgba(15, 20, 25, 0.55);
  border-radius: 8px;
  text-align: center;
  padding: 0 0.25rem;
}

.chart-type-hint {
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--muted);
}

.main-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1rem;
}

@media (max-width: 800px) {
  .main-grid {
    grid-template-columns: 1fr;
  }
}

.stocks-panel,
.chart-panel,
.portfolio-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.25rem;
}

.stocks {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.stock-card {
  background: var(--surface2);
  border-radius: 10px;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
}

.stock-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 0.5rem;
}

.stock-name {
  font-weight: 700;
  font-size: 1rem;
}

.stock-desc {
  font-size: 0.75rem;
  color: var(--muted);
}

.stock-price {
  font-family: var(--mono);
  font-size: 1.15rem;
  font-weight: 600;
  text-align: right;
}

.stock-change {
  font-size: 0.8rem;
  font-family: var(--mono);
}

.stock-change.up {
  color: var(--green);
}

.stock-change.down {
  color: var(--red);
}

.stock-change.flat {
  color: var(--muted);
}

.stock-actions {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 0.5rem;
}

.stock-actions input {
  width: 64px;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.9rem;
}

.btn-buy {
  background: var(--green);
  color: #0a1a12;
  padding: 0.4rem 0.75rem;
  font-size: 0.8rem;
}

.btn-sell {
  background: var(--red);
  color: #1a0a0c;
  padding: 0.4rem 0.75rem;
  font-size: 0.8rem;
}

.btn-info {
  background: #4a3d6a;
  color: #e0d4ff;
  padding: 0.4rem 0.6rem;
  font-size: 0.75rem;
}

.stock-info-badge {
  font-size: 0.72rem;
  color: var(--accent);
  background: rgba(61, 158, 255, 0.12);
  border: 1px solid rgba(61, 158, 255, 0.35);
  border-radius: 6px;
  padding: 0.35rem 0.5rem;
  margin-top: 0.4rem;
  line-height: 1.4;
}

.stock-info-badge strong {
  color: var(--gold);
}

.chart-tabs {
  display: flex;
  gap: 0.35rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}

.chart-tab {
  padding: 0.35rem 0.7rem;
  font-size: 0.8rem;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--muted);
  border-radius: 6px;
  cursor: pointer;
  font-family: var(--font);
}

.chart-tab.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.chart-wrap {
  position: relative;
  height: 260px;
}

.chart-wrap canvas {
  width: 100% !important;
  height: 100% !important;
  display: block;
}

.chart-legend {
  margin-top: 0.5rem;
  font-size: 0.85rem;
  font-family: var(--mono);
  color: var(--muted);
}

.portfolio-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.portfolio-table th,
.portfolio-table td {
  padding: 0.5rem 0.6rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.portfolio-table th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.75rem;
}

.portfolio-table .empty {
  text-align: center;
  color: var(--muted);
  padding: 1rem;
}

.portfolio-table .profit {
  color: var(--green);
}

.portfolio-table .loss {
  color: var(--red);
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.overlay.hidden {
  display: none;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2rem;
  max-width: 360px;
  text-align: center;
}

.modal h2 {
  margin-bottom: 0.75rem;
  font-size: 1.5rem;
}

.modal p {
  color: var(--muted);
  margin-bottom: 1.25rem;
}

.modal .btn-primary {
  width: 100%;
  padding: 0.75rem;
}

.site-footer {
  position: fixed;
  right: 12px;
  bottom: 10px;
  z-index: 50;
  font-size: 0.72rem;
  color: var(--muted);
  opacity: 0.75;
  pointer-events: none;
  letter-spacing: 0.02em;
}

.stat-pill strong.loan-debt {
  color: var(--red);
  font-family: var(--mono);
}

.btn-loan {
  background: #5a4a2a;
  color: #ffe8b8;
  border: 1px solid #8a7040;
}

.btn-repay {
  background: #2a3d4a;
  color: #b8d4e8;
  border: 1px solid var(--border);
}

.event-popup-card.life-card {
  border-color: var(--green);
}

.event-popup-card.life-card.clinic-card {
  border-color: #7a9eff;
}

.gen-badge {
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--gold);
  vertical-align: middle;
}

.event-emoji {
  font-size: 4.5rem;
  line-height: 1;
  display: block;
}
