:root {
  --bg: #0f1a24; --panel: #16242f; --panel-2: #1d2f3d; --line: #2b4254;
  --text: #e8eef3; --muted: #9db0bf; --accent: #4cc3ff; --warn: #ffb84d; --bad: #ff6b6b; --good: #6fe3a1;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font-family: var(--font); font-size: 15px; line-height: 1.4; display: flex; flex-direction: column; height: 100vh; overflow: hidden; }
button { font: inherit; cursor: pointer; }
button:disabled { opacity: .45; cursor: not-allowed; }
a { color: var(--accent); }

header { display: flex; align-items: center; gap: 16px; padding: 10px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
header h1 { font-size: 18px; margin: 0; letter-spacing: .3px; }
header h1 small { color: var(--muted); font-weight: 400; margin-left: 8px; }
.stats { display: flex; gap: 10px; flex-wrap: wrap; margin-left: auto; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; min-width: 110px; }
.stat .k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.stat .v { font-size: 18px; font-weight: 600; }
.stat .v.bad { color: var(--bad); } .stat .v.good { color: var(--good); } .stat .v.warn { color: var(--warn); }
.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 7px 12px; }
.ghost:hover { border-color: var(--accent); }

main { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 12px; padding: 12px 16px; flex: 1; min-height: 0; }
main > * { min-width: 0; min-height: 0; }
#left { display: flex; flex-direction: column; gap: 10px; min-height: 0; }
#stage { position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; display: flex; justify-content: center; flex: 0 1 auto; min-height: 0; }
/* the canvas keeps its 2:1 shape and shrinks to fit whatever height is left */
#valley { display: block; width: auto; height: auto; max-width: 100%; max-height: calc(100vh - 262px); }
#tip { position: absolute; pointer-events: none; background: rgba(10,18,26,.92); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 13px; display: none; max-width: 240px; }
#tip b { display: block; margin-bottom: 2px; }
#legend { position: absolute; left: 10px; bottom: 8px; font-size: 12px; color: var(--muted); display: flex; gap: 14px; }
#legend span::before { content: ""; display: inline-block; width: 18px; height: 3px; margin-right: 6px; vertical-align: middle; border-radius: 2px; }
#legend .wt::before { background: #5fd0ff; } #legend .wt0::before { background: #fff; opacity: .7; border-top: 1px dashed #fff; height: 0; }
#legend .dry::before { background: var(--bad); }

aside { display: flex; flex-direction: column; gap: 10px; overflow-y: auto; min-height: 0; padding-right: 2px; scrollbar-width: thin; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.card h2 { font-size: 13px; margin: 0 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }
.year { font-size: 22px; font-weight: 700; }
.year small { font-size: 13px; color: var(--muted); font-weight: 400; margin-left: 6px; }
#rain { color: var(--muted); font-size: 13px; margin-top: 2px; }
#next { width: 100%; padding: 12px; font-size: 17px; font-weight: 700; border: 0; border-radius: 10px; background: var(--accent); color: #06202e; margin-top: 10px; }
#next:hover { filter: brightness(1.08); }
.row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 0; border-top: 1px solid var(--line); }
.row:first-of-type { border-top: 0; }
.row .n { font-size: 14px; min-width: 0; flex: 1; } .row .n small { display: block; color: var(--muted); font-size: 12px; }
.row select, .row button.act { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 6px 9px; font-size: 13px; }
.row button.act:hover:not(:disabled) { border-color: var(--accent); }
.row button.act.on { background: #0e4a63; border-color: var(--accent); }
.seg { display: flex; gap: 4px; }
.seg button { flex: 1; background: var(--panel-2); color: var(--text); border: 1px solid var(--line); padding: 6px 0; font-size: 13px; }
.seg button:first-child { border-radius: 8px 0 0 8px; } .seg button:last-child { border-radius: 0 8px 8px 0; }
.seg button.on { background: #0e4a63; border-color: var(--accent); }
#log { font-size: 12.5px; color: var(--muted); max-height: 150px; overflow-y: auto; white-space: pre-wrap; font-family: ui-monospace, Menlo, monospace; line-height: 1.5; }
#log .y { color: var(--text); }

#chartwrap { flex: 0 0 auto; }
#chart { width: 100%; height: 130px; display: block; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: none; align-items: center; justify-content: center; padding: 16px; z-index: 10; }
.modal.open { display: flex; }
.dialog { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; max-width: 560px; width: 100%; padding: 20px 22px; max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,.5); }
.dialog h3 { margin: 0 0 8px; font-size: 20px; }
.dialog .tag { display: inline-block; font-size: 11px; text-transform: uppercase; letter-spacing: .6px; padding: 2px 8px; border-radius: 99px; margin-bottom: 8px; background: var(--panel-2); color: var(--muted); }
.dialog .tag.bad { background: #4a1f1f; color: #ffb3b3; } .dialog .tag.warn { background: #4a3a1f; color: #ffd9a0; } .dialog .tag.good { background: #1f4a30; color: #b3ffcf; }
.dialog p { margin: 8px 0; }
.dialog .btns { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; flex-wrap: wrap; }
.dialog .btns button { border-radius: 8px; padding: 8px 14px; border: 1px solid var(--line); background: var(--panel-2); color: var(--text); }
.dialog .btns button.primary { background: var(--accent); color: #06202e; border-color: transparent; font-weight: 600; }
.dialog ul { padding-left: 20px; } .dialog li { margin: 4px 0; }
.dialog .src { font-size: 13.5px; }
.dialog .src li { margin: 8px 0; }
.dialog .note { color: var(--muted); font-size: 13px; }
.grade { font-size: 40px; letter-spacing: 4px; margin: 6px 0; }
kbd { background: var(--panel-2); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; font-size: 12px; }

@media (max-width: 900px) {
  body { height: auto; overflow: auto; display: block; }
  main { grid-template-columns: minmax(0, 1fr); }
  #left { position: sticky; top: 0; z-index: 5; background: var(--bg); padding-bottom: 6px; }
  #valley { max-height: 46vh; }
  #chart { height: 90px; }
  #legend { font-size: 10px; gap: 8px; white-space: nowrap; left: 6px; bottom: 4px; }
  #legend span::before { width: 12px; margin-right: 4px; }
  aside { overflow: visible; }
  .stat { min-width: 0; flex: 1; }
  .stats { margin-left: 0; }
}
