/* 縁側 — engawa guest lounge. Quiet, warm, generous whitespace. */

:root {
  --bg: #f4efe4;
  --surface: #fffdf7;
  --surface-2: #efe8d8;
  --ink: #322f28;
  --ink-soft: #6f685b;
  --ink-faint: #98917f;
  --accent: #8a6d47;
  --accent-ink: #6d552f;
  --line: rgba(50, 40, 20, 0.10);
  --guest-bubble: #e7dec9;
  --guest-ink: #3a352b;
  --host-bubble: #fffdf7;
  --host-ink: #322f28;
  --danger: #a8503a;
  --radius: 14px;
  --radius-lg: 20px;
  --font: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN",
          "Noto Sans JP", "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1e1b17;
    --surface: #282420;
    --surface-2: #322d27;
    --ink: #ece4d5;
    --ink-soft: #b0a794;
    --ink-faint: #857d6d;
    --accent: #c8a878;
    --accent-ink: #e2c9a2;
    --line: rgba(255, 250, 235, 0.10);
    --guest-bubble: #3a342b;
    --guest-ink: #ece4d5;
    --host-bubble: #2f2a24;
    --host-ink: #ece4d5;
    --danger: #d98868;
  }
}

:root[data-theme="light"] {
  --bg: #f4efe4; --surface: #fffdf7; --surface-2: #efe8d8; --ink: #322f28;
  --ink-soft: #6f685b; --ink-faint: #98917f; --accent: #8a6d47; --accent-ink: #6d552f;
  --line: rgba(50, 40, 20, 0.10); --guest-bubble: #e7dec9; --guest-ink: #3a352b;
  --host-bubble: #fffdf7; --host-ink: #322f28; --danger: #a8503a;
}
:root[data-theme="dark"] {
  --bg: #1e1b17; --surface: #282420; --surface-2: #322d27; --ink: #ece4d5;
  --ink-soft: #b0a794; --ink-faint: #857d6d; --accent: #c8a878; --accent-ink: #e2c9a2;
  --line: rgba(255, 250, 235, 0.10); --guest-bubble: #3a342b; --guest-ink: #ece4d5;
  --host-bubble: #2f2a24; --host-ink: #ece4d5; --danger: #d98868;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  line-height: 1.65;
}

/* App fills the visible viewport; JS keeps --app-h synced to visualViewport on iOS. */
.app {
  height: var(--app-h, 100dvh);
  min-height: -webkit-fill-available;
  display: flex;
  flex-direction: column;
  max-width: 720px;
  margin: 0 auto;
}
.view { display: flex; flex-direction: column; flex: 1; min-height: 0; }
[hidden] { display: none !important; }

/* ── login ── */
.view-login { justify-content: center; align-items: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: 36px 28px 30px; text-align: center;
}
.mark {
  width: 56px; height: 56px; margin: 0 auto 14px; border-radius: 50%;
  background: var(--surface-2); color: var(--accent-ink);
  display: flex; align-items: center; justify-content: center;
  font-size: 26px; font-weight: 500;
}
.login-title { margin: 0 0 4px; font-size: 26px; font-weight: 500; letter-spacing: 0.04em; }
.login-sub { margin: 0 0 26px; color: var(--ink-soft); font-size: 15px; }
.field { display: block; text-align: left; margin-bottom: 16px; }
.field-label { display: block; font-size: 13px; color: var(--ink-soft); margin-bottom: 6px; }
input, textarea {
  font-family: inherit; font-size: 16px; color: var(--ink);
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius);
  width: 100%; padding: 13px 15px; outline: none; -webkit-appearance: none;
}
input:focus, textarea:focus { border-color: var(--accent); }
.error { color: var(--danger); font-size: 14px; margin: 0 0 14px; text-align: center; }

.btn {
  font-family: inherit; font-size: 16px; border: none; border-radius: var(--radius);
  cursor: pointer; -webkit-tap-highlight-color: transparent; transition: opacity .12s, transform .05s;
}
.btn:active { transform: scale(0.985); }
.btn-primary {
  width: 100%; padding: 15px; background: var(--accent); color: #fffdf7;
  font-weight: 500; margin-top: 6px; min-height: 52px;
}
@media (prefers-color-scheme: dark) { .btn-primary { color: #241f18; } }
:root[data-theme="dark"] .btn-primary { color: #241f18; }
.btn:disabled { opacity: 0.5; cursor: default; }

.foot {
  margin-top: 22px; color: var(--ink-faint); font-size: 12px; text-align: center;
  padding-bottom: env(safe-area-inset-bottom);
}
.foot-quiet { margin: 8px 0 0; padding: 12px 0 calc(12px + env(safe-area-inset-bottom)); }

/* ── top bar (chat + history) ── */
.bar {
  position: relative; display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; padding-top: calc(12px + env(safe-area-inset-top));
  border-bottom: 1px solid var(--line); background: var(--surface); min-height: 52px;
}
.bar-title { font-size: 17px; font-weight: 500; letter-spacing: 0.04em; }
.bar-actions { display: flex; gap: 14px; align-items: center; }
.link {
  background: none; border: none; color: var(--accent-ink); font-family: inherit;
  font-size: 15px; cursor: pointer; padding: 8px; min-height: 40px;
  -webkit-tap-highlight-color: transparent;
}
.menu {
  position: absolute; top: calc(100% - 4px); right: 12px; z-index: 20;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 6px; min-width: 168px; box-shadow: 0 8px 26px rgba(0,0,0,0.14);
}
.menu-item {
  display: block; width: 100%; text-align: left; background: none; border: none;
  font-family: inherit; font-size: 15px; color: var(--ink); padding: 12px 14px;
  border-radius: 10px; cursor: pointer;
}
.menu-item:active { background: var(--surface-2); }

/* ── messages ── */
.messages {
  flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 18px 16px 8px; display: flex; flex-direction: column; gap: 12px;
}
.row { display: flex; }
.row.guest { justify-content: flex-end; }
.row.host { justify-content: flex-start; }
.bubble {
  max-width: 82%; padding: 11px 15px; border-radius: 18px; font-size: 16px;
  word-wrap: break-word; overflow-wrap: anywhere;
}
.row.guest .bubble { background: var(--guest-bubble); color: var(--guest-ink); border-bottom-right-radius: 6px; }
.row.host .bubble { background: var(--host-bubble); color: var(--host-ink); border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.bubble p { margin: 0 0 8px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble pre { background: var(--surface-2); padding: 10px 12px; border-radius: 10px; overflow-x: auto; }
.bubble code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 14px; }
.bubble a { color: var(--accent-ink); }
.bubble ul, .bubble ol { margin: 4px 0; padding-left: 20px; }
.typing { color: var(--ink-faint); font-size: 15px; padding: 4px 4px 6px; }
.notice { text-align: center; color: var(--ink-faint); font-size: 13px; padding: 8px; }

/* ── composer ── */
.composer {
  display: flex; align-items: flex-end; gap: 10px; padding: 10px 12px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line); background: var(--surface);
}
.input {
  flex: 1; resize: none; max-height: 140px; border-radius: 20px; padding: 12px 16px;
  line-height: 1.4;
}
.btn-send {
  flex: 0 0 auto; width: 46px; height: 46px; border-radius: 50%; background: var(--accent);
  color: #fffdf7; font-size: 20px; display: flex; align-items: center; justify-content: center;
}
@media (prefers-color-scheme: dark) { .btn-send { color: #241f18; } }
:root[data-theme="dark"] .btn-send { color: #241f18; }

/* ── history ── */
.history-body { flex: 1; overflow-y: auto; padding: 16px; }
.visit-block { margin-bottom: 26px; }
.visit-head {
  font-size: 13px; color: var(--ink-soft); margin-bottom: 10px;
  padding-bottom: 6px; border-bottom: 1px solid var(--line);
}
.visit-block .row { margin-bottom: 8px; }
.history-empty { text-align: center; color: var(--ink-faint); padding: 48px 16px; font-size: 15px; }
