:root {
  --bg: #f6f1e6;
  --ink: #243044;
  --muted: #5c6a78;
  --line: #e3d9c8;
  --card: #fffdf8;
  --leaf: #3d6d8c;
  --leaf-dark: #2a4a62;
  --leaf-soft: #e7f2f8;
  --cream: #f8f1e4;
  --maple: #b85a48;
  --new: #9a4e22;
  --new-bg: #fff1e4;
  --wait: #5c6858;
  --wait-bg: #eef2ea;
  --done: #6d675c;
  --done-bg: #efece4;
  --err: #9c3b32;
  --shadow: 0 8px 24px rgba(36, 64, 44, 0.08);
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: #e7eef3;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  font-size: 17px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}
.phone {
  width: min(480px, 100%);
  margin: 0 auto;
  min-height: 100dvh;
  background: var(--bg);
  box-shadow: 0 0 0 1px rgba(30, 70, 52, 0.08);
}
.stage { display: contents; }
.narrow-view {
  width: min(480px, 100%);
  margin: 0 auto;
  min-height: 100dvh;
  background: var(--bg);
}
.hidden { display: none !important; }
.view { min-height: 100dvh; display: flex; flex-direction: column; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: var(--leaf-dark);
  color: #f4f7f0;
}
.brand { display: flex; align-items: center; gap: 6px; min-width: 0; }
.top-title { font-weight: 700; font-size: 1.05rem; }
.spacer { flex: 1; }
.text-btn, .who-chip, .done-btn, .icon-btn, button { font: inherit; cursor: pointer; }
.text-btn {
  background: transparent;
  color: #f4f7f0;
  border: 0;
  padding: 8px 4px;
  min-height: 44px;
}
.secret-box {
  background: var(--cream);
  border-radius: 14px;
  padding: 12px 14px;
  margin: 12px 0;
  word-break: break-all;
}
.user-row { display: flex; flex-direction: column; gap: 8px; align-items: stretch; }
.user-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.user-actions button { flex: 1 1 120px; background: var(--cream); color: var(--leaf-dark); min-height: 44px; white-space: nowrap; }
.who-chip {
  margin-left: auto;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  border: 0;
  border-radius: 999px;
  padding: 6px 12px;
  max-width: 42%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.done-btn {
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: transparent;
  color: #fff;
  border-radius: 999px;
  padding: 6px 12px;
  min-height: 36px;
}
.done-btn:disabled { opacity: 0.65; }
.thread-title {
  flex: 1;
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.gate { padding: 28px 22px 40px; }
.mark { font-size: 2rem; margin: 12px 0 0; }
.mark.small { font-size: 1.15rem; }
h1 { font-size: 1.55rem; margin: 8px 0; letter-spacing: -0.02em; }
.lede { color: var(--muted); margin: 0 0 18px; }
.field-label { display: block; font-size: 0.92rem; margin: 14px 0 6px; color: var(--leaf-dark); }
input[type=password], input[type=text], textarea {
  width: 100%;
  font: inherit;
  font-size: 16px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
}
textarea { resize: vertical; min-height: 120px; line-height: 1.5; }
button { border: 0; border-radius: 14px; }
button:disabled { opacity: 0.55; }
.primary { background: var(--leaf); color: #fff; }
.primary:active { background: var(--leaf-dark); }
.wide { width: 100%; padding: 14px; min-height: 48px; margin-top: 14px; }
.error { color: var(--err); min-height: 1.3em; margin: 10px 0 0; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 0.85rem; margin: 8px 0 0; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips button {
  background: var(--leaf-soft);
  color: var(--leaf-dark);
  padding: 10px 14px;
  border-radius: 999px;
  min-height: 44px;
}
.home-body { padding: 14px 14px 32px; }
.ask { margin-top: 0; }
.status-line { text-align: center; color: var(--muted); margin: 8px 0; }
.cards { display: flex; flex-direction: column; gap: 12px; }
.qcard {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px 14px 12px;
  box-shadow: var(--shadow);
  color: inherit;
}
.card-top, .card-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.badge {
  display: inline-block;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 0.78rem;
  font-weight: 700;
}
.badge.new { background: #f8ebe6; color: var(--maple); }
.badge.ok { background: var(--leaf-soft); color: var(--leaf); }
.badge.wait { background: var(--wait-bg); color: var(--wait); }
.badge.done { background: var(--done-bg); color: var(--done); }
.when { color: var(--muted); font-size: 0.82rem; }
.qcard h2 { font-size: 1.08rem; margin: 8px 0 4px; letter-spacing: -0.02em; }
.preview {
  margin: 0 0 10px;
  color: #3e5144;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.who { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 0.9rem; }
.avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--leaf-soft); color: var(--leaf-dark);
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.85rem;
}
.empty-card, .status-line button.retry {
  background: transparent;
  color: var(--leaf);
  text-decoration: underline;
  padding: 8px;
}
.empty-card {
  background: var(--card);
  border: 1px dashed var(--line);
  border-radius: 18px;
  padding: 28px 16px;
  text-align: center;
  text-decoration: none;
  color: var(--ink);
}
.empty-card strong { display: block; margin-bottom: 6px; }
.sheet { padding: 8px 16px 28px; }
.photo-row { display: flex; align-items: center; justify-content: space-between; margin-top: 12px; }
.photo-add, .icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 8px 12px;
  background: var(--cream);
  color: var(--leaf-dark);
  border-radius: 12px;
}
.previews { display: flex; gap: 8px; overflow-x: auto; padding: 8px 0; align-items: stretch; }
.file-chip {
  position: relative;
  flex: 0 0 auto;
  max-width: 168px;
  background: var(--cream);
  border-radius: 12px;
  padding: 8px 28px 8px 10px;
}
.file-chip button {
  position: absolute; top: 4px; right: 4px;
  width: 26px; height: 26px; border-radius: 50%;
  background: #fff; color: var(--ink);
  box-shadow: 0 1px 4px rgba(0,0,0,.18);
  padding: 0;
}
.file-chip strong, .file-chip span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.8rem;
}
.char-count { margin: 4px 0 0; text-align: right; color: var(--muted); font-size: 0.8rem; }
.char-count.over { color: var(--err); font-weight: 700; }
.upload-line { color: var(--leaf); font-size: 0.9rem; margin: 6px 0; }
.upload-line .bar { height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; margin-top: 4px; }
.upload-line .bar i { display: block; height: 100%; width: 0; background: var(--leaf); }
.file-card {
  display: block;
  text-decoration: none;
  color: inherit;
  background: var(--cream);
  border-radius: 12px;
  padding: 10px 12px;
  margin: 6px 0;
}
.file-card .file-name { font-weight: 700; word-break: break-all; }
.file-meta, .file-state { display: block; color: var(--muted); font-size: 0.85rem; margin-top: 2px; }
.file-state.file-error { color: var(--err); }
audio.voice { width: 100%; margin: 6px 0; }
.thumb { position: relative; flex: 0 0 auto; }
.thumb img { width: 72px; height: 72px; object-fit: cover; border-radius: 12px; background: #ddd; }
.thumb button {
  position: absolute; top: -6px; right: -6px;
  width: 26px; height: 26px; border-radius: 50%;
  background: #fff; color: var(--ink);
  box-shadow: 0 1px 4px rgba(0,0,0,.18);
  padding: 0;
}
#thread-view { height: 100dvh; min-height: 100dvh; }
.banner {
  margin: 0;
  padding: 8px 14px;
  background: var(--done-bg);
  color: var(--done);
  font-size: 0.9rem;
}
.msgs { flex: 1; overflow-y: auto; padding: 14px 12px 8px; -webkit-overflow-scrolling: touch; }
.bubble {
  max-width: 86%;
  margin: 8px 0;
  padding: 10px 12px;
  border-radius: 16px;
  word-break: break-word;
}
.bubble.family { margin-left: auto; background: var(--leaf-soft); border-bottom-right-radius: 5px; }
.bubble.bot { margin-right: auto; background: #fff; border: 1px solid var(--line); border-bottom-left-radius: 5px; }
.bubble .name { font-size: 0.78rem; font-weight: 700; color: var(--leaf-dark); margin-bottom: 4px; }
.bubble .text { white-space: pre-wrap; }
.bubble.bot .text { white-space: normal; }
.bubble .text p { margin: 0.35em 0; }
.bubble .text ul, .bubble .text ol { margin: 0.35em 0; padding-left: 1.2em; }
.bubble .text pre { background: var(--leaf-dark); color: #f4f7f0; padding: 8px; border-radius: 8px; overflow-x: auto; font-size: 0.85rem; }
.bubble .text code { background: var(--cream); padding: 0 4px; border-radius: 4px; }
.bubble .text pre code { background: none; padding: 0; color: inherit; }
.bubble .text a { color: var(--leaf); }
.photos { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 6px; }
.photo-hit {
  display: block;
  width: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  border-radius: 10px;
  touch-action: manipulation;
  cursor: zoom-in;
}
.photos img { width: 100%; max-width: 100%; border-radius: 10px; max-height: 220px; object-fit: cover; background: #eee; }
.bubble.bot .photos { grid-template-columns: 1fr; }
.bubble.bot .photos img { max-height: none; height: auto; object-fit: contain; background: #fff; }
.bubble .text table { width: 100%; border-collapse: collapse; margin: 0.4em 0; font-size: 0.92rem; }
.bubble .text th, .bubble .text td { border: 1px solid var(--line); padding: 4px 6px; text-align: left; }
.bubble .text .katex-display { overflow-x: auto; overflow-y: hidden; max-width: 100%; }
.typing-dots { display: flex; gap: 5px; padding: 8px 2px; }
.typing-dots i {
  width: 7px; height: 7px; border-radius: 50%; background: #2f6b4f;
  display: block; animation: dotpulse 1.1s infinite ease-in-out;
}
.typing-dots i:nth-child(2) { animation-delay: .15s; }
.typing-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes dotpulse { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-2px); } }
.drawing { color: var(--muted); font-size: .9rem; margin-top: 6px; }
.working-line { color: var(--leaf); font-size: .85rem; margin: 0 0 8px; }
.lightbox {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(18, 32, 24, 0.92);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 16px;
  padding-top: max(16px, env(safe-area-inset-top));
}
.lightbox-bar {
  position: absolute; top: max(12px, env(safe-area-inset-top)); left: 12px; right: 12px;
  display: flex; justify-content: space-between; gap: 8px; z-index: 2;
}
.lightbox-bar .primary { min-height: 44px; min-width: 88px; margin: 0; }
.lightbox-bar .text-btn { color: #fff; min-height: 44px; }
.lightbox img { max-width: min(100%, 420px); max-height: 78dvh; width: auto; height: auto; border-radius: 8px; background: #fff; }
.confirm {
  position: fixed; inset: 0; z-index: 45;
  background: rgba(18, 32, 24, 0.55);
  display: flex; align-items: center; justify-content: center; padding: 18px;
}
.confirm-box { background: #fff; border-radius: 18px; padding: 18px; width: min(100%, 360px); }
.confirm-actions { display: flex; gap: 8px; margin-top: 14px; }
.confirm-actions button { flex: 1; min-height: 48px; }
.danger { background: #9c3b32; color: #fff; }
.card-open { display: block; width: 100%; text-align: left; background: transparent; padding: 0; border-radius: 0; }
.text-del { margin-top: 6px; background: transparent; color: #9c3b32; padding: 8px 0; min-height: 44px; }
.delivered, .bubble .when { font-size: 0.75rem; color: var(--muted); margin-top: 4px; }
.bubble.family .delivered, .bubble.family .when { text-align: right; }
.composer {
  background: #fff;
  border-top: 1px solid var(--line);
  padding: 8px 8px max(8px, env(safe-area-inset-bottom));
}
.composer-row { display: flex; align-items: flex-end; gap: 6px; }
.composer textarea {
  flex: 1;
  min-height: 44px;
  max-height: 140px;
  padding: 10px 12px;
  resize: none;
}
.send { min-height: 44px; padding: 10px 14px; margin: 0; width: auto; }
.icon-btn { padding: 0 8px; min-width: 44px; font-size: 0.85rem; }
.pad { padding: 16px; text-align: center; }
.toast {
  position: fixed;
  left: 50%;
  bottom: max(110px, calc(env(safe-area-inset-bottom) + 96px));
  transform: translateX(-50%);
  background: var(--leaf-dark);
  color: #fff;
  padding: 12px 16px;
  border-radius: 14px;
  z-index: 20;
  max-width: min(90vw, 420px);
  text-align: center;
}
button:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 3px solid #8fbf9a;
  outline-offset: 2px;
}
@media (hover: hover) {
  .qcard:hover { border-color: #b7d0b4; }
}
@media (max-width: 360px) {
  h1 { font-size: 1.35rem; }
  .qcard h2 { font-size: 1rem; }
}

#login-view {
  background: linear-gradient(180deg, #d5e6f2 0%, var(--bg) 280px);
  padding-bottom: max(28px, env(safe-area-inset-bottom));
}
.launch { padding: 12px 0 8px; }
.hero-block { padding: 0 16px; }
.hero {
  position: relative;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: 22px;
  background: #d5e4ef;
  box-shadow: 0 14px 32px rgba(42, 74, 98, 0.16);
}
.hero img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 38%;
  display: block;
  filter: saturate(0.9);
}
.hero-fade {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 32%;
  background: linear-gradient(180deg, rgba(246, 241, 230, 0) 0%, var(--bg) 96%);
  pointer-events: none;
}
.hero-title {
  margin: 16px 8px 0;
  text-align: center;
  font-size: clamp(1.7rem, 6vw, 2.5rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.2;
  color: #2a4a62;
  background-image: linear-gradient(180deg, #2a4a62 0%, #3d6d8c 72%, #8d5344 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.launch-card { padding: 6px 22px 12px; }
.guide {
  display: grid;
  gap: 18px;
  padding: 8px 16px 12px;
}
.guide-block {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px 14px 8px;
}
.guide h2 { margin: 0 0 8px; font-size: 1.05rem; }
.guide-list { list-style: none; margin: 0; padding: 0; }
.guide-list li {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 8px 0;
  border-top: 1px solid var(--line);
}
.guide-icon {
  flex: 0 0 1.6rem;
  text-align: center;
  line-height: 1.4;
}
.user-meta { display: block; margin: 6px 0 0; }
#pw-view {
  width: 100%;
  background: linear-gradient(180deg, #d5e6f2 0%, var(--bg) 320px);
}
.pw-card {
  width: min(480px, calc(100% - 28px));
  margin: 18px auto 28px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: 0 14px 32px rgba(42, 74, 98, 0.12);
}
#admin-view { width: 100%; background: var(--bg); }
.admin-layout { padding: 14px 14px 32px; }
.admin-form {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 4px 14px 16px;
  margin-bottom: 14px;
}
.qcard.is-open { border-color: var(--leaf); box-shadow: 0 0 0 2px rgba(47, 107, 79, 0.28); }
.desk-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  padding: 32px;
  text-align: center;
}

@media (min-width: 900px) {
  body { font-size: 18px; }
  .launch {
    display: grid;
    grid-template-columns: minmax(0, 1.45fr) minmax(280px, 0.7fr);
    gap: 28px;
    align-items: center;
    max-width: 1100px;
    margin: 0 auto;
    padding: 28px 28px 8px;
  }
  .hero { aspect-ratio: 16 / 9; }
  .launch-card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 22px;
    padding: 22px 22px 18px;
    box-shadow: var(--shadow);
  }
  .guide {
    max-width: 1100px;
    margin: 0 auto;
    padding: 8px 28px 36px;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
  }
  body.split .phone {
    width: min(1200px, calc(100% - 32px));
    margin: 16px auto;
    height: calc(100dvh - 32px);
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
    border-radius: 18px;
    overflow: hidden;
  }
  body.split .stage {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    background: var(--bg);
  }
  body.split #home-view,
  body.split .stage > .view {
    min-height: 0;
    height: 100%;
  }
  body.split #home-view { border-right: 1px solid var(--line); }
  body.split .home-body { flex: 1; overflow: auto; }
  body.split #thread-view { height: 100%; min-height: 0; }
  body.split .sheet { max-width: 760px; padding: 18px 28px 36px; }
  body.split .msgs { padding: 22px 28px 12px; }
  body.split .bubble { max-width: min(720px, 92%); }
  body.split .photos img { max-height: 420px; }
  body.split audio.voice,
  body.split .file-card { max-width: 560px; }
  body.split .composer { padding-left: 20px; padding-right: 20px; }
  .lightbox img { max-width: min(92vw, 960px); }
  .pw-card { align-self: center; margin-top: 48px; }
  #admin-view { background: #e7eef3; }
  .admin-layout {
    width: min(1200px, calc(100% - 32px));
    margin: 20px auto 32px;
    padding: 0;
    display: grid;
    grid-template-columns: minmax(280px, 380px) minmax(0, 1fr);
    gap: 20px;
    align-items: start;
  }
  .admin-form { margin-bottom: 0; }
  .admin-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
}
