/*
 * 配色・形・タイポグラフィは自作アプリ共通のGUI規約に従う(参照実装はMyMoneyのstyle.css)。
 *  - 既定をダークにする。背景・面・境界はすべて無彩色で、色を持つのはアクセント(寒色)と警告だけ
 *  - 角丸は 4 / 6 / 14px の3段階。押せる要素は最小44px
 *  - 時刻・分数は等幅数字(tabular-nums)
 *  - 画面ごとに主役を1つ置く(今日: 次の一歩。着手: 一歩とタイマー)
 * 達成率・連続日数・未達の一覧は出さない(DESIGN.md §8)。
 */

:root {
  --bg: #121212;
  --surface: #1e1e1e;
  --surface-raised: #262626;
  --line: #333333;
  --text: #e8e8e8;
  --muted: #a0a0a0;
  --accent: #6ea8fe;
  --on-accent: #10151d;
  --alert: #ff8a80;

  --tap: 44px;
  --r-sm: 4px;
  --r-md: 6px;
  --r-sheet: 14px;

  --nav-h: 56px;
  --record-h: 52px;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #fafafa;
    --surface: #ffffff;
    --surface-raised: #ffffff;
    --line: #e0e0e0;
    --text: #1a1a1a;
    --muted: #5f5f5f;
    --accent: #1863dc;
    --on-accent: #ffffff;
    --alert: #c62828;
    color-scheme: light;
  }
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}

h1,
h2,
.label-muted,
.section-heading,
.primary-title,
.empty-title {
  font-feature-settings: "palt";
}

/* --- 共通の部品 ------------------------------------------------------------- */

input,
button {
  font: inherit;
  border-radius: var(--r-sm);
}

input {
  width: 100%;
  min-height: var(--tap);
  padding: 0 14px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
}

label.field-label {
  display: block;
  margin: 0 0 4px;
  font-size: 0.8rem;
  color: var(--muted);
}

button {
  min-height: var(--tap);
  padding: 0 20px;
  border: none;
  background: none;
  color: inherit;
  font-weight: 400;
  cursor: pointer;
}

.btn-primary {
  border-radius: var(--r-md);
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 700;
}

.btn-wide {
  width: 100%;
  height: var(--record-h);
  margin-top: 16px;
}

.btn-outline {
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  color: var(--text);
}

.btn-text {
  padding: 0 4px;
  color: var(--muted);
}

.btn-text.accent {
  color: var(--accent);
}

.btn-text.alert {
  color: var(--alert);
}

.link-btn-block,
.link-btn-alert {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0 4px;
  font-weight: 600;
}

.link-btn-block {
  color: var(--accent);
}

.link-btn-alert {
  color: var(--alert);
}

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

.error {
  margin: 6px 0 0;
  color: var(--alert);
  font-size: 0.85rem;
}

.empty-hint {
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
  padding: 16px 8px;
}

.empty-state {
  margin-top: 40px;
  text-align: center;
}

.empty-title {
  margin: 0 0 6px;
  font-size: 1.1rem;
  font-weight: 700;
}

.empty-desc {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 0.9rem;
}

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

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

.login-inner {
  width: min(360px, 100%);
  display: grid;
  gap: 16px;
}

.login-inner h1 {
  margin: 0;
  font-size: 1.5rem;
  line-height: 1.15;
  text-align: center;
}

#login-form {
  display: grid;
  gap: 10px;
}

#login-form button[type="submit"] {
  border-radius: var(--r-md);
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 700;
}

/* --- 本体のレイアウト --------------------------------------------------------- */

#app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  max-width: 640px;
  margin-inline: auto;
}

header {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: max(10px, env(safe-area-inset-top)) 16px 8px;
  background: var(--bg);
}

#header-date {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.conn-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 16px;
  background: var(--surface);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  color: var(--alert);
  font-size: 0.85rem;
}

main {
  flex: 1;
  padding: 4px 16px calc(var(--nav-h) + var(--record-h) + 40px + env(safe-area-inset-bottom));
}

/* --- セクション(枠なし。小さい見出しと1pxの罫線) -------------------------------- */

.section {
  margin-top: 32px;
}

.section-heading {
  margin: 0 0 6px;
  padding-bottom: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.02em;
  border-bottom: 1px solid var(--line);
}

.section-primary {
  margin-top: 8px;
}

.label-muted {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
}

/* 主役: 次の一歩。長い題でも折り返して全部見せる */
.primary-title {
  margin: 4px 0 0;
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.secondary-line {
  margin: 6px 0 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.secondary-line.is-alert {
  color: var(--alert);
  font-weight: 600;
}

/* --- 時間帯の一覧 ------------------------------------------------------------- */

.slot-list,
.day-slots {
  list-style: none;
  margin: 0;
  padding: 0;
}

.slot-row {
  display: flex;
  align-items: baseline;
  gap: 14px;
  width: 100%;
  min-height: 56px;
  padding: 8px 4px;
  border-radius: 0;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

li:last-child > .slot-row {
  border-bottom: none;
}

.slot-row:active {
  background: var(--surface-raised);
}

.slot-time {
  flex: none;
  min-width: 5.6em;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.slot-body {
  flex: 1;
  min-width: 0;
}

.slot-main {
  margin: 0;
  overflow-wrap: anywhere;
}

.slot-main.is-muted {
  color: var(--muted);
}

.slot-main.is-alert {
  color: var(--alert);
  font-weight: 600;
}

.slot-sub {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.day-heading {
  position: sticky;
  top: 34px;
  z-index: 1;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin: 24px 0 0;
  padding: 6px 0;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  font-feature-settings: "palt";
}

.day-none {
  margin: 0;
  padding: 10px 4px;
  font-size: 0.85rem;
  color: var(--muted);
}

/* --- 着手の画面 --------------------------------------------------------------- */

.timer {
  margin: 12px 0 0;
  font-size: 3.5rem;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}

.run-actions {
  display: grid;
  gap: 8px;
  margin-top: 24px;
}

.run-actions .btn-wide {
  margin-top: 0;
}

.run-choice {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.run-choice button {
  min-height: var(--record-h);
}

/* --- 設定(予定画面の下) ------------------------------------------------------- */

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.setting-row .secondary-line {
  margin: 0;
}

.settings-logout-section {
  margin-top: 40px;
}

/* --- 下部固定: 始めるボタン・ナビゲーション --------------------------------------- */

#start-now {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(var(--nav-h) + 12px + env(safe-area-inset-bottom));
  z-index: 4;
  height: var(--record-h);
  max-width: 608px;
  margin-inline: auto;
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 4;
  display: flex;
  max-width: 640px;
  margin-inline: auto;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--line);
}

.nav-btn {
  flex: 1;
  min-height: var(--nav-h);
  border-top: 2px solid transparent;
  border-radius: 0;
  color: var(--muted);
  font-weight: 400;
  font-size: 0.85rem;
}

.nav-btn[aria-selected="true"] {
  color: var(--text);
  font-weight: 700;
  border-top-color: var(--accent);
}

/* --- 下から出るシート ------------------------------------------------------------ */

.sheet-overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
}

.sheet {
  width: min(560px, 100%);
  max-height: 92dvh;
  overflow-y: auto;
  display: grid;
  gap: 14px;
  padding: 8px 16px calc(16px + env(safe-area-inset-bottom));
  background: var(--surface-raised);
  border-radius: var(--r-sheet) var(--r-sheet) 0 0;
  transform: translateY(100%);
  transition: transform 200ms ease-out;
}

.sheet-overlay.open .sheet {
  transform: translateY(0);
}

@media (prefers-reduced-motion: reduce) {
  .sheet {
    transition: none;
  }
}

.sheet h2 {
  margin: 4px 0 0;
  font-size: 1rem;
}

.sheet-handle {
  width: 40px;
  height: 4px;
  margin: 6px auto 2px;
  border-radius: 999px;
  background: var(--line);
}

#sheet-body {
  display: grid;
  gap: 14px;
}

.sheet-steps {
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 0.9rem;
  color: var(--muted);
}

.sheet-steps li {
  padding: 2px 0;
}

.sheet-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

.sheet-actions .btn-primary {
  flex: 1;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

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

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + var(--record-h) + 24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  background: var(--surface-raised);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
}

.toast span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toast button {
  min-height: 32px;
  padding: 0 14px;
  color: var(--accent);
  font-weight: 600;
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}
