/* ── Layout overrides ── */
.wrap {
  max-width: 820px;
}

/* ── Header ── */
.header-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 8px;
}
.header-row h1 {
  margin: 0;
}

/* ── Language selectors row ── */
.lang-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 8px;
  align-items: end;
  margin-bottom: 12px;
}
.lang-col label {
  display: block;
  font-size: 0.85rem;
  color: var(--soft);
  margin-bottom: 4px;
}
.lang-col select {
  width: 100%;
}
.swap-col {
  display: flex;
  align-items: center;
  justify-content: center;
  padding-bottom: 2px;
}

/* ── Swap button ── */
.btn-icon {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  min-width: 40px;
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.18s, transform 0.18s;
  color: var(--ink);
  padding: 0;
  line-height: 1;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.btn-icon:hover {
  background: var(--line);
  transform: scale(1.08);
}
.btn-icon:active {
  transform: scale(0.95);
}

/* ── Panels row ── */
.panels-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}
.panel {
  display: flex;
  flex-direction: column;
}
.panel textarea {
  width: 100%;
  min-height: 220px;
  resize: vertical;
  padding: 14px;
  font-size: 1rem;
  line-height: 1.6;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  transition: border-color 0.18s, box-shadow 0.18s;
}
.panel textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
.source-panel textarea {
  background: var(--surface);
}
.target-panel textarea {
  background: color-mix(in srgb, var(--bg) 50%, var(--surface));
}
.panel-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 4px 0;
  min-height: 28px;
}
.target-footer {
  justify-content: flex-end;
}

/* ── Action row ── */
.action-row {
  display: flex;
  justify-content: center;
  margin-bottom: 24px;
}
.btn-primary {
  min-width: 180px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 1.05rem;
  padding: 12px 28px;
}

/* ── Spinner ── */
.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid var(--accent-ink);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Error message ── */
.error-msg {
  color: #c0392b;
  font-size: 0.875rem;
  flex: 1;
}

/* ── History ── */
.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.history-header h2 {
  margin: 0;
}
.btn.small {
  padding: 6px 14px;
  font-size: 0.85rem;
}
.history-entry {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s;
  border: 1px solid transparent;
  margin-bottom: 6px;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.history-entry:hover {
  background: color-mix(in srgb, var(--accent) 8%, var(--surface));
  border-color: var(--line);
}
.history-entry:active {
  background: color-mix(in srgb, var(--accent) 14%, var(--surface));
}
.history-entry .entry-text {
  flex: 1;
  min-width: 0;
}
.history-entry .entry-text .src {
  font-weight: 600;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.history-entry .entry-text .meta {
  font-size: 0.8rem;
  color: var(--soft);
  margin-top: 2px;
}
.history-entry .entry-langs {
  font-size: 0.8rem;
  color: var(--accent);
  white-space: nowrap;
  font-weight: 500;
  padding-top: 2px;
}

/* ── Login barrier ── */
#loginBarrier p {
  margin-bottom: 8px;
}
#loginBarrier .btn {
  margin-top: 4px;
}

/* ── Mobile: stack everything ── */
@media (max-width: 600px) {
  .wrap {
    padding: 0 4px;
  }
  .header-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    margin-bottom: 12px;
  }
  .header-row h1 {
    font-size: 1.4rem;
  }

  /* Language row: two selects side by side, swap button between them as a small overlay */
  .lang-row {
    grid-template-columns: 1fr auto 1fr;
    gap: 6px;
    align-items: end;
    margin-bottom: 10px;
  }
  .lang-col label {
    font-size: 0.78rem;
    margin-bottom: 3px;
  }
  .lang-col select {
    font-size: 0.9rem;
    padding: 9px 8px;
  }
  .swap-col {
    padding-bottom: 2px;
  }
  .btn-icon {
    width: 34px;
    height: 34px;
    font-size: 1rem;
  }

  /* Panels: stack vertically */
  .panels-row {
    grid-template-columns: 1fr;
    gap: 10px;
    margin-bottom: 10px;
  }
  .panel textarea {
    min-height: 140px;
    font-size: 0.95rem;
    padding: 12px;
  }

  /* Full-width translate button */
  .action-row {
    margin-bottom: 20px;
  }
  .btn-primary {
    width: 100%;
    padding: 14px 20px;
    font-size: 1rem;
  }

  /* History entries: tighter */
  .history-entry {
    padding: 8px 10px;
    gap: 8px;
  }
  .history-entry .entry-text .src {
    font-size: 0.9rem;
  }
  .history-entry .entry-langs {
    font-size: 0.75rem;
  }
  .history-header h2 {
    font-size: 1.15rem;
  }

  /* Card padding */
  .card {
    padding: 14px;
  }
}

/* ── Extra small screens (≤ 380px) ── */
@media (max-width: 380px) {
  .lang-row {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto;
    gap: 4px;
  }
  .lang-col:first-child {
    grid-column: 1;
  }
  .lang-col:last-child {
    grid-column: 2;
  }
  .swap-col {
    grid-column: 1 / -1;
    grid-row: 2;
    padding: 2px 0;
    justify-content: center;
  }
  .btn-icon {
    width: 30px;
    height: 30px;
    min-width: 30px;
    font-size: 0.9rem;
  }
  .lang-col select {
    font-size: 0.82rem;
    padding: 8px 6px;
  }
  .panel textarea {
    min-height: 120px;
    font-size: 0.9rem;
  }
}
