:root {
  color-scheme: dark;
  --bg: #0b0d10;
  --sidebar: #101419;
  --surface: #151a20;
  --surface-2: #1a2027;
  --surface-3: #202831;
  --line: #2b3540;
  --line-strong: #3b4652;
  --text: #f4f7fa;
  --muted: #aab5c1;
  --faint: #74808d;
  --accent: #32d08b;
  --accent-strong: #47e69d;
  --accent-weak: rgba(50, 208, 139, 0.14);
  --on-accent: #07140d;
  --danger: #ff7a8a;
  --ok: #47e69d;
  --shadow: 0 18px 42px rgba(0, 0, 0, 0.26);
  --radius: 14px;
  --tap: 48px;
}

* { box-sizing: border-box; }

html { background: var(--bg); }

body {
  min-width: 0;
  min-height: 100vh;
  margin: 0;
  overflow-x: clip;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Hiragino Sans", "Yu Gothic", "Noto Sans JP", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid rgba(71, 230, 157, .56); outline-offset: 2px; }
svg { display: block; }

.app-shell { min-height: 100vh; padding: 0 16px calc(92px + env(safe-area-inset-bottom)); }
.desktop-sidebar { display: none; }

.top-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: var(--tap) minmax(0, 1fr) var(--tap);
  align-items: center;
  gap: 10px;
  min-height: 72px;
  margin: 0 -16px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(11, 13, 16, .94);
  backdrop-filter: blur(14px);
}

.top-bar h1 { margin: 0; color: var(--text); font-size: 1rem; font-weight: 800; line-height: 1.15; text-align: center; }
.today-label, .eyebrow, .record-hero-copy p { margin: 0 0 3px; color: var(--muted); font-size: .68rem; font-weight: 700; letter-spacing: .04em; }
.today-label { text-align: center; }

.icon-button {
  display: inline-grid;
  width: var(--tap);
  height: var(--tap);
  place-items: center;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: var(--text);
}
.icon-button:hover, .icon-button:active { border-color: var(--line); background: var(--surface-2); }
.icon-button.small { width: 42px; height: 42px; }
.icon-button svg, .bottom-nav svg, .save-button svg, .sidebar-nav svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.9; }

.header-panel {
  position: fixed;
  z-index: 30;
  top: 78px;
  right: 16px;
  left: 16px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #161b21;
  box-shadow: var(--shadow);
}
.header-panel[hidden], .app-screen[hidden] { display: none; }
.panel-title { margin-bottom: 11px; color: var(--muted); font-size: .78rem; font-weight: 800; }
.panel-title-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.panel-title-row span { margin-left: 2px; }
.panel-close { display: grid; width: 40px; height: 40px; margin: -8px -8px 3px 0; place-items: center; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); color: var(--text); font-size: 1.45rem; line-height: 1; }
.panel-close:hover { border-color: var(--accent); color: var(--accent-strong); }
.menu-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.menu-actions button { min-height: var(--tap); border: 1px solid var(--line); border-radius: 11px; background: var(--surface-2); color: var(--text); font-weight: 750; }
.menu-actions button:hover { border-color: var(--accent); color: var(--accent-strong); }
.menu-actions .menu-wide { grid-column: 1 / -1; }
.stats-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.stats-grid div { min-height: 68px; padding: 10px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface-2); }
.stats-grid span, .stats-grid strong { display: block; }
.stats-grid span { color: var(--muted); font-size: .7rem; font-weight: 700; }
.stats-grid strong { margin-top: 6px; color: var(--accent-strong); font-size: 1.06rem; font-weight: 800; }

main { min-width: 0; }
.app-screen { width: min(100%, 760px); margin: 0 auto; padding: 24px 0; }
.record-hero { display: flex; align-items: end; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.record-hero-copy h2, .screen-heading h2 { margin: 0; color: var(--text); font-size: 1.66rem; font-weight: 850; letter-spacing: -.025em; line-height: 1.18; }
.record-hero-copy span { display: block; margin-top: 7px; color: var(--muted); font-size: .78rem; font-weight: 600; }
.desktop-stats-button { display: none; min-height: 42px; padding: 0 14px; border: 1px solid var(--line-strong); border-radius: 11px; background: var(--surface); color: var(--muted); font-size: .78rem; font-weight: 800; }
.desktop-stats-button:hover { border-color: var(--accent); color: var(--accent-strong); }
.screen-heading { display: flex; align-items: end; justify-content: space-between; gap: 12px; padding: 3px 0 16px; }
.screen-section { padding: 0; }

.record-form-section, .chart-panel, .timer-panel, .calendar-panel {
  display: grid;
  gap: 16px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: 0 12px 28px rgba(0, 0, 0, .12);
}
.field-grid, .input-grid { display: grid; gap: 12px; }
.control-stack, .number-control { display: grid; gap: 8px; }
label, .control-stack > span, .number-control > label, .custom-duration > span { color: var(--muted); font-size: .74rem; font-weight: 800; }
select, .custom-form input, .custom-duration input { width: 100%; min-height: var(--tap); border: 1px solid var(--line-strong); border-radius: 11px; background: #10151a; color: var(--text); font-weight: 700; }
select { padding: 0 34px 0 12px; }
.field-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 26px; }
.selected-exercise { min-width: 0; overflow: hidden; color: var(--accent-strong); font-size: .77rem; font-weight: 750; text-overflow: ellipsis; white-space: nowrap; }
.text-button, .ghost-button { min-height: 40px; border: 1px solid transparent; border-radius: 10px; background: transparent; color: var(--accent-strong); font-weight: 800; }
.text-button { padding: 0 8px; white-space: nowrap; }
.text-button:hover, .ghost-button:hover { background: var(--accent-weak); }
.custom-form { padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2); }
.inline-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; margin-top: 8px; }
.custom-form input, .custom-duration input { padding: 0 10px; }
.custom-note { margin: 8px 0 0; color: var(--muted); font-size: .74rem; font-weight: 650; }
.mini-button { min-width: 64px; min-height: var(--tap); border: 1px solid var(--accent); border-radius: 10px; background: var(--accent); color: var(--on-accent); font-weight: 850; }

.stepper { display: grid; grid-template-columns: 48px minmax(0, 1fr) 48px; min-height: 56px; overflow: hidden; border: 1px solid var(--line-strong); border-radius: 12px; background: #10151a; }
.stepper button { border: 0; background: var(--surface-3); color: var(--accent-strong); font-size: 1.55rem; font-weight: 700; line-height: 1; }
.stepper button:active { background: var(--accent-weak); }
.stepper input { width: 100%; min-width: 0; border: 0; background: transparent; color: var(--text); font-size: 1.28rem; font-weight: 800; text-align: center; appearance: textfield; }
.stepper input::-webkit-outer-spin-button, .stepper input::-webkit-inner-spin-button { margin: 0; appearance: none; }

.recent-box, .chart-summary, .day-detail { overflow: hidden; border: 1px solid var(--line); border-radius: 12px; background: #11171c; }
.recent-box h3 { margin: 0; padding: 11px 12px; border-bottom: 1px solid var(--line); color: var(--text); font-size: .79rem; }
.recent-box ul, .record-list { display: grid; margin: 0; padding: 0; list-style: none; }
.recent-box li { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 8px; align-items: center; min-height: 58px; padding: 9px 12px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: .76rem; font-weight: 700; }
.recent-box li > div { min-width: 0; }
.recent-box li strong, .recent-box li span { display: block; }
.recent-box li > div > span { margin-top: 3px; color: var(--muted); font-size: .7rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent-box li.empty-record { display: block; min-height: 42px; padding-top: 12px; }
.record-volume { color: var(--accent-strong); font-size: .72rem; font-weight: 850; text-align: right; white-space: nowrap; }
.recent-box li:last-child, .record-list li:last-child { border-bottom: 0; }
.recent-box strong { color: var(--accent-strong); }
.save-button { display: inline-flex; min-height: 58px; align-items: center; justify-content: center; gap: 10px; border: 1px solid var(--accent); border-radius: 12px; background: var(--accent); color: var(--on-accent); font-size: 1rem; font-weight: 850; }
.save-button:hover, .outline-button:hover { background: var(--accent-strong); }
.form-message { min-height: 20px; margin: -5px 0 0; color: var(--ok); font-size: .8rem; font-weight: 750; }
.form-message.is-error { color: var(--danger); }

.segmented { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); min-height: 46px; overflow: hidden; border: 1px solid var(--line-strong); border-radius: 11px; background: #11171c; }
.segmented button { border: 0; border-right: 1px solid var(--line); background: transparent; color: var(--muted); font-weight: 800; }
.segmented button:last-child { border-right: 0; }
.segmented button.is-active { background: var(--accent); color: var(--on-accent); }
.period-toggle { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.chart-metric-hint { margin: -7px 1px 0; color: var(--muted); font-size: .74rem; font-weight: 650; line-height: 1.55; }
.chart-wrap { position: relative; height: 250px; overflow: hidden; border-radius: 12px; background: #11171c; }
#progressChart { width: 100%; height: 100%; }
.chart-point { cursor: pointer; outline: none; }
.chart-point-hit { fill: transparent; }
.chart-point-dot { fill: var(--accent); stroke: #11171c; stroke-width: 3; transition: r .16s ease, stroke .16s ease; }
.chart-point:hover .chart-point-dot, .chart-point:focus .chart-point-dot { r: 7; stroke: var(--text); }
.chart-tooltip { position: absolute; z-index: 2; top: var(--point-y); left: var(--point-x); width: max-content; max-width: calc(100% - 16px); padding: 8px 10px; border: 1px solid var(--line-strong); border-radius: 10px; background: #0d1216; box-shadow: var(--shadow); color: var(--text); font-size: .71rem; font-weight: 750; line-height: 1.45; pointer-events: none; transform: translate(-50%, calc(-100% - 12px)); white-space: normal; }
.chart-tooltip[data-placement="bottom"] { transform: translate(-50%, 12px); }
.chart-tooltip strong, .chart-tooltip span { display: block; }
.chart-tooltip strong { color: var(--accent-strong); }
.chart-tooltip span { margin-top: 2px; color: var(--muted); }
.chart-summary { display: grid; grid-template-columns: 1fr auto; gap: 5px 10px; align-items: center; min-height: 74px; padding: 12px; }
.chart-summary strong { color: var(--accent-strong); font-size: 1.18rem; }
.chart-summary span, .chart-summary small { color: var(--muted); font-size: .76rem; font-weight: 700; }
.chart-series-legend { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
.chart-series-legend:empty { display: none; }
.chart-series-legend span { display: grid; grid-template-columns: 24px minmax(0, 1fr) auto; align-items: center; gap: 6px; min-height: 38px; padding: 7px 8px; overflow: hidden; border: 1px solid var(--line); border-radius: 9px; background: #11171c; color: var(--text); font-size: .72rem; font-weight: 760; }
.chart-series-legend i { display: block; height: 3px; border-radius: 999px; background: repeating-linear-gradient(to right, rgba(71, 230, 157, var(--series-opacity)) 0 7px, transparent 7px 11px); }
.chart-series-legend small { color: var(--muted); font-size: .66rem; font-weight: 700; }

.timer-presets { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 7px; }
.timer-presets button { min-height: var(--tap); border: 1px solid var(--line-strong); border-radius: 11px; background: #11171c; color: var(--text); font-size: .78rem; font-weight: 800; }
.timer-presets button.is-active { border-color: var(--accent); background: var(--accent); color: var(--on-accent); }
.custom-duration { display: grid; grid-template-columns: 1fr 96px; gap: 10px; align-items: center; }
.timer-face { position: relative; display: grid; width: min(70vw, 260px); aspect-ratio: 1; place-items: center; margin: 8px auto; }
.timer-face svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.timer-track { fill: none; stroke: var(--surface-3); stroke-width: 10; }
.timer-progress { fill: none; stroke: var(--accent); stroke-linecap: round; stroke-width: 10; stroke-dasharray: 314; stroke-dashoffset: 0; transition: stroke-dashoffset .2s linear; }
.timer-readout { position: absolute; display: grid; place-items: center; }
.timer-readout span, .timer-readout small { color: var(--muted); font-size: .77rem; font-weight: 750; }
.timer-readout strong { color: var(--text); font-size: 2.8rem; font-weight: 850; letter-spacing: -.04em; line-height: 1.12; }
.timer-actions { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.outline-button { min-height: 54px; border: 1px solid var(--accent); border-radius: 12px; background: var(--accent); color: var(--on-accent); font-weight: 850; }
.ghost-button { min-width: 88px; border: 1px solid var(--line-strong); color: var(--text); }
.timer-alert { min-height: 22px; margin: 0; color: var(--accent-strong); font-size: .8rem; font-weight: 800; text-align: center; }
.timer-alert.is-done { color: var(--ok); animation: flashDone .9s ease-out 2; }

.calendar-heading { align-items: center; }
.today-button { min-width: 58px; border: 1px solid var(--line-strong); }
.month-controls { display: grid; grid-template-columns: 42px 1fr 42px; align-items: center; gap: 8px; }
.month-controls strong { color: var(--text); font-size: .96rem; text-align: center; }
.calendar-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); overflow: hidden; border: 1px solid var(--line); border-radius: 12px; background: var(--line); gap: 1px; }
.weekday, .calendar-cell { min-width: 0; background: #11171c; }
.weekday { display: grid; min-height: 30px; place-items: center; color: var(--muted); font-size: .68rem; font-weight: 800; }
.calendar-cell { position: relative; display: grid; min-height: 48px; place-items: center; border: 0; color: var(--text); font-size: .84rem; font-weight: 800; }
.calendar-cell.is-muted { color: var(--faint); background: #101419; }
.calendar-cell.has-workout::after { content: ""; position: absolute; bottom: 7px; width: 5px; height: 5px; border-radius: 50%; background: var(--accent); }
.calendar-cell.is-selected { background: var(--accent-weak); color: var(--accent-strong); box-shadow: inset 0 0 0 2px var(--accent); }
.calendar-cell.is-today { color: var(--accent-strong); }
.day-detail-header { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: baseline; padding: 12px; border-bottom: 1px solid var(--line); }
.day-detail-header strong { color: var(--text); font-size: .8rem; }
.day-detail-header span { color: var(--accent-strong); font-size: .76rem; font-weight: 800; }
.record-list li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: center; min-height: 58px; padding: 9px 12px; border-bottom: 1px solid var(--line); }
.record-list strong, .record-list span { display: block; }
.record-list strong { color: var(--text); font-size: .82rem; }
.record-list span { margin-top: 3px; color: var(--muted); font-size: .73rem; font-weight: 650; }
.delete-button { min-width: 48px; min-height: 40px; border: 1px solid rgba(255, 122, 138, .45); border-radius: 10px; background: rgba(255, 122, 138, .08); color: var(--danger); font-size: .74rem; font-weight: 800; }
.delete-button.compact { min-width: 46px; min-height: 38px; }
.add-record-button { width: calc(100% - 24px); min-height: 50px; margin: 10px 12px 12px; border: 1px solid var(--accent); border-radius: 10px; background: var(--accent-weak); color: var(--accent-strong); font-weight: 850; }
.add-record-button:hover { background: var(--accent); color: var(--on-accent); }

.bottom-nav { position: fixed; right: 0; bottom: 0; left: 0; z-index: 20; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); min-height: 76px; padding-bottom: env(safe-area-inset-bottom); border-top: 1px solid var(--line); background: rgba(16, 20, 25, .96); backdrop-filter: blur(14px); }
.bottom-nav button { display: grid; min-width: 0; place-items: center; gap: 4px; padding: 8px 2px; border: 0; background: transparent; color: var(--muted); font-size: .67rem; font-weight: 800; }
.bottom-nav button.is-active { color: var(--accent-strong); }
.bottom-nav button.is-active svg { stroke-width: 2.5; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
@keyframes flashDone { 0%,100% { opacity: 1; } 50% { opacity: .45; } }

@media (min-width: 500px) {
  .app-shell { padding-right: 24px; padding-left: 24px; }
  .top-bar { margin-right: -24px; margin-left: -24px; padding-right: 24px; padding-left: 24px; }
  .header-panel { right: 24px; left: 24px; }
  .field-grid { grid-template-columns: minmax(0, .72fr) minmax(0, 1.28fr); }
  .input-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .stepper { grid-template-columns: 42px minmax(0, 1fr) 42px; }
}

@media (max-width: 360px) {
  .chart-series-legend { grid-template-columns: 1fr; }
}

@media (min-width: 960px) {
  .app-shell { min-height: 100vh; padding: 0 44px 48px 318px; }
  .desktop-sidebar { position: fixed; inset: 0 auto 0 0; z-index: 40; display: flex; width: 270px; flex-direction: column; padding: 36px 24px 28px; border-right: 1px solid #1d252c; background: var(--sidebar); }
  .brand-lockup { display: flex; align-items: center; gap: 12px; }
  .brand-lockup > div > strong { display: block; color: var(--text); font-size: 1.12rem; font-weight: 850; letter-spacing: -.025em; }
  .brand-lockup > div > span { display: block; margin-top: 3px; color: var(--muted); font-size: .68rem; }
  .brand-mark { width: 34px; height: 34px; flex: 0 0 34px; margin: 0; color: var(--accent); }
  .brand-mark path { fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 2.2; }
  .sidebar-nav { display: grid; gap: 7px; margin-top: 56px; }
  .sidebar-nav button { display: flex; min-height: 52px; align-items: center; gap: 13px; padding: 0 14px; border: 1px solid transparent; border-radius: 12px; background: transparent; color: var(--muted); font-size: .88rem; font-weight: 800; text-align: left; }
  .sidebar-nav button:hover { background: var(--surface-2); color: var(--text); }
  .sidebar-nav button.is-active { border-color: rgba(50, 208, 139, .16); background: var(--accent-weak); color: var(--text); }
  .sidebar-nav button.is-active svg { color: var(--accent-strong); }
  .sidebar-user { display: flex; align-items: center; gap: 10px; margin-top: auto; padding: 13px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface-2); }
  .sidebar-user > span { display: grid; width: 34px; height: 34px; place-items: center; border-radius: 50%; background: var(--accent-weak); color: var(--accent-strong); font-size: .72rem; font-weight: 850; }
  .sidebar-user strong, .sidebar-user small { display: block; }
  .sidebar-user strong { color: var(--text); font-size: .8rem; }
  .sidebar-user small { margin-top: 2px; color: var(--muted); font-size: .67rem; }
  .top-bar, .bottom-nav { display: none; }
  .header-panel { top: 30px; right: 44px; left: auto; width: 330px; }
  main { width: min(100%, 1120px); margin: 0 auto; }
  .app-screen { width: 100%; max-width: 1120px; padding-top: 44px; }
  .record-hero-copy h2, .screen-heading h2 { font-size: 2rem; }
  .desktop-stats-button { display: inline-flex; align-items: center; }
  .record-form-section { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; padding: 22px; }
  .record-form-section .field-grid, .record-form-section .field-row, .record-form-section .custom-form, .record-form-section .input-grid, .record-form-section .recent-box, .record-form-section .save-button, .record-form-section .form-message { grid-column: 1 / -1; }
  .field-grid { grid-template-columns: minmax(0, .72fr) minmax(0, 1.28fr); }
  .input-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .record-form-section .save-button { justify-self: end; width: min(290px, 100%); }
  .chart-panel, .timer-panel, .calendar-panel { width: min(100%, 820px); }
}

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; } }
