:root {
  --bg: #FBF6EE;
  --surface: #FFFFFF;
  --ink: #3B2F2A;
  --ink-soft: #7A6A62;
  --line: #EADFD2;
  --accent: #D9734E;
  --accent-ink: #FFFFFF;
  --radius: 20px;
  --tabs-h: 64px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
  --bg: #1F1A17;
  --surface: #2B2420;
  --ink: #F3E9DF;
  --ink-soft: #B5A498;
  --line: #43382F;
  --accent: #E08663;
  --accent-ink: #24150E;
  color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1F1A17;
  --surface: #2B2420;
  --ink: #F3E9DF;
  --ink-soft: #B5A498;
  --line: #43382F;
  --accent: #E08663;
  --accent-ink: #24150E;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }

.app {
  max-width: 480px;
  min-height: 100dvh;
  margin: 0 auto;
  padding-block: 24px calc(var(--tabs-h) + 32px + env(safe-area-inset-bottom, 0px));
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}

main:focus { outline: none; }

h1 { font-size: 1.6rem; line-height: 1.3; margin: 8px 0 4px; }
h2 { font-size: 1.1rem; margin: 0 0 8px; }
.sub { color: var(--ink-soft); margin: 0 0 20px; }
.hint { color: var(--ink-soft); font-size: 0.9rem; margin: 0 0 12px; }

/* 小夥伴卡片 */
.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.card {
  position: relative;
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 12px 14px;
  transition: border-color .15s, transform .15s;
}
.card.selected { border-color: var(--c); }

.pick {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  padding: 4px 0 0;
  background: none;
  border: 0;
  border-radius: 12px;
}
.pick:active { transform: scale(.97); }

.avatar { display: block; width: 76px; height: 76px; }
.avatar.small { width: 48px; height: 48px; flex: none; }
.card:not(.selected) .avatar { opacity: .75; }

.name { font-weight: 700; font-size: 1.05rem; margin-top: 4px; }
.emotion { color: var(--ink-soft); font-size: 0.85rem; }

.rename {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  background: none;
  border: 0;
  border-radius: 50%;
  color: var(--ink-soft);
}
.rename svg { width: 18px; height: 18px; }

.intensity { margin-top: 10px; }
.intensity[hidden] { display: none; }
.intensity label {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--ink-soft);
}
.intensity output { font-weight: 700; color: var(--ink); }
.intensity input[type="range"] {
  width: 100%;
  height: 32px;
  margin: 0;
  accent-color: var(--c);
}

/* 按鈕 */
.btn {
  min-height: 48px;
  padding: 0 20px;
  border-radius: 999px;
  border: 2px solid transparent;
  font-weight: 700;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:disabled { background: var(--line); color: var(--ink-soft); cursor: default; }
.btn.ghost { background: none; border-color: var(--line); }
.btn.block { display: block; width: 100%; margin-top: 20px; }
#submit {
  position: sticky;
  bottom: calc(var(--tabs-h) + 12px + env(safe-area-inset-bottom));
  box-shadow: 0 0 0 8px var(--bg);
}

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

/* 回應 */
.replies { display: flex; flex-direction: column; gap: 16px; margin-top: 20px; }
.reply { display: flex; gap: 12px; align-items: flex-start; }
.bubble {
  flex: 1;
  background: var(--surface);
  border: 2px solid var(--line);
  border-left: 6px solid var(--c);
  border-radius: 6px var(--radius) var(--radius) var(--radius);
  padding: 12px 14px;
}
.bubble .who { font-weight: 700; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.bubble p { margin: 4px 0 0; }

.dots { display: inline-flex; gap: 3px; }
.dots i {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--line);
}
.dots i.on { background: var(--c); }

/* 記錄 */
.day { margin-top: 24px; }
.day h2 { color: var(--ink-soft); font-size: 0.95rem; font-weight: 600; }
.entry {
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}
.entry time { color: var(--ink-soft); font-size: 0.85rem; }
.entry .reply { margin-top: 10px; }
.entry .bubble { border: 0; border-left: 4px solid var(--c); border-radius: 0; padding: 0 0 0 10px; }

.empty {
  text-align: center;
  color: var(--ink-soft);
  padding: 48px 16px;
}

/* 底部選單 */
.tabs {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  height: calc(var(--tabs-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--surface);
  border-top: 2px solid var(--line);
}
.tab {
  background: none;
  border: 0;
  font-weight: 700;
  color: var(--ink-soft);
}
.tab[aria-current="page"] { color: var(--accent); box-shadow: inset 0 3px 0 var(--accent); }

/* 改名視窗 */
dialog {
  width: min(92vw, 400px);
  border: 0;
  border-radius: var(--radius);
  padding: 20px;
  background: var(--surface);
  color: var(--ink);
}
dialog::backdrop { background: rgba(20, 14, 11, .55); }
dialog input[type="text"] {
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
}
.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 16px;
}
.dialog-actions .btn { padding: 0 16px; }

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