/* 福祉フォロー通訳 — 共通スタイル
 * 方針: 大きな文字・大きなボタン・状態が色で分かる(青=待機 / 緑=話して / 黄=翻訳中 / 赤=エラー) */

:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --ink: #1b2430;
  --muted: #5f6b7a;
  --line: #d9dee5;
  --primary: #1f5fbf;
  --primary-ink: #ffffff;
  --state-idle: #1f5fbf;
  --state-listen: #1f9d55;
  --state-translate: #e2a400;
  --state-error: #d64545;
  --bubble-staff: #e3ecfa;
  --bubble-client: #e8f6ec;
  --radius: 18px;
  --font-xxl: clamp(28px, 4.2vw, 48px);
  --font-xl: clamp(22px, 3vw, 34px);
  --font-lg: clamp(18px, 2.2vw, 26px);
  --font-md: clamp(16px, 1.8vw, 20px);
}

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

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family:
    'Hiragino Sans',
    'Hiragino Kaku Gothic ProN',
    'Noto Sans JP',
    'Noto Sans',
    'Segoe UI',
    system-ui,
    -apple-system,
    sans-serif;
  font-size: var(--font-md);
  line-height: 1.5;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-text-size-adjust: 100%;
}

button {
  font: inherit;
  cursor: pointer;
  border: 0;
  border-radius: var(--radius);
  padding: 0.8em 1.4em;
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
  touch-action: manipulation;
}
button:disabled {
  opacity: 0.5;
  cursor: default;
}
button.primary {
  background: var(--primary);
  color: var(--primary-ink);
}
button.danger {
  background: var(--state-error);
  color: #fff;
}
button.ghost {
  background: transparent;
  box-shadow: none;
  color: var(--muted);
}
button.big {
  font-size: var(--font-xl);
  padding: 0.9em 1.6em;
  border-radius: 28px;
}

.hidden {
  display: none !important;
}

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom)
    env(safe-area-inset-left);
}

/* ---- 開始画面 ---- */
.start {
  align-items: center;
  justify-content: center;
  gap: 32px;
  padding: 24px;
  overflow-y: auto;
}
.start h1 {
  margin: 0;
  font-size: var(--font-lg);
  color: var(--muted);
  font-weight: 600;
}
.start .facility {
  font-size: var(--font-md);
  color: var(--muted);
}
.lang-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 14px;
  width: min(1000px, 100%);
}
.lang-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: var(--font-lg);
  padding: 16px 18px;
  border: 3px solid transparent;
  text-align: left;
}
.lang-btn .flag {
  font-size: 1.6em;
}
.lang-btn.selected {
  border-color: var(--primary);
  background: var(--bubble-staff);
}
.lang-btn small {
  display: block;
  font-size: 0.6em;
  color: var(--muted);
}

/* ---- 会話画面 ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  font-size: var(--font-md);
}
.topbar .lang {
  font-size: var(--font-lg);
  font-weight: 700;
}
.topbar button,
.topbar .peer {
  white-space: nowrap;
}
.topbar .peer {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
}
.topbar .peer::before {
  content: '';
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--state-error);
}
.topbar .peer.on::before {
  background: var(--state-listen);
}

.statusbar {
  padding: 12px 18px;
  text-align: center;
  color: #fff;
  font-weight: 700;
  font-size: var(--font-lg);
  background: var(--state-idle);
  transition: background 0.2s;
}
.statusbar[data-phase='listening'] {
  background: var(--state-listen);
}
.statusbar[data-phase='translating'] {
  background: var(--state-translate);
}
.statusbar[data-phase='error'] {
  background: var(--state-error);
}
.statusbar[data-phase='speaking'] {
  background: var(--state-idle);
}

.history {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  -webkit-overflow-scrolling: touch;
}
.msg {
  max-width: 88%;
  padding: 14px 18px;
  border-radius: var(--radius);
  background: var(--bubble-client);
  align-self: flex-start;
  position: relative;
}
.msg.staff {
  background: var(--bubble-staff);
  align-self: flex-end;
}
.msg .who {
  font-size: 0.75em;
  color: var(--muted);
  margin-bottom: 4px;
}
.msg .main {
  font-size: var(--font-lg);
  font-weight: 600;
  overflow-wrap: anywhere;
}
.msg .sub {
  font-size: 0.85em;
  color: var(--muted);
  margin-top: 6px;
  overflow-wrap: anywhere;
}
.msg.important {
  outline: 3px solid var(--state-translate);
}
.msg .tools {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}
.msg .tools button {
  font-size: 0.8em;
  padding: 0.4em 0.9em;
  border-radius: 12px;
}
.msg .badge {
  display: inline-block;
  font-size: 0.75em;
  background: var(--state-translate);
  color: #fff;
  border-radius: 8px;
  padding: 2px 8px;
  margin-right: 6px;
}
.msg .confirmed {
  color: var(--state-listen);
  font-weight: 700;
}
.numbers {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}
.numbers span {
  font-size: var(--font-xl);
  font-weight: 800;
  background: #fff;
  border: 2px solid var(--state-translate);
  border-radius: 12px;
  padding: 2px 12px;
  letter-spacing: 0.02em;
}

/* 途中経過(確定前)の吹き出し */
.msg.live {
  order: 999;
  opacity: 0.75;
  border: 2px dashed var(--state-translate);
  background: #fffbe8;
}
.msg.live .main {
  font-style: italic;
}
.msg.live .main::after {
  content: ' …';
}
.latest .main.draft {
  opacity: 0.7;
  font-style: italic;
}
.latest .main.draft::after {
  content: ' …';
}

/* 相談者側: 最新の翻訳を最も大きく */
.latest {
  padding: 24px;
  background: var(--panel);
  border-top: 1px solid var(--line);
  min-height: 30vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 10px;
}
.latest .main {
  font-size: var(--font-xxl);
  font-weight: 700;
  line-height: 1.35;
  overflow-wrap: anywhere;
}
.latest .sub {
  font-size: var(--font-md);
  color: var(--muted);
  overflow-wrap: anywhere;
}
.confirm-box {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
  margin-top: 8px;
}
.confirm-box .q {
  font-size: var(--font-lg);
  font-weight: 700;
}
.confirm-box .yn {
  display: flex;
  gap: 16px;
}
.confirm-box .yn button {
  font-size: var(--font-xl);
  min-width: 160px;
}
.confirm-box .yes {
  background: var(--state-listen);
  color: #fff;
}
.confirm-box .no {
  background: var(--state-error);
  color: #fff;
}

.bottombar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px calc(14px + env(safe-area-inset-bottom));
  background: var(--panel);
  border-top: 1px solid var(--line);
}
.mic {
  flex: 1;
  max-width: 560px;
  margin: 0 auto;
  font-size: var(--font-xl);
  font-weight: 700;
  padding: 22px;
  border-radius: 40px;
  background: var(--state-listen);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 96px;
}
.mic.active {
  background: var(--state-error);
  animation: pulse 1.2s infinite;
}
.mic.busy {
  background: var(--state-translate);
}
@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(214, 69, 69, 0.5);
  }
  100% {
    box-shadow: 0 0 0 22px rgba(214, 69, 69, 0);
  }
}
.side-btns {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.side-btns button {
  font-size: var(--font-md);
}
.mytext {
  padding: 10px 18px;
  background: var(--panel);
  border-top: 1px solid var(--line);
  color: var(--muted);
  min-height: 2.6em;
  font-size: var(--font-md);
}
.mytext b {
  color: var(--ink);
}

/* ---- モーダル / パネル ---- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(20, 28, 40, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}
.modal .card {
  background: var(--panel);
  border-radius: 24px;
  padding: 28px;
  width: min(760px, 100%);
  max-height: 92vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.modal h2 {
  margin: 0;
  font-size: var(--font-lg);
}
.modal .actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  flex-wrap: wrap;
}
.pairing {
  display: flex;
  gap: 28px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
}
.pairing img {
  width: 260px;
  height: 260px;
  background: #fff;
  border-radius: 12px;
}
.paircode {
  font-size: clamp(40px, 7vw, 72px);
  font-weight: 800;
  letter-spacing: 0.15em;
  font-variant-numeric: tabular-nums;
}
.phrase-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.phrase-list h3 {
  margin: 10px 0 0;
  font-size: var(--font-md);
  color: var(--muted);
}
.phrase-list button {
  text-align: left;
  font-size: var(--font-lg);
  padding: 14px 18px;
}
.rate-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.rate-row button.selected {
  background: var(--primary);
  color: #fff;
}
textarea.typed {
  width: 100%;
  font: inherit;
  font-size: var(--font-lg);
  padding: 12px;
  border-radius: 12px;
  border: 2px solid var(--line);
  min-height: 3.5em;
  -webkit-user-select: text;
  user-select: text;
}
input.code {
  font-size: clamp(32px, 6vw, 56px);
  letter-spacing: 0.3em;
  text-align: center;
  width: 100%;
  max-width: 420px;
  padding: 10px;
  border-radius: 16px;
  border: 3px solid var(--line);
  font-variant-numeric: tabular-nums;
  -webkit-user-select: text;
  user-select: text;
}
.toast {
  position: fixed;
  left: 50%;
  bottom: 140px;
  transform: translateX(-50%);
  background: var(--state-error);
  color: #fff;
  padding: 14px 22px;
  border-radius: 16px;
  font-weight: 700;
  z-index: 60;
  max-width: 90%;
  text-align: center;
}
.toast.info {
  background: var(--ink);
}
.note {
  color: var(--muted);
  font-size: 0.9em;
}
