/* ============================================================
   실시간 통역기 — style.css
   Mobile-first, Korean ↔ English real-time interpreter UI
   ============================================================ */

/* ── Design tokens ────────────────────────────────────────── */
:root {
  /* Brand colours */
  --clr-primary:       #4f46e5;   /* indigo-600 */
  --clr-primary-dark:  #3730a3;   /* indigo-800 */
  --clr-primary-light: #eef2ff;   /* indigo-50  */

  --clr-ko:            #2563eb;   /* blue-600  — Korean side  */
  --clr-ko-light:      #dbeafe;   /* blue-100  */
  --clr-ko-dark:       #1d4ed8;   /* blue-700  */

  --clr-en:            #059669;   /* emerald-600 — English side */
  --clr-en-light:      #d1fae5;   /* emerald-100 */
  --clr-en-dark:       #047857;   /* emerald-700 */

  --clr-bg:            #ffffff;
  --clr-surface:       #f8fafc;
  --clr-border:        #e2e8f0;
  --clr-text:          #1e293b;
  --clr-text-muted:    #94a3b8;
  --clr-placeholder:   #cbd5e1;

  /* Recording accent */
  --clr-recording:     #ef4444;   /* red-500 */

  /* Spacing */
  --header-h:     64px;
  --micbar-h:     96px;   /* footer height */
  --gap:          12px;
  --radius-bubble:16px;
  --radius-btn:   16px;

  /* Typography */
  --font-base: 'Segoe UI', 'Apple SD Gothic Neo', 'Noto Sans KR',
               sans-serif;
  --fs-title:  1.35rem;
  --fs-body:   1rem;
  --fs-small:  0.8125rem;

  /* Animation */
  --transition: 0.2s ease;
}

/* ── Reset & base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;        /* prevent page scroll — inner areas scroll */
}

body {
  font-family: var(--font-base);
  font-size: var(--fs-body);
  color: var(--clr-text);
  background: var(--clr-bg);
  display: flex;
  flex-direction: column;
  /* Exactly fill the viewport — avoids mobile address-bar jump */
  height: 100dvh;
}

/* Screen-reader only utility */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

/* ── Header ───────────────────────────────────────────────── */
.app-header {
  flex-shrink: 0;
  height: var(--header-h);
  background: var(--clr-primary);
  color: #fff;
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 8px;
  position: relative;
  box-shadow: 0 2px 8px rgba(79, 70, 229, 0.35);
  z-index: 10;
}

.app-title {
  font-size: var(--fs-title);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
  white-space: nowrap;
}

.app-subtitle {
  font-size: 0.7rem;
  opacity: 0.75;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  margin-left: 4px;
  align-self: flex-end;
  padding-bottom: 2px;
}

/* Clear / reset button (top-right) */
.clear-btn {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 5px;
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.35);
  border-radius: 8px;
  color: #fff;
  font-size: var(--fs-small);
  padding: 6px 12px;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition);
  flex-shrink: 0;
}

.clear-btn:hover,
.clear-btn:focus-visible {
  background: rgba(255,255,255,0.28);
  outline: 2px solid rgba(255,255,255,0.6);
  outline-offset: 2px;
}

.clear-btn:active { transform: scale(0.96); }

.clear-icon { font-size: 1rem; line-height: 1; }

/* ── Main — fills the space between header & footer ──────── */
.app-main {
  flex: 1 1 0;
  min-height: 0;           /* critical for flex children to scroll */
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--clr-surface);
}

/* ── Conversation area (two columns) ─────────────────────── */
.conversation-area {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: row;
  overflow: hidden;
}

/* ── Language columns ─────────────────────────────────────── */
.lang-column {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--clr-bg);
}

/* Column header strip */
.column-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--clr-border);
  background: var(--clr-bg);
}

.lang-ko .column-header { border-bottom-color: var(--clr-ko-light); }
.lang-en .column-header { border-bottom-color: var(--clr-en-light); }

.lang-flag { font-size: 1.1rem; line-height: 1; }

.lang-label {
  font-size: var(--fs-small);
  font-weight: 600;
  color: var(--clr-text);
}

.lang-ko .lang-label { color: var(--clr-ko-dark); }
.lang-en .lang-label { color: var(--clr-en-dark); }

/* ── Recording status dot ─────────────────────────────────── */
.recording-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: transparent;
  margin-left: 2px;
  transition: background var(--transition);
}

/* Active (recording) state — toggled by app.js via class */
.recording-dot.is-recording {
  background: var(--clr-recording);
  animation: pulse-dot 1s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1;   transform: scale(1);    }
  50%       { opacity: 0.4; transform: scale(0.65); }
}

/* ── Bubble list (scrollable) ─────────────────────────────── */
.bubble-list {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--gap);
  display: flex;
  flex-direction: column;
  gap: 10px;
  /* Smooth momentum scroll on iOS */
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}

/* Thin custom scrollbar (desktop) */
.bubble-list::-webkit-scrollbar { width: 4px; }
.bubble-list::-webkit-scrollbar-track { background: transparent; }
.bubble-list::-webkit-scrollbar-thumb {
  background: var(--clr-placeholder);
  border-radius: 2px;
}

/* ── Placeholder (empty state) ───────────────────────────── */
.bubble-placeholder {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--clr-placeholder);
  font-size: var(--fs-small);
  text-align: center;
  line-height: 1.5;
  padding: 24px 8px;
  user-select: none;
  pointer-events: none;
}

.placeholder-icon { font-size: 2rem; opacity: 0.5; }

/* Hide placeholder when bubbles exist — toggled by app.js */
.bubble-placeholder.is-hidden { display: none; }

/* ── Individual speech bubble ─────────────────────────────── */
.bubble {
  max-width: 100%;
  padding: 10px 13px;
  border-radius: var(--radius-bubble);
  font-size: var(--fs-body);
  line-height: 1.55;
  word-break: break-word;
  animation: bubble-in 0.22s ease both;
  position: relative;
}

@keyframes bubble-in {
  from { opacity: 0; transform: translateY(6px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0)  scale(1);    }
}

/* Korean bubbles — left-aligned, blue */
.lang-ko .bubble {
  background: var(--clr-ko-light);
  color: var(--clr-ko-dark);
  border-bottom-left-radius: 4px;
  align-self: flex-start;
}

/* English bubbles — right-aligned, green */
.lang-en .bubble {
  background: var(--clr-en-light);
  color: var(--clr-en-dark);
  border-bottom-right-radius: 4px;
  align-self: flex-end;
  text-align: right;
}

/* Translated (secondary) bubble — slightly dimmed */
.bubble--translated {
  opacity: 0.78;
  font-style: italic;
  font-size: 0.9375rem;
}

/* Timestamp chip on each bubble */
.bubble__time {
  display: block;
  font-size: 0.68rem;
  opacity: 0.55;
  margin-top: 4px;
}

.lang-en .bubble__time { text-align: right; }

/* ── Vertical divider between columns ───────────────────────*/
.column-divider {
  flex-shrink: 0;
  width: 1px;
  background: var(--clr-border);
}

/* ── Interim transcript ribbon ───────────────────────────── */
.interim-ribbon {
  flex-shrink: 0;
  background: rgba(79, 70, 229, 0.06);
  border-top: 1px solid rgba(79, 70, 229, 0.15);
  padding: 8px 16px;
  min-height: 38px;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background 0.2s, border-color 0.2s;
}

.interim-ribbon[hidden] { display: none; }

/* Colour the ribbon to match whichever mic is active */
.interim-ribbon[data-lang="ko"] {
  background: rgba(37, 99, 235, 0.07);
  border-top-color: rgba(37, 99, 235, 0.2);
}
.interim-ribbon[data-lang="en"] {
  background: rgba(5, 150, 105, 0.07);
  border-top-color: rgba(5, 150, 105, 0.2);
}

.interim-icon {
  font-size: 0.6rem;
  color: var(--clr-recording);
  animation: pulse-dot 1s ease-in-out infinite;
  flex-shrink: 0;
}

.interim-ribbon[data-lang="ko"] .interim-icon { color: var(--clr-ko); }
.interim-ribbon[data-lang="en"] .interim-icon { color: var(--clr-en); }

.interim-text {
  font-size: var(--fs-small);
  color: var(--clr-primary);
  font-style: italic;
  opacity: 0.85;
  white-space: pre-wrap;
  word-break: break-word;
}

.interim-ribbon[data-lang="ko"] .interim-text { color: var(--clr-ko-dark); }
.interim-ribbon[data-lang="en"] .interim-text { color: var(--clr-en-dark); }

/* ── Mic button bar (footer) ──────────────────────────────── */
.mic-bar {
  flex-shrink: 0;
  height: var(--micbar-h);
  display: flex;
  gap: 10px;
  padding: 10px 12px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  background: var(--clr-bg);
  border-top: 1px solid var(--clr-border);
  box-shadow: 0 -2px 10px rgba(0,0,0,0.06);
  z-index: 10;
}

/* ── Individual mic button ────────────────────────────────── */
.mic-btn {
  flex: 1 1 0;
  min-height: 60px;          /* requirement */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: none;
  border-radius: var(--radius-btn);
  cursor: pointer;
  padding: 8px 10px;
  transition: transform var(--transition),
              box-shadow var(--transition),
              filter var(--transition);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  position: relative;
  overflow: hidden;
}

/* Ripple on press */
.mic-btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0.25);
  opacity: 0;
  transition: opacity 0.15s;
}
.mic-btn:active::after { opacity: 1; }

/* Korean button — blue */
.mic-btn--ko {
  background: linear-gradient(135deg, var(--clr-ko), var(--clr-ko-dark));
  color: #fff;
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.4);
}

/* English button — green */
.mic-btn--en {
  background: linear-gradient(135deg, var(--clr-en), var(--clr-en-dark));
  color: #fff;
  box-shadow: 0 4px 14px rgba(5, 150, 105, 0.4);
}

/* Hover (desktop) */
.mic-btn--ko:hover:not(:disabled) {
  filter: brightness(1.08);
  box-shadow: 0 6px 18px rgba(37, 99, 235, 0.5);
}
.mic-btn--en:hover:not(:disabled) {
  filter: brightness(1.08);
  box-shadow: 0 6px 18px rgba(5, 150, 105, 0.5);
}

/* Press */
.mic-btn:active:not(:disabled) { transform: scale(0.96); }

/* ── Active / recording state ─────────────────────────────── */
.mic-btn.is-recording {
  animation: btn-pulse 1.4s ease-in-out infinite;
}

.mic-btn--ko.is-recording {
  box-shadow: 0 0 0 0 rgba(37, 99, 235, 0.7);
}
.mic-btn--en.is-recording {
  box-shadow: 0 0 0 0 rgba(5, 150, 105, 0.7);
}

@keyframes btn-pulse {
  0%   { box-shadow: 0 0 0 0   rgba(255,255,255,0.6); }
  60%  { box-shadow: 0 0 0 12px rgba(255,255,255,0); }
  100% { box-shadow: 0 0 0 0   rgba(255,255,255,0); }
}

/* Disabled state */
.mic-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Button inner elements */
.mic-btn__icon  { font-size: 1.45rem; line-height: 1; }
.mic-btn__label { font-size: 0.8125rem; font-weight: 700; line-height: 1.2; }
.mic-btn__status {
  font-size: 0.68rem;
  opacity: 0.8;
  line-height: 1;
}

/* ── Error / permission toast ─────────────────────────────── */
.toast {
  position: fixed;
  bottom: calc(var(--micbar-h) + 12px);
  left: 50%;
  transform: translateX(-50%);
  background: #1e293b;
  color: #fff;
  border-radius: 12px;
  padding: 12px 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: var(--fs-small);
  max-width: calc(100vw - 32px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
  z-index: 100;
  animation: toast-in 0.25s ease both;
}

.toast[hidden] { display: none; }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(12px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0);    }
}

.toast__icon { font-size: 1.1rem; flex-shrink: 0; }

.toast__msg { flex: 1; line-height: 1.4; }

.toast__close {
  flex-shrink: 0;
  background: none;
  border: none;
  color: rgba(255,255,255,0.7);
  font-size: 1rem;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  line-height: 1;
  transition: color var(--transition);
}
.toast__close:hover { color: #fff; }

/* ── Responsive: tablet & desktop ────────────────────────── */
@media (min-width: 600px) {
  :root {
    --header-h:    72px;
    --micbar-h:   104px;
    --fs-title:   1.6rem;
    --gap:        16px;
  }

  .app-subtitle { font-size: 0.8rem; }

  .mic-btn__icon  { font-size: 1.6rem; }
  .mic-btn__label { font-size: 0.9rem; }
  .mic-btn__status { font-size: 0.75rem; }

  .bubble { font-size: 1.0625rem; }
}

@media (min-width: 900px) {
  :root {
    --header-h:    76px;
    --micbar-h:   108px;
    --gap:        20px;
  }

  .conversation-area {
    max-width: 960px;
    margin: 0 auto;
    width: 100%;
  }

  /* On wide screens, centre the button group but keep footer full-width */
  .mic-bar {
    justify-content: center;
  }

  .mic-btn {
    max-width: 420px;
  }

  .bubble-list { padding: 20px; }

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

/* ── High-contrast / forced-colors accessibility ─────────── */
@media (forced-colors: active) {
  .mic-btn { border: 2px solid ButtonText; }
  .recording-dot.is-recording { background: Highlight; }
}

/* ── Very small phones: hide subtitle to prevent overflow ─── */
@media (max-width: 359px) {
  .app-subtitle { display: none; }
  .clear-label  { display: none; }  /* show only the icon */
}

/* ── Reduced-motion accessibility ─────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .recording-dot.is-recording { animation: none; opacity: 1; }
  .mic-btn.is-recording       { animation: none; }
  .bubble                     { animation: none; }
  .toast                      { animation: none; }
  .interim-icon               { animation: none; opacity: 1; }
}
