:root {
  --bg: #f6f3ec;
  --panel: #ffffff;
  --ink: #18212f;
  --muted: #697386;
  --line: #d9dee8;
  --blue: #1769aa;
  --green: #1f8f62;
  --yellow: #f3c443;
  --red: #d35c45;
  --shadow: 0 12px 30px rgba(24, 33, 47, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
  overflow-x: clip;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
  padding: 24px;
  background: #e9f0f7;
  border-right: 1px solid var(--line);
}

.brand {
  display: grid;
  grid-template-columns: 56px 1fr;
  gap: 12px;
  align-items: center;
}

.brand svg,
.empty-state svg,
.game-strip svg {
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 5;
}

.brand svg {
  color: var(--blue);
  background: #fff7da;
  border-radius: 8px;
  padding: 8px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 1.35rem;
}

h2 {
  font-size: 1.1rem;
}

h3 {
  font-size: 1rem;
}

.brand p,
label,
.panel-heading span,
.profile p,
.metric span,
.window-card span,
#goal-copy,
.feedback,
#quiz-score {
  color: var(--muted);
  font-size: 0.9rem;
}

.panel {
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 16px;
}

form {
  display: grid;
  gap: 12px;
}

label {
  display: grid;
  gap: 6px;
  font-weight: 700;
}

input,
select {
  width: 100%;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  padding: 10px 12px;
}

.stock-helper {
  display: grid;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f9fbfd;
  padding: 10px;
}

.stock-helper div {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.stock-helper span,
.stock-helper p {
  color: var(--muted);
  font-size: 0.86rem;
}

input:focus,
select:focus,
button:focus-visible {
  outline: 3px solid rgba(23, 105, 170, 0.28);
  outline-offset: 2px;
}

.primary {
  border: 0;
  border-radius: 6px;
  background: var(--blue);
  color: white;
  font-weight: 800;
  padding: 11px 14px;
}

.danger {
  background: var(--red);
}

.link-button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  color: var(--blue);
  font-weight: 800;
  padding: 7px 10px;
}

.avatar-picker,
.segmented,
.answers {
  display: flex;
  gap: 8px;
}

.avatar,
.segmented button,
.answers button {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 6px;
  min-height: 42px;
}

.avatar {
  display: grid;
  place-items: center;
  width: 48px;
}

.avatar.active,
.segmented button.active {
  border-color: var(--blue);
  background: #e8f3fb;
}

.coin-icon,
.star-icon,
.rocket-icon {
  display: block;
  width: 24px;
  height: 24px;
}

.coin-icon {
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff7a7 0 16%, var(--yellow) 17% 100%);
  border: 2px solid #a27500;
}

.star-icon {
  background: var(--yellow);
  clip-path: polygon(50% 0, 61% 34%, 98% 34%, 68% 55%, 79% 91%, 50% 69%, 21% 91%, 32% 55%, 2% 34%, 39% 34%);
}

.rocket-icon {
  background: linear-gradient(135deg, var(--red) 0 45%, #fff 46% 62%, var(--blue) 63% 100%);
  clip-path: polygon(50% 0, 78% 22%, 88% 76%, 58% 64%, 42% 64%, 12% 76%, 22% 22%);
}

.children-list {
  display: grid;
  gap: 8px;
}

.child-card {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) max-content;
  gap: 12px;
  align-items: center;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  padding: 9px;
  text-align: left;
}

.child-card-avatar {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: #fff7da;
}

.child-card-avatar > span {
  width: 24px;
  height: 24px;
}

.child-card-copy {
  display: grid;
  gap: 5px;
  min-width: 0;
  line-height: 1.12;
}

.child-card-copy strong,
.child-card-copy small {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.child-card-copy small {
  color: var(--muted);
}

.child-card-balance {
  justify-self: end;
  white-space: nowrap;
}

.child-card.active {
  border-color: var(--blue);
  background: #f0f7fc;
}

.workspace {
  min-width: 0;
  padding: 28px;
}

.empty-state {
  display: grid;
  min-height: calc(100vh - 56px);
  place-content: center;
  justify-items: center;
  gap: 16px;
  color: var(--muted);
  text-align: center;
}

.empty-state svg {
  width: min(320px, 70vw);
  color: var(--green);
}

.hidden {
  display: none !important;
}

.dashboard {
  display: grid;
  gap: 18px;
  min-width: 0;
}

.topbar,
.game-strip,
.grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, auto);
  gap: 18px;
  align-items: stretch;
  min-width: 0;
}

.profile,
.game-strip {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.profile {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
  padding: 16px;
}

.profile-avatar {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border-radius: 8px;
  background: #fff7da;
}

.profile-avatar > span {
  width: 30px;
  height: 30px;
}

.window-card {
  display: grid;
  align-content: center;
  min-width: 0;
  padding: 16px;
  border-radius: 8px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  background: var(--panel);
}

.window-card strong {
  font-size: 1.55rem;
}

.window-card.open {
  border-color: rgba(31, 143, 98, 0.45);
  background: #e8f7ef;
}

.window-card.closed {
  border-color: rgba(211, 92, 69, 0.4);
  background: #fff0ed;
}

.portfolio-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  min-width: 0;
}

.metric {
  display: grid;
  gap: 5px;
  min-height: 126px;
  align-content: center;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  min-width: 0;
}

.metric strong {
  font-size: 1.25rem;
  min-width: 0;
  overflow-wrap: anywhere;
}

.metric small {
  color: var(--muted);
  font-size: 0.86rem;
  min-width: 0;
  overflow-wrap: anywhere;
}

.metric em {
  font-style: normal;
  font-weight: 900;
  min-width: 0;
  overflow-wrap: anywhere;
}

.yield-positive {
  color: var(--green);
}

.yield-negative {
  color: var(--red);
}

.yield-neutral,
.yield-range {
  color: var(--muted);
}

.explain-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px;
  min-width: 0;
}

.explain {
  display: grid;
  gap: 8px;
  min-height: 148px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.explain p {
  color: var(--muted);
  line-height: 1.4;
  font-size: 0.92rem;
}

.explain.bank {
  border-top: 4px solid var(--red);
}

.explain.fixed {
  border-top: 4px solid var(--green);
}

.explain.stock {
  border-top: 4px solid var(--blue);
}

.explain.deposit {
  border-top: 4px solid var(--yellow);
}

.grid {
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  min-width: 0;
}

.segmented button {
  flex: 1;
  font-weight: 800;
  padding: 9px 8px;
}

.panel-heading {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
}

.switch {
  display: inline-flex;
  width: 48px;
  height: 28px;
  padding: 0;
}

.switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch span {
  position: relative;
  display: block;
  width: 48px;
  height: 28px;
  border-radius: 999px;
  background: #c9d1dc;
  transition: background 160ms ease;
}

.switch span::after {
  position: absolute;
  top: 4px;
  left: 4px;
  width: 20px;
  height: 20px;
  content: "";
  border-radius: 50%;
  background: white;
  box-shadow: 0 2px 5px rgba(24, 33, 47, 0.25);
  transition: transform 160ms ease;
}

.switch input:checked + span {
  background: var(--green);
}

.switch input:checked + span::after {
  transform: translateX(20px);
}

.history {
  display: grid;
  gap: 8px;
}

.week-card {
  display: grid;
  gap: 10px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.week-card:first-child {
  border-top: 0;
  padding-top: 0;
}

.week-card-head,
.week-ending {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
}

.week-breakdown {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  color: var(--muted);
  font-size: 0.86rem;
}

.week-breakdown span {
  min-width: 0;
}

.week-ending {
  border-radius: 6px;
  background: #f4f7fa;
  padding: 8px 10px;
}

.history-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) max-content;
  gap: 12px;
  align-items: center;
  border-top: 1px solid var(--line);
  padding-top: 9px;
}

.history-row > span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.history-row:first-child {
  border-top: 0;
  padding-top: 0;
}

.amount-positive {
  color: var(--green);
  font-weight: 800;
}

.amount-negative {
  color: var(--red);
  font-weight: 800;
}

@media (max-width: 860px) {
  .app-shell,
  .topbar,
  .game-strip,
  .grid,
  .portfolio-grid,
  .explain-grid {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .workspace {
    padding: 18px;
  }

  .game-strip svg {
    justify-self: center;
  }

  .week-breakdown {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 1120px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
}
