:root {
  color-scheme: light;
  --bg: #f7f9fb;
  --surface: #ffffff;
  --ink: #17201c;
  --muted: #65716c;
  --line: #dfe7e2;
  --primary: #1f7a5a;
  --primary-strong: #145f45;
  --coral: #dd6b52;
  --gold: #d69f36;
  --shadow: 0 18px 50px rgba(25, 42, 35, 0.11);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(120deg, rgba(31, 122, 90, 0.12), transparent 32%),
    linear-gradient(280deg, rgba(221, 107, 82, 0.11), transparent 34%),
    var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  padding: 0 18px;
  background: var(--primary);
  color: #fff;
  font-weight: 760;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 160ms ease, background 160ms ease, box-shadow 160ms ease;
}

button:hover:not(:disabled) {
  background: var(--primary-strong);
  box-shadow: 0 10px 24px rgba(31, 122, 90, 0.18);
  transform: translateY(-1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(31, 122, 90, 0.12);
}

label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 720;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 32px 0 48px;
}

.hidden {
  display: none !important;
}

.login-view {
  min-height: calc(100vh - 80px);
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 420px);
  align-items: center;
  gap: 48px;
}

.login-copy h1,
.topbar h1 {
  margin: 0;
  font-size: clamp(42px, 7vw, 82px);
  line-height: 0.96;
  letter-spacing: 0;
}

.lead {
  max-width: 520px;
  margin: 22px 0 0;
  color: var(--muted);
  font-size: 20px;
  line-height: 1.65;
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--primary);
  font-size: 13px;
  font-weight: 820;
}

.login-panel,
.tool-panel,
.history-section {
  border: 1px solid rgba(31, 122, 90, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: var(--shadow);
}

.login-panel {
  padding: 28px;
}

.login-row,
.record-row,
.control-row {
  display: flex;
  gap: 10px;
}

.login-row input,
.record-row input {
  flex: 1 1 auto;
}

.record-row button {
  flex: 0 0 auto;
}

.form-message {
  min-height: 22px;
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.capture-message {
  margin-top: 10px;
}

.form-message.error {
  color: #ba392b;
}

.form-message.success {
  color: var(--primary-strong);
}

.dashboard {
  display: grid;
  gap: 22px;
}

.capture-view {
  display: grid;
  gap: 18px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding-top: 10px;
}

.topbar h1 {
  font-size: clamp(34px, 5vw, 58px);
}

.ghost-button,
.secondary-button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.ghost-button:hover:not(:disabled),
.secondary-button:hover:not(:disabled) {
  background: #f0f5f2;
  box-shadow: none;
}

.chart-section {
  min-width: 0;
}

.action-zone {
  padding: 0;
}

.primary-action-button {
  width: 100%;
  min-height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  border: 1px solid rgba(31, 122, 90, 0.15);
  background: rgba(255, 255, 255, 0.88);
  color: var(--ink);
  text-align: left;
  box-shadow: 0 12px 34px rgba(25, 42, 35, 0.08);
}

.primary-action-button:hover:not(:disabled) {
  background: #fff;
  color: var(--primary-strong);
  box-shadow: 0 14px 36px rgba(31, 122, 90, 0.13);
}

.primary-action-button > span:first-child {
  min-width: 0;
}

.action-label,
.action-meta {
  display: block;
}

.action-label {
  font-size: 18px;
  line-height: 1.2;
}

.action-meta {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
  line-height: 1.35;
  white-space: normal;
}

.action-plus {
  position: relative;
  flex: 0 0 34px;
  width: 34px;
  height: 34px;
  display: block;
  border: 1px solid rgba(31, 122, 90, 0.18);
  border-radius: 50%;
  background: #f3f8f5;
}

.action-plus::before,
.action-plus::after {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 14px;
  height: 2px;
  border-radius: 999px;
  background: var(--primary-strong);
  content: "";
  transform: translate(-50%, -50%);
}

.action-plus::after {
  transform: translate(-50%, -50%) rotate(90deg);
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.tool-panel,
.history-section {
  padding: 18px;
}

.panel-heading,
.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.panel-heading h2,
.section-heading h2 {
  margin: 0;
  font-size: 21px;
  line-height: 1.2;
}

.panel-heading p,
.section-heading span {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.compact-heading {
  margin-bottom: 10px;
}

.capture-flow {
  width: min(520px, 100%);
  margin: 0 auto;
}

.camera-stage,
.replay-stage {
  position: relative;
  width: 100%;
  overflow: hidden;
  margin-top: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #18221d;
}

.camera-stage {
  aspect-ratio: 3 / 4;
  cursor: pointer;
  margin-top: 0;
}

.camera-stage.is-active {
  cursor: default;
}

.replay-stage {
  aspect-ratio: 3 / 4;
  max-width: 520px;
  margin-left: auto;
  margin-right: auto;
}

.camera-stage video,
.camera-stage img,
.replay-stage img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.camera-stage video.mirrored {
  transform: scaleX(-1);
}

.camera-switch-button {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 8;
  min-height: 38px;
  border: 1px solid rgba(255, 255, 255, 0.56);
  background: rgba(10, 16, 14, 0.62);
  color: #fff;
  padding: 0 12px;
  backdrop-filter: blur(8px);
}

.camera-switch-button:hover:not(:disabled) {
  background: rgba(10, 16, 14, 0.78);
  box-shadow: none;
}

.camera-switch-button:disabled {
  display: none;
}

.empty-camera,
.replay-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: rgba(255, 255, 255, 0.72);
  font-weight: 820;
}

.empty-camera span {
  display: inline-grid;
  place-items: center;
  min-width: min(72%, 260px);
  min-height: 52px;
  padding: 0 18px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 8px;
  color: rgba(255, 255, 255, 0.42);
  letter-spacing: 0;
}

.control-row {
  margin-top: 12px;
}

.control-row button {
  flex: 1 1 0;
}

.record-form {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.capture-hint {
  min-height: 22px;
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.replay-stage {
  background: #101615;
}

.replay-stage img {
  opacity: 0;
  transition: opacity 180ms ease;
}

.replay-stage.has-image img {
  opacity: 1;
}

.replay-caption {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  min-height: 48px;
  border-radius: 8px;
  padding: 10px 12px;
  background: rgba(14, 20, 18, 0.74);
  color: #fff;
  font-weight: 720;
  display: none;
}

.replay-stage.has-image .replay-caption {
  display: block;
}

.weight-chart {
  min-height: 258px;
  border: 1px solid rgba(31, 122, 90, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 14px 38px rgba(25, 42, 35, 0.07);
  overflow: hidden;
}

.chart-frame {
  position: relative;
  padding-left: 48px;
}

.chart-scroll {
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  scrollbar-width: thin;
  scrollbar-color: #bccbc3 transparent;
}

.chart-y-axis {
  position: absolute;
  z-index: 2;
  top: 0;
  left: 0;
  bottom: 0;
  width: 48px;
  border-right: 1px solid rgba(223, 231, 226, 0.8);
  background: rgba(255, 255, 255, 0.94);
  color: var(--muted);
  pointer-events: none;
}

.chart-y-axis span {
  position: absolute;
  left: 9px;
  transform: translateY(-50%);
  font-size: 12px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.chart-scroll::-webkit-scrollbar {
  height: 6px;
}

.chart-scroll::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: #bccbc3;
}

.chart-scroll::-webkit-scrollbar-track {
  background: transparent;
}

.weight-chart svg {
  height: 258px;
  display: block;
  min-width: 100%;
}

.chart-day-label {
  fill: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.chart-weight-bar {
  transition: stroke 140ms ease, stroke-width 140ms ease, opacity 140ms ease;
}

.chart-hit-area {
  cursor: pointer;
  outline: none;
  pointer-events: fill;
}

.chart-hit-area:focus-visible {
  fill: rgba(214, 159, 54, 0.12);
}

.chart-detail {
  position: absolute;
  z-index: 4;
  top: 10px;
  left: calc(50% + 24px);
  transform: translateX(-50%);
  min-height: 40px;
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1px solid rgba(31, 122, 90, 0.14);
  border-radius: 8px;
  padding: 7px 11px;
  background: rgba(255, 255, 255, 0.94);
  color: var(--muted);
  box-shadow: 0 10px 28px rgba(25, 42, 35, 0.12);
  font-size: 12px;
  white-space: nowrap;
  pointer-events: none;
  backdrop-filter: blur(10px);
}

.chart-detail-date {
  color: var(--ink);
  font-weight: 780;
}

.chart-detail strong {
  color: var(--primary-strong);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.chart-empty {
  height: 210px;
  display: grid;
  place-items: center;
  color: var(--muted);
  text-align: center;
  padding: 24px;
}

.weight-chart .chart-empty {
  height: 258px;
}

.history-section {
  box-shadow: none;
}

.history-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.history-item {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr) auto auto;
  gap: 14px;
  align-items: center;
  min-height: 86px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.history-thumb {
  width: 72px;
  aspect-ratio: 3 / 4;
  height: auto;
  border-radius: 7px;
  background: #edf3ef;
  object-fit: cover;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
}

.history-time {
  margin: 0;
  font-weight: 780;
}

.history-note {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.history-weight {
  color: var(--primary-strong);
  font-size: 20px;
  font-weight: 820;
  white-space: nowrap;
}

.delete-record-button {
  min-height: 38px;
  border: 1px solid rgba(186, 57, 43, 0.22);
  background: #fff;
  color: #ba392b;
  padding: 0 12px;
}

.delete-record-button:hover:not(:disabled) {
  background: #fff1ef;
  box-shadow: none;
}

@media (max-width: 900px) {
  .login-view,
  .workspace-grid {
    grid-template-columns: 1fr;
  }

  .login-view {
    align-content: center;
    gap: 28px;
  }
}

@media (max-width: 620px) {
  .app-shell {
    width: min(100% - 22px, 1180px);
    padding: 18px 0 32px;
  }

  .topbar,
  .panel-heading,
  .section-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .login-row,
  .record-row {
    flex-direction: column;
  }

  .login-copy h1 {
    font-size: 46px;
  }

  .lead {
    font-size: 17px;
  }

  .chart-detail {
    left: calc(50% + 24px);
    gap: 8px;
    padding: 7px 9px;
  }

  .history-item {
    grid-template-columns: 66px minmax(0, 1fr);
  }

  .history-thumb {
    width: 66px;
    height: auto;
  }

  .history-weight {
    grid-column: 2;
    font-size: 18px;
  }

  .delete-record-button {
    grid-column: 1 / -1;
    width: 100%;
  }
}
