:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1a1d21;
  --text-muted: #6b7280;
  --border: #e2e4e8;
  --accent: #2f6f4f;
  --accent-text: #ffffff;
  --user-bubble: #2f6f4f;
  --user-bubble-text: #ffffff;
  --hayato-bubble: #ffffff;
  --hayato-bubble-text: #1a1d21;
  --error-bubble: #fdecec;
  --error-bubble-text: #9c2b2b;
  --status-ok: #2f6f4f;
  --status-bad: #b3392f;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --surface: #1d2025;
    --text: #eceef0;
    --text-muted: #9aa0a8;
    --border: #2c3036;
    --accent: #4f9d76;
    --accent-text: #0c1210;
    --user-bubble: #3a7a58;
    --user-bubble-text: #f2fbf6;
    --hayato-bubble: #262a30;
    --hayato-bubble-text: #eceef0;
    --error-bubble: #3a1f21;
    --error-bubble-text: #f4a5a1;
    --status-ok: #4f9d76;
    --status-bad: #e0776e;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Hiragino Sans", "Yu Gothic", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.6;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 760px;
  margin: 0 auto;
  background: var(--bg);
}

.app-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  /* Phase C2.1: standalone display (viewport-fit=cover in index.html) lets
     content draw under the notch/status bar/Dynamic Island -- without this,
     the header (incl. the "HAYATO" title) renders underneath it on iPhone. */
  padding: calc(0.9rem + env(safe-area-inset-top)) calc(1.1rem + env(safe-area-inset-right))
    0.9rem calc(1.1rem + env(safe-area-inset-left));
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.app-header__title {
  font-weight: 600;
  letter-spacing: 0.02em;
  font-size: 1.05rem;
}

.dashboard-link {
  flex: 0 0 auto;
  color: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1;
  padding: 0.3rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 0.4rem;
  text-decoration: none;
  white-space: nowrap;
}

.dashboard-link:hover,
.dashboard-link:focus-visible {
  background: var(--bg);
}

.profile-select {
  margin-left: auto;
  max-width: 9rem;
  font-size: 0.85rem;
  padding: 0.2rem 0.4rem;
  border-radius: 0.4rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: inherit;
}

.profile-select[hidden] {
  display: none;
}

.profile-pin-form {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1.1rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.profile-pin-form[hidden] {
  display: none;
}

.profile-pin-input {
  width: 8rem;
  font-size: 0.9rem;
  padding: 0.3rem 0.5rem;
  border-radius: 0.4rem;
  border: 1px solid var(--border);
  background: var(--bg);
  color: inherit;
}

.profile-pin-submit {
  font-size: 0.85rem;
  padding: 0.3rem 0.7rem;
  border-radius: 0.4rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: inherit;
  cursor: pointer;
}

.profile-pin-submit:disabled,
.profile-pin-input:disabled {
  opacity: 0.6;
  cursor: default;
}

.profile-pin-error {
  font-size: 0.8rem;
  color: var(--status-bad);
}

.download-button {
  flex: 0 0 auto;
  margin-left: auto;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 0.25rem 0.55rem;
  border-radius: 0.4rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: inherit;
  cursor: pointer;
}

.download-button:disabled {
  opacity: 0.45;
  cursor: default;
}

.status-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--text-muted);
  margin-left: 0.4rem;
  transition: background-color 0.2s ease;
}

.status-dot.ok {
  background: var(--status-ok);
}

.status-dot.bad {
  background: var(--status-bad);
}

.chat-log {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 1rem 1rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  -webkit-overflow-scrolling: touch;
}

.bubble-row {
  display: flex;
  width: 100%;
}

.bubble-row.user {
  justify-content: flex-end;
}

.bubble-row.hayato,
.bubble-row.error {
  justify-content: flex-start;
}

.bubble {
  max-width: 82%;
  padding: 0.55rem 0.85rem;
  border-radius: 1rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.bubble-row.user .bubble {
  background: var(--user-bubble);
  color: var(--user-bubble-text);
  border-bottom-right-radius: 0.3rem;
}

.bubble-row.hayato .bubble {
  background: var(--hayato-bubble);
  color: var(--hayato-bubble-text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 0.3rem;
}

.bubble-row.error .bubble {
  background: var(--error-bubble);
  color: var(--error-bubble-text);
  border-bottom-left-radius: 0.3rem;
  font-size: 0.92rem;
}

.bubble.loading {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 0.7rem 0.9rem;
}

.loading-dots {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.loading-dots span {
  width: 0.4rem;
  height: 0.4rem;
  border-radius: 50%;
  background: var(--text-muted);
  animation: pulse 1.1s infinite ease-in-out;
}

.loading-dots span:nth-child(2) {
  animation-delay: 0.15s;
}

.loading-dots span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes pulse {
  0%,
  80%,
  100% {
    opacity: 0.25;
    transform: scale(0.8);
  }
  40% {
    opacity: 1;
    transform: scale(1);
  }
}

.chat-form {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.75rem calc(1rem + env(safe-area-inset-right))
    calc(0.75rem + env(safe-area-inset-bottom)) calc(1rem + env(safe-area-inset-left));
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.chat-input {
  flex: 1 1 auto;
  resize: none;
  max-height: 8rem;
  min-height: 2.6rem;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 0.85rem;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  line-height: 1.4;
}

.chat-input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.mic-button {
  flex: 0 0 auto;
  width: 2.6rem;
  height: 2.6rem;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.mic-button__icon {
  width: 0.85rem;
  height: 0.85rem;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.7;
}

.mic-button.recording {
  background: var(--status-bad);
  border-color: var(--status-bad);
  color: #fff;
  animation: mic-pulse 1.2s infinite ease-in-out;
}

.mic-button.recording .mic-button__icon {
  opacity: 1;
}

.mic-button.processing {
  opacity: 0.5;
  cursor: default;
}

@keyframes mic-pulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(179, 57, 47, 0.35);
  }
  50% {
    box-shadow: 0 0 0 0.4rem rgba(179, 57, 47, 0);
  }
}

.loading-label {
  display: block;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.chat-send {
  flex: 0 0 auto;
  padding: 0.6rem 1.1rem;
  border: none;
  border-radius: 0.85rem;
  background: var(--accent);
  color: var(--accent-text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.chat-send:disabled {
  opacity: 0.5;
  cursor: default;
}

.chat-send:not(:disabled):hover {
  filter: brightness(1.05);
}

@media (max-width: 480px) {
  .app {
    max-width: 100%;
  }

  .app-header {
    gap: 0.35rem;
    padding-right: calc(0.75rem + env(safe-area-inset-right));
    padding-left: calc(0.75rem + env(safe-area-inset-left));
  }

  .dashboard-link {
    font-size: 0.7rem;
    padding: 0.25rem 0.4rem;
  }

  .profile-select {
    max-width: 7rem;
  }

  .bubble {
    max-width: 88%;
  }
}

/* Unified HAYATO shell: Market / Dashboardと同じダークな操作面にそろえる。 */
:root {
  color-scheme: dark;
  --bg: #070b12;
  --surface: #101925;
  --text: #e9f0fb;
  --text-muted: #8492a7;
  --border: #263b53;
  --accent: #42d6d0;
  --accent-text: #07111a;
  --user-bubble: #146b83;
  --user-bubble-text: #f3fdff;
  --hayato-bubble: #101d2c;
  --hayato-bubble-text: #e9f0fb;
  --error-bubble: #341921;
  --error-bubble-text: #ff9baa;
  --status-ok: #36c991;
  --status-bad: #fa6276;
}

body {
  background: radial-gradient(circle at 55% -30%, #15283d 0, #070b12 42%);
  font-family: Inter, "Segoe UI", "Hiragino Sans", "Yu Gothic", system-ui, sans-serif;
}

.app {
  max-width: 960px;
  background: linear-gradient(145deg, #0b121d, #070b12);
  border-right: 1px solid rgb(38 59 83 / 55%);
  border-left: 1px solid rgb(38 59 83 / 55%);
}

.app-header {
  min-height: 64px;
  gap: 0.7rem;
  padding-top: calc(0.7rem + env(safe-area-inset-top));
  padding-bottom: 0.7rem;
  border-color: var(--border);
  background: rgb(9 14 22 / 92%);
  box-shadow: 0 7px 24px rgb(0 0 0 / 18%);
}

.app-brand {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--text);
  text-decoration: none;
  letter-spacing: 0.08em;
  line-height: 1;
}

.app-brand__mark {
  display: grid;
  width: 1.85rem;
  height: 1.85rem;
  place-items: center;
  color: #06141d;
  font-size: 0.76rem;
  font-weight: 900;
  background: linear-gradient(135deg, var(--accent), #497df2);
  clip-path: polygon(50% 0, 100% 100%, 50% 70%, 0 100%);
}

.app-brand small,
.app-brand strong { display: block; }
.app-brand small { color: var(--accent); font-size: 0.53rem; font-weight: 900; }
.app-brand strong { margin-top: 0.16rem; font-size: 0.88rem; font-weight: 850; }

.app-nav { display: flex; gap: 0.2rem; align-items: center; }
.app-nav a {
  padding: 0.34rem 0.44rem;
  color: var(--text-muted);
  border: 1px solid transparent;
  border-radius: 0.35rem;
  font-size: 0.72rem;
  font-weight: 750;
  letter-spacing: 0.02em;
  text-decoration: none;
}
.app-nav a:hover,
.app-nav a:focus-visible { color: var(--text); border-color: var(--border); background: #142238; }

.profile-select { max-width: 8.5rem; border-color: #334a65; background: #101b29; color: var(--text); }
.download-button { border-color: #334a65; background: #142238; color: #b9c7db; font-size: 0.67rem; }
.download-button:not(:disabled):hover { border-color: var(--accent); color: var(--accent); }
.status-dot { margin-left: 0; box-shadow: 0 0 9px currentColor; }
.profile-pin-form,
.chat-form { border-color: var(--border); background: rgb(9 14 22 / 94%); }
.profile-pin-input,
.profile-pin-submit,
.chat-input,
.mic-button { border-color: #334a65; background: #0d1723; color: var(--text); }
.profile-pin-submit:hover,
.mic-button:hover { border-color: var(--accent); }

.voice-welcome {
  margin: 1rem 1rem 0;
  padding: 1.25rem;
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  background: radial-gradient(circle at 86% 5%, rgb(66 214 208 / 16%), transparent 42%), linear-gradient(145deg, #101d2c, #0c141f);
  box-shadow: 0 12px 26px rgb(0 0 0 / 18%);
}
.voice-welcome[hidden] { display: none; }
.voice-welcome__eyebrow { color: var(--accent); font-size: 0.62rem; font-weight: 900; letter-spacing: 0.14em; }
.voice-welcome h1 { margin: 0.45rem 0; font-size: clamp(1.38rem, 4.5vw, 2rem); line-height: 1.2; letter-spacing: -0.04em; }
.voice-welcome p { max-width: 40rem; margin: 0; color: var(--text-muted); font-size: 0.86rem; }
.voice-welcome__actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 1rem; }
.voice-prompt { padding: 0.42rem 0.65rem; color: #b9c7db; border: 1px solid #334a65; border-radius: 0.35rem; background: #142238; font: inherit; font-size: 0.76rem; font-weight: 700; cursor: pointer; }
.voice-prompt:hover,
.voice-prompt:focus-visible { color: var(--accent); border-color: var(--accent); }

.chat-log { gap: 0.8rem; padding: 1rem; }
.bubble { padding: 0.68rem 0.86rem; border-radius: 0.55rem; box-shadow: 0 6px 16px rgb(0 0 0 / 10%); }
.bubble-row.user .bubble { background: linear-gradient(135deg, #126881, #185576); border-bottom-right-radius: 0.16rem; }
.bubble-row.hayato .bubble { border-color: #2a405a; border-bottom-left-radius: 0.16rem; }
.chat-input { border-radius: 0.55rem; }
.chat-send { border-radius: 0.45rem; background: linear-gradient(135deg, var(--accent), #50a7eb); color: #06111a; }

@media (max-width: 600px) {
  .app { border: 0; }
  .app-header { flex-wrap: wrap; }
  .app-nav { order: 5; flex-basis: 100%; }
  .app-nav a { flex: 1 1 0; text-align: center; }
  .profile-select { max-width: 6.5rem; }
  .voice-welcome { margin: 0.75rem 0.75rem 0; padding: 1rem; }
  .chat-log { padding: 0.75rem; }
}
