/* =============================================================================
 * KAI Sun Study — styles.
 * Design tokens copied VERBATIM from sibling financing-app/styles.css.
 * Same editorial KAI feel: warm cream paper, navy depth, bronze eyebrows,
 * rose for active/selection, water for secondary unit highlight.
 * ========================================================================== */

:root {
  --navy:        #10133F;
  --navy-2:      #30314A;
  --navy-soft:   #2a2d57;
  --bronze:      #A67B5D;
  --bronze-2:    #C5A996;
  --rose:        #BF125D;
  --cream:       #F0EDE6;
  --cream-deep:  #E7E2D6;
  --water:       #C6D6E2;
  --water-light: #F1F5F8;
  --white:       #FFFFFF;
  --ink:         #1b1c2a;
  --ink-soft:    #5b5c6e;

  --green:       #4f7a52;
  --amber:       #b07d2b;
  --red:         #b23a48;

  --serif: "Fraunces", Georgia, "Times New Roman", serif;
  --sans:  "Work Sans", system-ui, -apple-system, "Segoe UI", sans-serif;

  --rail:   360px;
  --gap:    28px;
  --radius: 4px;
  --shadow: 0 1px 2px rgba(16,19,63,.04), 0 8px 28px rgba(16,19,63,.06);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--sans);
  font-weight: 300;
  color: var(--ink);
  background: var(--cream);
  line-height: 1.5;
  letter-spacing: .01em;
  -webkit-font-smoothing: antialiased;
}

/* ---- shared editorial bits ------------------------------------------------ */
.eyebrow {
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--bronze);
}
h1, h2, h3 { font-family: var(--serif); font-weight: 300; color: var(--navy); margin: 0; }
.num { font-family: var(--serif); font-variant-numeric: tabular-nums lining-nums; }
a { color: var(--rose); text-decoration: none; }
a:hover { text-decoration: underline; }

/* =============================================================================
 * LAYOUT
 * ========================================================================== */
.app { display: grid; grid-template-columns: var(--rail) 1fr; min-height: 100vh; }

/* ---- input rail ----------------------------------------------------------- */
.rail {
  background: var(--navy);
  color: var(--cream);
  padding: 26px 22px 60px;
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  overflow-y: auto;
}
.rail::-webkit-scrollbar { width: 8px; }
.rail::-webkit-scrollbar-thumb { background: var(--navy-soft); border-radius: 8px; }

.rail .brand { display: flex; align-items: baseline; gap: 10px; margin-bottom: 4px; }
.rail .brand .wordmark { font-family: var(--serif); font-size: 30px; letter-spacing: .12em; color: var(--white); font-weight: 300; }
.rail .brand .sub { font-size: 9.5px; letter-spacing: .2em; text-transform: uppercase; color: var(--bronze-2); }
.rail .rail-title { font-size: 11px; color: var(--bronze-2); letter-spacing: .04em; margin-bottom: 22px; }

/* season presets */
.presets { display: flex; gap: 6px; margin-bottom: 14px; }
.presets button {
  flex: 1; padding: 9px 4px; cursor: pointer;
  background: transparent; color: var(--cream);
  border: 1px solid var(--navy-soft); border-radius: var(--radius);
  font-family: var(--sans); font-size: 10px; letter-spacing: .12em; text-transform: uppercase; font-weight: 400;
  transition: all .15s;
}
.presets button:hover { border-color: var(--bronze); color: var(--white); }
.presets button.active { background: var(--rose); border-color: var(--rose); color: var(--white); }

/* control groups */
.group { border-top: 1px solid var(--navy-soft); padding: 16px 0 6px; }
.group > .eyebrow { display: block; margin-bottom: 14px; color: var(--bronze); }

.ctl { margin-bottom: 15px; }
.ctl .ctl-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 5px; }
.ctl label { font-size: 12px; color: var(--cream); font-weight: 300; }
.ctl .val { font-family: var(--serif); font-size: 13px; color: var(--bronze-2); font-variant-numeric: tabular-nums; white-space: nowrap; }
.ctl .hint { font-size: 10px; color: #8a8ba6; margin-top: 3px; line-height: 1.35; }

input[type=range] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 2px; background: var(--navy-soft); border-radius: 2px; outline: none; cursor: pointer;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 13px; height: 13px; border-radius: 50%; background: var(--bronze);
  border: 2px solid var(--navy); cursor: pointer; transition: background .15s;
}
input[type=range]:hover::-webkit-slider-thumb { background: var(--rose); }

/* toggle switch */
.toggle { display: flex; align-items: center; justify-content: space-between; cursor: pointer; }
.toggle .sw { width: 36px; height: 20px; background: var(--navy-soft); border-radius: 20px; position: relative; transition: background .15s; flex: 0 0 auto; }
.toggle .sw::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--cream); transition: transform .15s; }
.toggle.on .sw { background: var(--rose); }
.toggle.on .sw::after { transform: translateX(16px); }

/* segmented unit toggle */
.seg { display: flex; gap: 0; border: 1px solid var(--navy-soft); border-radius: var(--radius); overflow: hidden; }
.seg button {
  flex: 1; padding: 8px 4px; cursor: pointer;
  background: transparent; color: var(--cream);
  border: none; border-right: 1px solid var(--navy-soft);
  font-family: var(--sans); font-size: 10px; letter-spacing: .08em; text-transform: uppercase;
  transition: all .15s;
}
.seg button:last-child { border-right: none; }
.seg button:hover { background: var(--navy-soft); }
.seg button.active { background: var(--rose); color: var(--white); }

/* play button */
.play-btn {
  width: 100%; padding: 9px; margin-top: 4px; cursor: pointer;
  background: transparent; color: var(--bronze-2);
  border: 1px solid var(--navy-soft); border-radius: var(--radius);
  font-family: var(--sans); font-size: 11px; letter-spacing: .12em; text-transform: uppercase;
  transition: all .15s;
}
.play-btn:hover { border-color: var(--bronze); color: var(--white); }
.play-btn.playing { background: var(--rose); border-color: var(--rose); color: var(--white); }

/* rail actions */
.rail-actions { display: flex; gap: 6px; margin-top: 18px; }
.rail-actions button {
  flex: 1; padding: 8px; cursor: pointer; background: transparent; color: var(--bronze-2);
  border: 1px solid var(--navy-soft); border-radius: var(--radius);
  font-family: var(--sans); font-size: 10px; letter-spacing: .1em; text-transform: uppercase;
}
.rail-actions button:hover { border-color: var(--bronze); color: var(--white); }

/* =============================================================================
 * CANVAS (results)
 * ========================================================================== */
.canvas { padding: 0 0 80px; }
.masthead { background: var(--navy); color: var(--cream); padding: 34px 48px 30px; }
.masthead .eyebrow { color: var(--bronze-2); }
.masthead h1 { color: var(--white); font-size: 34px; line-height: 1.1; margin: 8px 0 6px; font-weight: 300; }
.masthead p { max-width: 760px; color: var(--bronze-2); font-size: 13.5px; margin: 0; line-height: 1.55; }

.canvas-inner { padding: 0 48px; max-width: 1180px; }

/* placeholder/honesty warning */
.placeholder-banner {
  display: flex; gap: 12px; align-items: flex-start;
  background: var(--water-light); border: 1px solid var(--water);
  border-left: 3px solid var(--bronze);
  padding: 13px 16px; border-radius: var(--radius); margin: 24px 0 6px; font-size: 12.5px; color: var(--navy-2);
}
.placeholder-banner b { color: var(--navy); }

/* verdict / winner line */
.verdict { margin: 0; padding: 16px 20px; border-radius: var(--radius); border: 1px solid; display: flex; gap: 14px; align-items: center; box-shadow: var(--shadow); background: var(--white); }
.verdict .dot { width: 12px; height: 12px; border-radius: 50%; flex: 0 0 auto; background: var(--rose); box-shadow: 0 0 0 4px rgba(191,18,93,.15); }
.verdict .v-text { font-size: 13px; color: var(--navy); font-family: var(--serif); }
.verdict { border-color: rgba(191,18,93,.25); }

/* section heading */
.section { margin: 40px 0 0; }
.section-head { margin-bottom: 14px; }
.section-head h2 { font-size: 23px; }
.section-head .lead { font-size: 12.5px; color: var(--ink-soft); margin-top: 4px; max-width: 720px; }

/* metric cards */
.metrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.metric { background: var(--white); border: 1px solid var(--cream-deep); border-radius: var(--radius); padding: 16px 16px 14px; box-shadow: var(--shadow); }
.metric .m-label { font-size: 10.5px; letter-spacing: .12em; text-transform: uppercase; color: var(--bronze); margin-bottom: 8px; }
.metric .m-val { font-family: var(--serif); font-size: 24px; color: var(--navy); line-height: 1; font-variant-numeric: tabular-nums; }
.metric .m-val.sm { font-size: 18px; }
.metric .m-sub { font-size: 11px; color: var(--ink-soft); margin-top: 7px; line-height: 1.35; }
.metric.accent { background: var(--navy); border-color: var(--navy); }
.metric.accent .m-label { color: var(--bronze-2); }
.metric.accent .m-val { color: var(--white); }
.metric.accent .m-sub { color: var(--bronze-2); }
.metric.rose { background: var(--rose); border-color: var(--rose); }
.metric.rose .m-label { color: rgba(255,255,255,.7); }
.metric.rose .m-val { color: var(--white); }
.metric.rose .m-sub { color: rgba(255,255,255,.7); }

/* =============================================================================
 * 3-D SCENE CARD
 * ========================================================================== */
.scene-card {
  background: var(--white); border: 1px solid var(--cream-deep);
  border-radius: var(--radius); box-shadow: var(--shadow);
  overflow: hidden; position: relative;
}
#scene {
  width: 100%; height: 520px;
  background: #d8e4ea;
}
#scene > canvas:not(#overlay-compass) { display: block; width: 100% !important; height: 100% !important; }

/* HUD overlay */
.scene-hud {
  position: absolute; top: 12px; right: 14px;
  background: rgba(16,19,63,.75); backdrop-filter: blur(4px);
  border-radius: var(--radius); padding: 8px 12px;
  color: var(--bronze-2); font-size: 11px; font-family: var(--sans); letter-spacing: .04em;
  display: flex; flex-direction: column; gap: 4px;
  pointer-events: none;
}
.scene-hud span { color: var(--cream); }
.scene-hud span b { color: var(--bronze-2); font-weight: 400; font-size: 10px; }

/* heatmap legend (bottom-right of scene) */
.heat-legend {
  position: absolute; bottom: 12px; right: 14px;
  background: rgba(16,19,63,.78); backdrop-filter: blur(4px);
  border-radius: var(--radius); padding: 7px 10px;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  font-family: var(--sans); font-size: 9px; color: var(--cream);
  pointer-events: none; max-width: 360px;
}
.heat-legend .legend-title { color: var(--bronze-2); letter-spacing: .1em; text-transform: uppercase; font-size: 8.5px; margin-right: 2px; }
.heat-legend .legend-cell { display: inline-flex; align-items: center; gap: 3px; }
.heat-legend .legend-cell .sw { width: 14px; height: 9px; border-radius: 1px; display: inline-block; }
/* The minimap copy sits in .chart-card, which is NOT position:relative — an
 * absolute chip there escapes its card and floats at the page corner (was seen
 * as a duplicated legend). Render it in-flow under the canvas instead. */
#minimap-heat-legend { position: static; display: inline-flex; margin-top: 10px; }

/* facade-sun breakdown rows inside Apartment-light metric cards */
.f-rows { margin-top: 10px; display: flex; flex-direction: column; gap: 4px; }
.f-row  { display: flex; align-items: center; gap: 7px; font-size: 11px; }
.f-dot  { width: 10px; height: 10px; border-radius: 2px; flex: none; }
.f-name { flex: 1; opacity: 0.85; }
.f-val  { font-variant-numeric: tabular-nums; }
.metric.accent .f-row { color: rgba(240,237,230,0.88); }  /* readable on the dark card */

/* =============================================================================
 * MINIMAP / CHART CARD
 * ========================================================================== */
.chart-card {
  background: var(--white); border: 1px solid var(--cream-deep);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px 14px;
}
#minimap { display: block; width: 100%; height: auto; max-width: 700px; }
.minimap-legend {
  display: flex; gap: 18px; flex-wrap: wrap; margin-top: 10px; font-size: 11px; color: var(--ink-soft);
}
.minimap-legend span { display: inline-flex; align-items: center; gap: 6px; }
.minimap-legend .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; }

/* =============================================================================
 * RESPONSIVE
 * ========================================================================== */
@media (max-width: 1080px) {
  .app { grid-template-columns: 1fr; }
  .rail { position: static; height: auto; }
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .canvas-inner, .masthead { padding-left: 24px; padding-right: 24px; }
  #scene { height: 380px; }
}
