/* 「今日の自分」Web版。
   Swift版 AppTheme（手書き風・ライト固定）をそのまま持ってきている。 */

:root {
  --bg: #FFFFFF;
  --surface: #FFFFFF;
  --ink: #292621;
  --ink-2: #75736E;
  --accent: #2E2B26;
  --slot: #F7F7F6;
  --quiet-stroke: rgba(117, 115, 110, 0.26);
  --saturday: #2173E6;
  --sunday: #DB3333;
  --saved: #1CB866;

  /* Klee One を載せるときはここだけ差し替える。
     8.5MB を丸ごと配ると初回が重いので、載せるならサブセット化してからにすること */
  --font: "Hiragino Maru Gothic ProN", "ヒラギノ丸ゴ ProN", "Hiragino Sans",
          "Yu Gothic", system-ui, -apple-system, sans-serif;

  --tabbar-h: 52px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  /* 引っ張って更新（＝Webっぽさの正体）を止める */
  overscroll-behavior: none;
}

body {
  /* タップ時の青い矩形、長押しのメニュー、テキスト選択を止める。
     これが残っていると、ホーム画面から起動しても一発でWebだと分かる */
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-text-size-adjust: 100%;
}

input, textarea { -webkit-user-select: text; user-select: text; }

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  position: relative;
  /* 揺らいだ枠は背景のSVGが描くので、押したときは縮めるだけにする */
  transition: transform 0.12s ease;
}
button:active { transform: scale(0.97); }

/* 揺らいだ「面」。中身より必ず後ろに敷く */
svg.surface {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}
.surfaced { position: relative; }
.surfaced > *:not(svg.surface) { position: relative; z-index: 1; }

svg.fig { display: block; overflow: visible; }

/* ---------------------------------------------------------------- 骨格 */

#app { display: flex; flex-direction: column; height: 100%; }
#app[hidden] { display: none; }

#screen {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-top: var(--safe-t);
  /* インストールバーが出ているときは、そちらが安全領域を負担する */
  /* タブバーとホームバーのぶんを空ける。これを忘れると最下部が押せない */
  padding-bottom: calc(var(--tabbar-h) + var(--safe-b) + 8px);
}

.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  height: calc(var(--tabbar-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-top: 1px solid rgba(117, 115, 110, 0.18);
  z-index: 20;
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--ink-2);
  font-size: 10px;
}
.tab svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.tab[aria-selected="true"] { color: var(--accent); }
.tab[aria-selected="true"] svg { stroke-width: 2.1; }
.tab:active { transform: none; }

/* ---------------------------------------------------------------- 記録画面 */

.record { padding: 10px 16px 6px; display: flex; flex-direction: column; gap: 5px; min-height: 100%; }

.bubble { position: relative; align-self: flex-start; margin-left: 0; }
.bubble .bubble-text {
  position: relative; z-index: 1;
  font-size: 22px; line-height: 1.25;
  padding: 11px 18px 24px;
  display: block;
}
.bubble svg { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 0; }

.record-date { font-size: 15px; color: var(--ink-2); padding-left: 6px; }

.streak {
  align-self: flex-start;
  margin: 1px 0 0 6px;
  font-size: 13px;
  color: var(--ink-2);
  padding: 5px 11px;
  animation: fade-in 0.25s ease;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.section-label { font-size: 12px; font-weight: 600; color: var(--ink-2); margin-top: 2px; }

.level-row { display: flex; gap: 6px; }
.level-cell {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 5px 2px;
  min-width: 0;
}
.level-cell .fig { transition: transform 0.18s ease; }
.level-cell[aria-pressed="true"] .fig { transform: scale(1.12); }
.level-cell .level-name { font-size: 10px; color: var(--ink-2); white-space: nowrap; }
.level-cell[aria-pressed="true"] .level-name { font-weight: 600; }
.level-cell .fig.battery { width: 34px; height: 20px; }
.level-cell .fig.face { width: 26px; height: 26px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 5px 9px;
  font-size: 12px;
  color: var(--ink);
}
.chip .fig { width: 16px; height: 16px; flex: none; }
.chip .chip-emoji { font-size: 13px; filter: grayscale(1); }
.chip[aria-pressed="true"] { color: var(--accent); font-weight: 600; }
.chip-add { color: var(--ink-2); }

.memo {
  width: 100%;
  min-height: 46px;
  max-height: 92px;
  resize: none;
  border: 0;
  outline: none;
  background: transparent;
  font: inherit;
  font-size: 14px;
  color: var(--ink);
  padding: 10px 12px;
}
.memo::placeholder { color: rgba(117, 115, 110, 0.7); }
.memo-wrap { position: relative; }

.save {
  width: 100%;
  padding: 13px;
  font-size: 16px;
  color: #fff;
  display: flex; align-items: center; justify-content: center; gap: 7px;
  margin-top: 2px;
}
.save .check { font-size: 15px; font-weight: 700; }

.grow { flex: 1; min-height: 0; }

/* ---------------------------------------------------------------- 履歴 */

.history { padding: 10px 8px 24px; display: flex; flex-direction: column; gap: 12px; }
.history.is-list, .history.is-year { padding-left: 16px; padding-right: 16px; }

.screen-title { font-size: 17px; text-align: center; margin: 4px 0 0; font-weight: 600; }

.segmented {
  display: flex;
  background: var(--slot);
  border-radius: 9px;
  padding: 2px;
  gap: 2px;
}
.segmented button {
  flex: 1;
  padding: 6px 4px;
  font-size: 13px;
  color: var(--ink-2);
  border-radius: 7px;
}
.segmented button[aria-selected="true"] {
  background: #fff;
  color: var(--ink);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0,0,0,0.12);
}

.period { display: flex; align-items: center; justify-content: space-between; }
.period .period-label { font-size: 17px; }
.period button { padding: 6px 14px; font-size: 20px; color: var(--ink); line-height: 1; }
.period button[disabled] { opacity: 0.3; }

.weekdays { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.weekdays span { text-align: center; font-size: 11px; color: var(--ink-2); }
.weekdays span:first-child { color: var(--sunday); }
.weekdays span:last-child { color: var(--saturday); }

.calendar { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.cal-cell {
  height: 84px;
  border-radius: 10px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 4px 2px;
  border: 1px solid transparent;
  overflow: hidden;
}
.cal-cell.empty { visibility: hidden; }
.cal-cell .cal-day { font-size: 13px; }
.cal-cell .fig.battery { width: 26px; height: 15px; }
.cal-cell .fig.face { width: 20px; height: 20px; }
.cal-cell .cal-events { display: flex; gap: 1px; align-items: center; }
.cal-cell .cal-events .fig { width: 14px; height: 14px; }
.cal-cell .cal-events .chip-emoji { font-size: 11px; }
.cal-cell .cal-more { font-size: 7px; color: var(--ink-2); }
.cal-cell.is-today { border-color: var(--accent); border-width: 2px; }
.cal-cell.future { opacity: 0.3; }
.cal-cell .note-dot { position: absolute; top: 4px; right: 4px; width: 5px; height: 5px; border-radius: 50%; background: var(--accent); }
.cal-cell { position: relative; }

.day-list { display: flex; flex-direction: column; gap: 7px; }
.day-row {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 12px;
  width: 100%;
  text-align: left;
  overflow: hidden;
}
.day-row .day-label { font-size: 15px; width: 76px; flex: none; white-space: nowrap; }
.day-row .fig.battery { width: 36px; height: 21px; flex: none; }
.day-row .fig.face { width: 30px; height: 30px; flex: none; }
.day-row .day-events { display: flex; gap: 5px; align-items: center; flex: none; }
.day-row .day-events .fig { width: 21px; height: 21px; }
.day-row .day-events .chip-emoji { font-size: 17px; }
.day-row .day-note {
  font-size: 12px; color: var(--ink-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0;
}
.day-row .day-more { font-size: 11px; color: var(--ink-2); }

.focus-row { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0; scrollbar-width: none; }
.focus-row::-webkit-scrollbar { display: none; }
.focus-row .chip { flex: none; }

.compare { padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.compare h3 { margin: 0; font-size: 13px; font-weight: 600; }
.compare-row { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.compare-row .compare-title { font-size: 12px; color: var(--ink-2); width: 32px; flex: none; }
.compare-row .with { font-weight: 600; }
.compare-row .without { color: var(--ink-2); }
.compare-row .delta { margin-left: auto; font-weight: 600; }
.compare-row .delta.up { color: #299475; }
.compare-row .delta.down { color: #D95247; }
.compare .compare-note { font-size: 10px; color: var(--ink-2); margin: 0; }

.year-grid { display: flex; flex-direction: column; gap: 1.2px; }
.year-row { display: flex; gap: 1.2px; align-items: center; }
.year-row .year-label { width: 16px; flex: none; font-size: 8px; color: var(--ink-2); text-align: right; }
.year-row .year-cell { flex: 1; height: 12px; border-radius: 2.5px; }
.year-head { display: flex; gap: 1.2px; }
.year-head .year-label { width: 16px; flex: none; }
.year-head span:not(.year-label) { flex: 1; text-align: center; font-size: 9px; color: var(--ink-2); }
.year-legend { display: flex; align-items: center; gap: 6px; font-size: 10px; color: var(--ink-2); margin-top: 8px; }
.year-legend i { display: block; width: 14px; height: 10px; border-radius: 2px; }
.year-legend .spacer { margin-left: auto; }

.empty-state { text-align: center; color: var(--ink-2); font-size: 13px; padding: 48px 16px; }

/* ---------------------------------------------------------------- 設定 */

.settings { padding: 12px 16px 24px; display: flex; flex-direction: column; gap: 18px; }
.group { display: flex; flex-direction: column; gap: 8px; }
.group > h2 { margin: 0; font-size: 12px; font-weight: 600; color: var(--ink-2); }
.group > .note { margin: 0; font-size: 11px; color: var(--ink-2); line-height: 1.5; }
.row {
  display: flex; align-items: center; gap: 10px;
  color: inherit; text-decoration: none;
  padding: 13px 14px;
  width: 100%;
  text-align: left;
  font-size: 14px;
}
.row .row-sub { margin-left: auto; color: var(--ink-2); font-size: 13px; }
.row.danger { color: #D95247; }

.tag-row { display: flex; align-items: center; gap: 10px; padding: 10px 12px; font-size: 14px; }
.tag-row .fig { width: 20px; height: 20px; flex: none; }
.tag-row .tag-emoji { font-size: 17px; filter: grayscale(1); }
.tag-row .tag-name { flex: 1; min-width: 0; }
.tag-row .cal-toggle { font-size: 11px; color: var(--ink-2); padding: 4px 8px; border-radius: 999px; background: var(--slot); }
.tag-row .cal-toggle[aria-pressed="true"] { background: rgba(46,43,38,0.12); color: var(--accent); font-weight: 600; }
.tag-row .tag-delete { color: #D95247; font-size: 13px; padding: 4px 6px; }

.backup-warning {
  padding: 12px 14px;
  font-size: 12.5px;
  line-height: 1.6;
  background: rgba(255, 201, 26, 0.16);
  border-radius: 10px;
}

/* ---------------------------------------------------------------- シート */

.sheet-back {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(0,0,0,0.28);
  display: flex; align-items: flex-end;
  animation: back-in 0.2s ease;
}
@keyframes back-in { from { opacity: 0; } to { opacity: 1; } }
.sheet {
  width: 100%;
  background: #fff;
  border-radius: 16px 16px 0 0;
  padding: 16px 16px calc(16px + var(--safe-b));
  max-height: 86%;
  overflow-y: auto;
  animation: sheet-up 0.24s cubic-bezier(0.32, 0.72, 0, 1);
}
@keyframes sheet-up { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet h2 { margin: 0 0 12px; font-size: 16px; }
.sheet .sheet-actions { display: flex; gap: 8px; margin-top: 16px; }
.sheet .sheet-actions button { flex: 1; padding: 12px; font-size: 15px; border-radius: 10px; }
.sheet .sheet-actions .primary { background: var(--accent); color: #fff; }
.sheet .sheet-actions .secondary { background: var(--slot); color: var(--ink); }
.sheet .sheet-actions .destructive { background: #D95247; color: #fff; }
.sheet label { display: block; font-size: 12px; color: var(--ink-2); margin: 10px 0 4px; }
.sheet input[type="text"] {
  width: 100%; padding: 11px 12px; font: inherit; font-size: 15px;
  border: 1px solid var(--quiet-stroke); border-radius: 10px; background: #fff; color: var(--ink);
  outline: none;
}
.sheet input[type="text"]:focus { border-color: var(--accent); }
.sheet .detail-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.sheet .detail-head .fig.battery { width: 46px; height: 26px; }
.sheet .detail-head .fig.face { width: 34px; height: 34px; }
.sheet .detail-meta { font-size: 13px; color: var(--ink-2); }

/* ---------------------------------------------------------------- 追加ゲート */

#install-gate {
  position: fixed; inset: 0; z-index: 50;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  padding: calc(24px + var(--safe-t)) 22px calc(24px + var(--safe-b));
  overflow-y: auto;
}
#install-gate[hidden] { display: none; }
.gate-card { max-width: 420px; }
.gate-what {
  font-size: 14px; line-height: 1.8; margin: 0 0 26px;
  padding: 14px 16px; border-radius: 12px; background: var(--slot);
}
.gate-what strong { font-size: 17px; }
.gate-privacy { display: block; margin-top: 6px; color: var(--ink-2); font-size: 12.5px; }
.gate-card h1 { font-size: 20px; margin: 0 0 14px; }
.gate-lead { font-size: 14px; line-height: 1.75; margin: 0 0 18px; }
.gate-steps { font-size: 14px; line-height: 2; padding-left: 1.2em; margin: 0 0 18px; }
.gate-note { font-size: 12px; color: var(--ink-2); margin: 0 0 22px; }
.gate-dismiss {
  font-size: 13px; color: var(--ink-2);
  text-decoration: underline; text-underline-offset: 3px;
  display: block;
}

/* --------------------------------------------------- Androidのインストールバー */

#install-bar {
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + var(--safe-t)) 14px 10px;
  background: var(--slot);
  border-bottom: 1px solid var(--quiet-stroke);
  font-size: 12.5px;
  color: var(--ink-2);
}
#install-bar[hidden] { display: none; }
#install-bar span { flex: 1; min-width: 0; }
#install-run {
  flex: none; padding: 7px 14px; border-radius: 999px;
  background: var(--accent); color: #fff; font-size: 13px;
}
#install-close { flex: none; padding: 4px 6px; font-size: 17px; color: var(--ink-2); }

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

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + var(--safe-b) + 18px);
  transform: translate(-50%, 12px);
  background: rgba(41, 38, 33, 0.94);
  color: #fff;
  font-size: 13px;
  padding: 10px 16px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 60;
  max-width: 86%;
  text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
