:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #6f6d68;
  --axis-text: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --wash: rgba(11, 11, 11, 0.05);
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --danger: #c22f2f;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --radius: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #a3a29b;
    --axis-text: #898781;
    --grid: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --wash: rgba(255, 255, 255, 0.07);
    --accent: #3987e5;
    --danger: #e66767;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
  }
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Yu Gothic UI", Meiryo, sans-serif;
  font-size: 16px;
  line-height: 1.6;
}

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

h1 {
  font-size: 1.125rem;
}

h2 {
  font-size: 1.0625rem;
}

.muted {
  color: var(--text-muted);
}

.small {
  font-size: 0.8125rem;
}

.error {
  color: var(--danger);
  font-size: 0.875rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

/* ---------- ボタン・入力 ---------- */

.button {
  appearance: none;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text-primary);
  font: inherit;
  font-weight: 600;
  min-height: 44px;
  padding: 8px 16px;
  cursor: pointer;
}

.button.primary {
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-ink);
  width: 100%;
}

.button.ghost {
  background: transparent;
}

.button.small {
  min-height: 36px;
  padding: 4px 12px;
  font-size: 0.8125rem;
  font-weight: 500;
}

.button.danger {
  color: var(--danger);
}

.button:hover {
  filter: brightness(0.96);
}

.button:disabled {
  opacity: 0.6;
  cursor: default;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.field {
  display: block;
  margin: 16px 0;
}

.field > span {
  display: block;
  font-weight: 600;
  font-size: 0.9375rem;
  margin-bottom: 6px;
}

.field small {
  font-weight: 400;
  margin-left: 6px;
}

input[type="password"],
textarea {
  width: 100%;
  border: 1px solid var(--baseline);
  border-radius: 10px;
  background: var(--page);
  color: var(--text-primary);
  font: inherit;
  padding: 10px 12px;
}

textarea {
  resize: vertical;
  min-height: 96px;
}

/* ---------- ログイン ---------- */

.login {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 16px;
}

.login-card {
  width: 100%;
  max-width: 360px;
  padding: 24px;
}

.login-card h1 {
  font-size: 1.375rem;
  margin-bottom: 4px;
}

.login-card .error {
  margin-bottom: 12px;
}

/* ---------- ヘッダー・タブ ---------- */

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--page);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}

.app-header-inner,
.tabs,
.screen {
  max-width: 760px;
  margin: 0 auto;
  padding-left: 16px;
  padding-right: 16px;
}

.app-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 10px;
  padding-bottom: 6px;
}

.tabs {
  display: flex;
  gap: 4px;
}

.tab {
  appearance: none;
  flex: 1;
  border: 0;
  border-bottom: 3px solid transparent;
  background: none;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  min-height: 44px;
  padding: 6px 4px;
  cursor: pointer;
}

.tab[aria-selected="true"] {
  color: var(--text-primary);
  border-bottom-color: var(--accent);
}

.screen {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  padding-top: 16px;
  padding-bottom: calc(32px + env(safe-area-inset-bottom));
}

/* ---------- グラフ ---------- */

.chart-head {
  align-items: center;
  flex-wrap: nowrap;
  margin-bottom: 4px;
}

.chart-subtitle {
  margin-bottom: 12px;
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 2px;
  background: var(--page);
}

.segmented button {
  appearance: none;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--text-secondary);
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  min-width: 48px;
  min-height: 36px;
  cursor: pointer;
}

.segmented button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--text-primary);
  box-shadow: 0 0 0 1px var(--border);
}

.legend {
  list-style: none;
  margin: 0 0 8px;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

.legend li,
.tooltip-row,
.score-chip {
  display: flex;
  align-items: center;
  gap: 6px;
}

.swatch {
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 3px;
}

.chart {
  position: relative;
  display: flex;
}

.chart-axis {
  flex: none;
}

.chart-scroll {
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
}

.chart svg {
  display: block;
}

.chart text {
  fill: var(--axis-text);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.chart .gridline {
  stroke: var(--grid);
  stroke-width: 1;
}

.chart .baseline {
  stroke: var(--baseline);
  stroke-width: 1;
}

.chart .hit {
  fill: transparent;
  cursor: pointer;
}

.chart .slot.active .hit {
  fill: var(--wash);
}

.tooltip {
  position: absolute;
  top: 4px;
  z-index: 2;
  min-width: 190px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.16);
  padding: 10px 12px;
  font-size: 0.8125rem;
  pointer-events: none;
}

.tooltip-title {
  font-weight: 600;
  margin-bottom: 4px;
}

.tooltip-row {
  color: var(--text-secondary);
}

.tooltip-row b,
.tooltip-total b {
  margin-left: auto;
  padding-left: 12px;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.tooltip-total {
  display: flex;
  border-top: 1px solid var(--grid);
  margin-top: 6px;
  padding-top: 6px;
  color: var(--text-secondary);
}

.empty {
  text-align: center;
  color: var(--text-muted);
  padding: 32px 8px;
}

/* ---------- 評価フォーム ---------- */

.metric {
  border: 0;
  border-top: 1px solid var(--grid);
  margin: 0;
  padding: 14px 0;
  min-width: 0;
}

.metric legend {
  /* float させると legend が枠線上ではなく fieldset の中に入る */
  float: left;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0;
  font-weight: 600;
  font-size: 0.9375rem;
}

.metric-desc {
  clear: both;
  color: var(--text-secondary);
  font-size: 0.8125rem;
  padding: 2px 0 10px;
}

.score-options {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.score-options label {
  position: relative;
  display: block;
}

.score-options input {
  position: absolute;
  inset: 0;
  opacity: 0;
  margin: 0;
  cursor: pointer;
}

.score-options span {
  display: grid;
  place-items: center;
  min-height: 46px;
  border: 1px solid var(--baseline);
  border-radius: 10px;
  background: var(--page);
  font-weight: 600;
  font-size: 1.0625rem;
}

.score-options input:checked + span {
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-ink);
}

.score-options input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.score-guide {
  display: grid;
  gap: 2px;
  margin-top: 8px;
  color: var(--text-muted);
  font-size: 0.75rem;
  line-height: 1.5;
}

/* ---------- 記録一覧 ---------- */

.list-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

.record-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 12px;
}

.record-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.record-head time {
  font-weight: 600;
}

.record-scores {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 4px 16px;
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.score-chip b {
  margin-left: auto;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.record-total {
  margin-top: 8px;
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.record-total b {
  color: var(--text-primary);
}

.record-memo {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--grid);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 0.9375rem;
}

/* ---------- トースト ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 20;
  background: var(--text-primary);
  color: var(--page);
  border-radius: 999px;
  padding: 8px 18px;
  font-size: 0.875rem;
  font-weight: 600;
  white-space: nowrap;
}
