:root {
  --bg: #0f1216;
  --surface: #171c22;
  --surface-2: #212831;
  --border: #2b333e;
  --text: #e8ecf1;
  --muted: #98a2b0;
  --accent: #79c9a6;
  --accent-ink: #07130d;
  --danger: #e58a8a;
  --tap: 48px;
  --radius: 12px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }

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

button, input, textarea { font: inherit; color: inherit; touch-action: manipulation; }
button { cursor: pointer; }

/* ---------- レイアウト ---------- */
.view {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  max-width: 560px;
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: calc(env(safe-area-inset-top) + 10px) 8px 10px;
  border-bottom: 1px solid var(--border);
}

.title {
  flex: 1;
  margin: 0 4px;
  font-size: 17px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 12px calc(env(safe-area-inset-bottom) + 32px);
}

.bottombar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px calc(env(safe-area-inset-bottom) + 10px);
  border-top: 1px solid var(--border);
  background: var(--bg);
}

/* ---------- ボタン ---------- */
.text-btn {
  min-height: var(--tap);
  min-width: var(--tap);
  padding: 0 10px;
  background: none;
  border: 0;
  color: var(--muted);
  font-size: 15px;
}
.text-btn.danger { color: var(--danger); }

.link {
  background: none;
  border: 0;
  color: var(--accent);
  font-weight: 700;
  min-height: 40px;
  padding: 0 8px;
}

.btn-primary,
.btn-secondary,
.btn-danger,
.btn-ghost {
  display: block;
  width: 100%;
  min-height: 52px;
  border-radius: var(--radius);
  font-size: 17px;
  font-weight: 700;
  border: 1px solid transparent;
}

.btn-primary { background: var(--accent); color: var(--accent-ink); border: 0; }
.btn-primary:disabled { background: var(--surface-2); color: var(--muted); }

.btn-secondary { background: var(--surface-2); color: var(--text); border-color: var(--border); }

.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px dashed var(--border);
  font-weight: 400;
  font-size: 16px;
  margin-top: 12px;
}

/* ---------- ホーム ---------- */
.tag-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.tag-btn {
  min-height: 84px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 17px;
  font-weight: 700;
  line-height: 1.35;
  text-align: left;
  word-break: break-word;
}
.tag-btn:active { background: var(--surface-2); }

.tag-list { margin-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.tag-list .tag-btn { min-height: var(--tap); font-size: 16px; font-weight: 400; }

.hint { color: var(--muted); font-size: 14px; margin: 12px 2px; }
.muted { color: var(--muted); font-size: 14px; }

.toast {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: calc(env(safe-area-inset-bottom) + 64px);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 8px 10px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .45);
}
.toast-text { flex: 1; font-size: 14px; }

/* ---------- 入力フォーム ---------- */
.field { margin-bottom: 26px; }

.label {
  display: block;
  margin: 0 2px 8px;
  font-size: 14px;
  font-weight: 700;
  color: var(--muted);
}

.input {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
}
.input::placeholder { color: #6d7784; }
.textarea { min-height: 96px; resize: vertical; margin-top: 10px; }

.choices { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.choices.two { grid-template-columns: repeat(2, 1fr); }
.scale { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }

.choice, .scale button {
  min-height: 54px;
  padding: 0 2px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 15px;
}
.scale button { font-size: 18px; font-weight: 700; }

.choice[aria-pressed="true"],
.scale button[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
}

.scale-ends {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin: 6px 4px 0;
  font-size: 12px;
  color: var(--muted);
}
.scale-ends span:last-child { text-align: right; }

.stepper {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
}
.step {
  width: 64px;
  min-height: 54px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 24px;
}
.step-out {
  flex: 1;
  text-align: center;
  font-size: 18px;
  font-weight: 700;
}

/* ---------- 履歴 ---------- */
.day-head {
  margin: 22px 2px 8px;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
}
.day:first-child .day-head { margin-top: 0; }

.log-row {
  display: block;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  margin-bottom: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
}
.log-row:active { background: var(--surface-2); }
.log-name { font-size: 16px; font-weight: 700; word-break: break-word; }
.log-meta { margin-top: 4px; font-size: 13px; color: var(--muted); }
.log-note {
  margin-top: 6px;
  font-size: 13px;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---------- 作業マスタ ---------- */
.master-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0 8px 12px;
  margin-bottom: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.master-name { flex: 1; font-size: 15px; word-break: break-word; }
.master-row.archived .master-name { color: var(--muted); text-decoration: line-through; }

/* ---------- ダイアログ ---------- */
.dialog {
  width: min(92vw, 420px);
  padding: 20px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 16px;
}
.dialog::backdrop { background: rgba(0, 0, 0, .6); }
.dialog-title { margin: 0 0 12px; font-size: 17px; }
.dialog-body { margin: 0 0 12px; font-size: 14px; color: var(--muted); }
.dialog-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }

/* ---------- その他 ---------- */
.update-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: calc(env(safe-area-inset-top) + 8px) 12px 8px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

.fatal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
  background: var(--bg);
  color: var(--danger);
  font-size: 15px;
  text-align: center;
}
