@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;700&family=Inter:wght@300;400;500;600&display=swap');

* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #07080a;
  --surface: #0e1117;
  --surface-2: #151921;
  --border: #1e2533;
  --border-glow: #2a3a5c;
  --text: #c9d1d9;
  --text-dim: #6b7688;
  --accent: #58a6ff;
  --accent-glow: rgba(88, 166, 255, 0.15);
  --green: #3fb950;
  --green-glow: rgba(63, 185, 80, 0.15);
  --red: #f85149;
  --red-glow: rgba(248, 81, 73, 0.12);
  --mono: 'JetBrains Mono', 'Fira Code', monospace;
  --sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --radius: 8px;
}

/* ── Light theme ── */
[data-theme="light"] {
  --bg: #ffffff;
  --surface: #f6f8fa;
  --surface-2: #eef1f5;
  --border: #d0d7de;
  --border-glow: #b0bec5;
  --text: #1f2328;
  --text-dim: #656d76;
  --accent: #0969da;
  --accent-glow: rgba(9, 105, 218, 0.12);
  --green: #1a7f37;
  --green-glow: rgba(26, 127, 55, 0.12);
  --red: #cf222e;
  --red-glow: rgba(207, 34, 46, 0.1);
}

body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ── Theme toggle button ── */
.btn-theme {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 32px;
  height: 32px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1rem;
  color: var(--text-dim);
  transition: all 0.2s;
  flex-shrink: 0;
}

.btn-theme:hover {
  color: var(--text);
  border-color: var(--text-dim);
}

/* ── Simple mode ── */
.receiver-container.simple .receiver-header {
  padding: 0.4rem 1rem;
}

.receiver-container.simple .logo,
.receiver-container.simple .receiver-controls-row {
  display: none;
}

/* ── Sender Layout ── */
.sender-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: 0;
  background: var(--bg);
  overflow: hidden;
}

.sender-header {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 0.6rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  z-index: 10;
}

.sender-header-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.logo-img {
  height: 32px;
  width: auto;
}

.logo h1 {
  font-family: var(--mono);
  font-size: 1.15rem;
  font-weight: 500;
  color: var(--text-dim);
  letter-spacing: -0.02em;
}

.logo h1 .accent {
  color: var(--text);
  font-weight: 700;
}

/* ── Status ── */
.status-pill {
  font-family: var(--mono);
  font-size: 0.75rem;
  font-weight: 500;
  padding: 0.3rem 0.75rem;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.status-pill.info {
  background: var(--surface-2);
  color: var(--text-dim);
  border: 1px solid var(--border);
}

.status-pill.success {
  background: var(--green-glow);
  color: var(--green);
  border: 1px solid rgba(63, 185, 80, 0.3);
}

.status-pill.error {
  background: var(--red-glow);
  color: var(--red);
  border: 1px solid rgba(248, 81, 73, 0.25);
}

select {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.55rem 0.7rem;
  font-family: var(--sans);
  font-size: 0.85rem;
  outline: none;
  transition: border-color 0.2s;
  width: auto;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%236b7688'%3E%3Cpath d='M2 4l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.6rem center;
  padding-right: 2rem;
}

select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

.control-actions {
  display: flex;
  gap: 0.5rem;
}

button {
  padding: 0.55rem 1.2rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

button:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--green-glow);
  color: var(--green);
  border-color: rgba(63, 185, 80, 0.3);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.btn-primary:hover:not(:disabled) {
  background: rgba(63, 185, 80, 0.25);
  border-color: var(--green);
}

.btn-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green);
  display: inline-block;
  animation: pulse 2s infinite;
}

.btn-danger {
  background: var(--red-glow);
  color: var(--red);
  border-color: rgba(248, 81, 73, 0.25);
}

.btn-danger:hover:not(:disabled) {
  background: rgba(248, 81, 73, 0.2);
  border-color: var(--red);
}

/* ── Session Info ── */
.session-info {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.5rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.session-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex: 1;
  min-width: 0;
  flex-wrap: wrap;
}

.session-label {
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.session-id {
  font-family: var(--mono);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--green);
}

.receiver-link {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--accent);
  text-decoration: none;
  word-break: break-all;
  overflow-wrap: break-word;
  min-width: 0;
  opacity: 0.8;
}

.receiver-link:hover {
  opacity: 1;
  text-decoration: underline;
}

.btn-copy {
  font-family: var(--mono);
  font-size: 0.65rem;
  padding: 0.2rem 0.6rem;
  background: var(--surface-2);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 4px;
  white-space: nowrap;
}

.btn-copy:hover {
  color: var(--text);
  border-color: var(--text-dim);
}

/* ── Tabs (mobile only) ── */
.tabs {
  display: flex;
  margin-bottom: 0;
  border-bottom: 1px solid var(--border);
}

.panel {
  display: none;
}

.panel.active {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.panel .panel-title {
  display: none;
}

.tab {
  flex: 1;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  color: var(--text-dim);
  padding: 0.6rem 0;
  font-family: var(--mono);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
}

.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tab:hover:not(.active) {
  color: var(--text);
}

.tab-action {
  margin-left: auto;
}

.tab-action + .tab-action {
  margin-left: 0;
}

.btn-icon {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  width: 32px;
  height: 32px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1rem;
  color: var(--text-dim);
  transition: all 0.2s;
  flex-shrink: 0;
}

.btn-icon:hover {
  color: var(--text);
  border-color: var(--text-dim);
}

.btn-icon.flash {
  color: var(--green);
  border-color: var(--green);
}

/* ── Panels ── */
.dual-panel {
  display: grid;
  grid-template-columns: 1fr;
  height: 100%;
}

.panel-title {
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.4rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.panel-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  display: inline-block;
}

.transcript-dot { background: var(--accent); }
.translation-dot { background: var(--green); }

/* ── Sender Panels ── */
.sender-panels {
  padding: 0.75rem 1.25rem;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.sender-panels .panel {
  min-width: 0;
}

.sender-current {
  font-size: 1.15rem;
  font-weight: 500;
  color: var(--text);
  min-height: 2rem;
  padding: 0.6rem 0.75rem;
  margin-bottom: 0.4rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  line-height: 1.5;
  border-left: 2px solid transparent;
  border-radius: 4px;
  word-wrap: break-word;
  overflow-wrap: break-word;
  max-width: 100%;
}

.sender-current.transcript-accent {
  border-left-color: var(--accent);
  background: var(--accent-glow);
}

.sender-current.translation-accent {
  border-left-color: var(--green);
  background: var(--green-glow);
}

.sender-current .word {
  display: inline-block;
  opacity: 0;
  filter: blur(4px);
  transform: translateY(6px);
  animation: wordReveal 0.3s ease forwards;
}

.sender-history {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  mask-image: linear-gradient(to bottom, black 80%, transparent 100%);
  -webkit-mask-image: linear-gradient(to bottom, black 80%, transparent 100%);
}

.sender-history::-webkit-scrollbar {
  width: 3px;
}

.sender-history::-webkit-scrollbar-track {
  background: transparent;
}

.sender-history::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

.sender-history-line {
  font-size: 0.9rem;
  color: var(--text);
  padding: 0.3rem 0.75rem;
  border-radius: 4px;
  border-left: 2px solid transparent;
  word-wrap: break-word;
  overflow-wrap: break-word;
  max-width: 100%;
}

.sender-history-line.transcript-line {
  border-left-color: rgba(88, 166, 255, 0.2);
}

.sender-history-line.translation-line {
  border-left-color: rgba(63, 185, 80, 0.2);
}

.sender-history-line.history-enter {
  opacity: 1;
  transform: translateY(-1rem);
}

.sender-history-line.history-entered {
  animation: historyFadeDown 0.4s ease forwards;
}

.sender-history-line:hover {
  background: var(--surface-2);
}

/* ── Mobile ── */
@media (max-width: 640px) {
  .sender-header {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .sender-header .logo {
    width: 100%;
  }
}

/* ── Receiver ── */
.receiver-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  padding: 8rem 1.5rem 1.5rem;
  background: var(--bg);
}

.receiver-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 0.6rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  z-index: 10;
}

.receiver-header-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--text-dim);
  transition: background 0.3s;
}

.status-dot.success {
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
}

.status-dot.error {
  background: var(--red);
  box-shadow: 0 0 6px var(--red);
}

.status-dot.info {
  background: var(--text-dim);
  animation: pulse 1.5s infinite;
}

.receiver-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.receiver-label {
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.receiver-meta #sessionLabel {
  font-family: var(--mono);
  font-size: 1rem;
  font-weight: 700;
  color: var(--green);
}

.receiver-controls {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.receiver-controls select {
  width: auto;
}

.qr-code {
  width: 110px;
  height: 110px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: transparent;
  padding: 4px;
  margin-left: auto;
  flex-shrink: 0;
}

#subtitle {
  font-family: var(--sans);
  font-size: 2rem;
  font-weight: 500;
  text-align: center;
  color: var(--text);
  margin-top: 1rem;
  max-width: 90vw;
  width: 100%;
  padding: 1.5rem;
  min-height: 4rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
  line-height: 1.4;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

#subtitle .word {
  display: inline-block;
  opacity: 0;
  filter: blur(4px);
  transform: translateY(8px);
  animation: wordReveal 0.35s ease forwards;
}

@keyframes wordReveal {
  to {
    opacity: 1;
    filter: blur(0);
    transform: translateY(0);
  }
}

#history {
  margin-top: 0.5rem;
  width: 100%;
  max-width: 90vw;
  max-height: calc(50vh - 60px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  scroll-behavior: smooth;
  mask-image: linear-gradient(to bottom, black 85%, transparent 100%);
  -webkit-mask-image: linear-gradient(to bottom, black 85%, transparent 100%);
}

#history::-webkit-scrollbar {
  width: 3px;
}

#history::-webkit-scrollbar-track {
  background: transparent;
}

#history::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

.history-line {
  font-family: var(--sans);
  font-size: 2rem;
  font-weight: 500;
  text-align: center;
  color: var(--text);
  padding: 0.2rem 0;
  transition: opacity 0.4s;
  line-height: 1.4;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
  word-wrap: break-word;
  overflow-wrap: break-word;
  max-width: 100%;
}

/* Fade-down animation when subtitle moves to history */
.history-line.history-enter {
  opacity: 1 !important;
  transform: translateY(-1.5rem);
  filter: blur(0);
}

.history-line.history-entered {
  animation: historyFadeDown 0.5s ease forwards;
}

@keyframes historyFadeDown {
  from {
    transform: translateY(-1.5rem);
    filter: blur(0);
  }
  to {
    transform: translateY(0);
    filter: blur(0);
  }
}

/* Opacity set dynamically by JS based on scroll position */

/* ── Animations ── */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes slideIn {
  from { opacity: 0; transform: translateX(-6px); }
  to   { opacity: 1; transform: translateX(0); }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.4; }
}
