:root {
  color-scheme: dark;
  --border: #4a4a4a;
  --text: #e8e8e8;
  --muted: #aaa;
  --blue: #286fa8;
  --green: #62b879;
  --red: #e47770;
}

* { box-sizing: border-box; }

html, body { min-width: 320px; min-height: 100%; }

body {
  margin: 0;
  color: var(--text);
  background: #181818;
  font: 15px/1.4 Arial, Helvetica, sans-serif;
}

button, input { font: inherit; }
[hidden] { display: none !important; }

.app-shell { display: flex; flex-direction: column; min-height: 100vh; }
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  height: 54px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  background: #222;
}
.brand-area { display: flex; align-items: center; gap: 8px; }
.brand { font-size: 1rem; font-weight: bold; white-space: nowrap; }
.brand > span { display: none; }
.help-wrap { position: relative; }
.help-button {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 1px solid #777;
  border-radius: 50%;
  color: #ddd;
  background: #333;
  font-size: 0.82rem;
  font-weight: bold;
  cursor: pointer;
}
.help-button:hover { color: white; border-color: #aaa; background: #444; }
.help-nudge {
  position: absolute;
  z-index: 120;
  top: 34px;
  left: -10px;
  width: max-content;
  padding: 8px 11px;
  border: 1px solid #8aa1b5;
  border-radius: 11px;
  color: #17202a;
  background: #eaf2f8;
  font-size: 0.8rem;
  font-weight: normal;
  white-space: nowrap;
}
.help-nudge::before {
  content: "";
  position: absolute;
  top: -7px;
  left: 18px;
  width: 12px;
  height: 12px;
  transform: rotate(45deg);
  border-top: 1px solid #8aa1b5;
  border-left: 1px solid #8aa1b5;
  background: #eaf2f8;
}
.toolbar-actions { display: flex; align-items: center; gap: 12px; min-width: 0; }
.file-name { max-width: 35vw; overflow: hidden; color: var(--muted); font-size: 0.85rem; text-overflow: ellipsis; white-space: nowrap; }
#csv-file { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.upload-button {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  border: 1px solid #4d8cbd;
  border-radius: 3px;
  color: white;
  background: var(--blue);
  font-size: 0.86rem;
  font-weight: bold;
  cursor: pointer;
}
.upload-button:hover { background: #337fb9; }

.plot-panel { position: relative; flex: 1; min-height: 0; padding: 8px; }
.plot-wrap {
  position: relative;
  width: 100%;
  height: calc(100vh - 70px);
  min-height: 480px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: #222;
}
.weight-plot { width: 100%; height: 100%; }
.empty-state { position: absolute; inset: 0; display: grid; place-content: center; gap: 3px; color: var(--muted); text-align: center; pointer-events: none; }
.empty-state strong { color: var(--text); font-size: 1rem; }

.chart-overlay {
  position: absolute;
  z-index: 20;
  max-width: min(360px, calc(100% - 32px));
  border: 1px solid #666;
  border-radius: 3px;
  background: #292929;
}
.corner-top-left { top: 62px; left: 72px; right: auto; bottom: auto; }
.corner-top-right { top: 62px; right: 18px; left: auto; bottom: auto; }
.corner-bottom-left { bottom: 54px; left: 72px; right: auto; top: auto; }
.corner-bottom-right { right: 18px; bottom: 54px; left: auto; top: auto; }

.next-point-prompt {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 2px 10px;
  padding: 11px 13px;
  color: #f3e7b0;
  background: #3b351e;
  border-color: #9b8434;
  pointer-events: none;
}
.next-point-prompt div { display: flex; gap: 7px; }
.next-point-prompt div span { color: #d4c681; }
.next-point-prompt > b { grid-column: 2; font-size: 0.84rem; }
.prompt-dot { grid-row: 1 / 3; width: 9px; height: 9px; border-radius: 50%; background: #b89600; }

.weekly-hover-card {
  display: flex;
  flex-direction: column;
  width: 190px;
  padding: 10px 12px;
  border-color: #777;
  pointer-events: none;
  transition: none;
}
.weekly-hover-card > span { color: var(--muted); font-size: 0.66rem; font-weight: bold; letter-spacing: 0.08em; }
.weekly-hover-card > strong { margin: 1px 0 2px; font-size: 1.3rem; }
.weekly-hover-card > small { color: #bbb; font-size: 0.76rem; }

.trend-card { width: 340px; padding: 13px 14px 14px; border-color: #777; }
.close-button {
  position: absolute;
  top: 7px;
  right: 7px;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 2px;
  color: #bbb;
  background: transparent;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
}
.close-button:hover { border-color: #777; background: #3b3b3b; }
.trend-label { display: block; margin-bottom: 1px; color: var(--muted); font-size: 0.68rem; font-weight: bold; letter-spacing: 0.08em; }
.trend-change { display: block; font-size: 1.75rem; line-height: 1.15; }
.trend-change.down { color: var(--green); }
.trend-change.up { color: var(--red); }
.trend-range { display: block; margin-top: 2px; color: var(--muted); font-size: 0.8rem; }
.trend-details { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 11px; padding-top: 10px; border-top: 1px solid #555; }
.trend-details span { display: flex; flex-direction: column; min-width: 0; }
.trend-details small { color: var(--muted); font-size: 0.69rem; }
.trend-details b { margin-top: 2px; font-size: 0.8rem; white-space: nowrap; }

.toast {
  position: absolute;
  z-index: 30;
  right: 20px;
  bottom: 20px;
  max-width: min(500px, calc(100% - 40px));
  padding: 9px 12px;
  border: 1px solid;
  border-radius: 3px;
  background: #292929;
  font-size: 0.84rem;
}
.error-message { color: #ffc4c0; border-color: #a75555; background: #422525; }
.warning-message { color: #f0dfa5; border-color: #8f7b3b; background: #39331f; }

.tutorial-card {
  position: fixed;
  z-index: 110;
  top: 50%;
  left: 50%;
  display: flex;
  flex-direction: column;
  width: min(360px, calc(100% - 32px));
  padding: 16px 18px;
  transform: translate(-50%, -50%);
  border: 1px solid #888;
  border-radius: 8px;
  color: #17202a;
  background: #eaf2f8;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.45);
  pointer-events: none;
}
.tutorial-card.plot-step {
  top: 78px;
  left: 105px;
  width: 290px;
  transform: none;
}
.tutorial-card small { margin-bottom: 5px; color: #526270; font-size: 0.7rem; font-weight: bold; letter-spacing: 0.08em; }
.tutorial-card strong { font-size: 1.1rem; }
.tutorial-card span { margin-top: 10px; color: #526270; font-size: 0.8rem; }
.tutorial-card.upload-step {
  top: 64px;
  right: 12px;
  left: auto;
  width: 275px;
  transform: none;
}
.tutorial-click-layer { position: fixed; z-index: 100; inset: 0; cursor: pointer; }
.tutorial-active .upload-button { position: relative; z-index: 120; }
.tutorial-pointer {
  position: fixed;
  z-index: 108;
  height: 2px;
  transform-origin: left center;
  background: #dcecff;
  pointer-events: none;
  transition: left 180ms linear, top 180ms linear, transform 180ms ease-out;
  will-change: left, top, transform;
}
.tutorial-pointer::after {
  content: "";
  position: absolute;
  top: -4px;
  right: -1px;
  width: 0;
  height: 0;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  border-left: 9px solid #dcecff;
}

@media (max-width: 600px) {
  .toolbar { height: 50px; padding: 0 10px; }
  .file-name { display: none; }
  .plot-panel { padding: 4px; }
  .plot-wrap { height: calc(100vh - 58px); min-height: 420px; }
  .corner-top-left, .corner-top-right { top: 56px; }
  .corner-bottom-left, .corner-bottom-right { bottom: 46px; }
  .corner-top-left, .corner-bottom-left { left: 10px; }
  .corner-top-right, .corner-bottom-right { right: 10px; }
  .trend-card { width: min(340px, calc(100% - 20px)); }
  .tutorial-card.upload-step { top: 60px; right: 8px; }
  .tutorial-card.plot-step { top: 68px; left: 72px; width: min(290px, calc(100% - 84px)); }
}
