:root {
  --bg: #0b1120;
  --bg-glow-1: rgba(91, 157, 255, 0.4);
  --bg-glow-2: rgba(255, 138, 99, 0.3);
  --card-bg: #141d38;
  --card-bg-2: #101830;
  --field-bg: rgba(255,255,255,0.05);
  --accent: #5b9dff;
  --accent-dim: rgba(91, 157, 255, 0.16);
  --accent-2: #ff8a63;
  --accent-2-dim: rgba(255, 138, 99, 0.16);
  --text: #f4f6fb;
  --text-dim: rgba(244, 246, 251, 0.55);
  --danger: #ff4d5e;
  --radius: 20px;
  --display-font: "Bricolage Grotesque", ui-sans-serif, system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  background:
    radial-gradient(50vw 50vh at 8% -6%, var(--bg-glow-1), transparent 65%),
    radial-gradient(46vw 46vh at 100% 12%, var(--bg-glow-2), transparent 62%),
    radial-gradient(48vw 48vh at 4% 100%, var(--bg-glow-2), transparent 64%),
    radial-gradient(46vw 46vh at 98% 104%, var(--bg-glow-1), transparent 62%),
    var(--bg);
  background-attachment: fixed;
  position: relative;
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='64' height='64' viewBox='0 0 64 64'%3E%3Cpath d='M10 14h30a8 8 0 0 1 8 8v10a8 8 0 0 1-8 8H26l-9 8v-8h-7a8 8 0 0 1-8-8V22a8 8 0 0 1 8-8z' fill='%235b9dff' fill-opacity='0.05'/%3E%3Cpath d='M24 26h30a8 8 0 0 1 8 8v9a8 8 0 0 1-8 8h-4v7l-8-7H24a8 8 0 0 1-8-8v-9a8 8 0 0 1 8-8z' fill='%23ff8a63' fill-opacity='0.05'/%3E%3C/svg%3E");
  background-size: 150px 150px;
  background-repeat: repeat;
}
.app {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  min-height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) 16px calc(env(safe-area-inset-bottom) + 16px);
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: rise 0.45s ease both;
}
@media (prefers-reduced-motion: reduce) {
  .app { animation: none; }
}
@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
}
.brand-mark {
  width: 30px;
  height: 30px;
  filter: drop-shadow(0 3px 8px rgba(91, 157, 255, 0.35));
}
.brand-name {
  font-family: var(--display-font);
  font-weight: 800;
  font-size: 22px;
  letter-spacing: -0.01em;
  background: linear-gradient(100deg, #8ebeff, var(--text) 45%, #ffb69c);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.lang-bar {
  display: flex;
  align-items: center;
  gap: 10px;
}

.lang-select {
  flex: 1;
  background: linear-gradient(180deg, rgba(255,255,255,0.07), rgba(255,255,255,0.03));
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 999px;
  padding: 11px 14px;
  font-size: 15px;
  font-weight: 600;
  appearance: none;
  text-align: center;
  cursor: pointer;
  box-shadow: 0 1px 0 rgba(255,255,255,0.06) inset, 0 6px 14px -8px rgba(0,0,0,0.5);
  transition: border-color 0.15s ease;
}
.lang-select:hover { border-color: rgba(255,255,255,0.28); }
.lang-select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.lang-select option {
  background: #16213e;
  color: #f4f6fb;
}

.card {
  background: linear-gradient(165deg, var(--card-bg), var(--card-bg-2));
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius);
  padding: 4px;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 220px;
  box-shadow:
    0 1px 0 rgba(255,255,255,0.06) inset,
    0 0 0 1px rgba(91, 157, 255, 0.12),
    0 20px 44px -14px rgba(0,0,0,0.6),
    0 14px 50px -18px rgba(91, 157, 255, 0.35),
    0 24px 60px -20px rgba(255, 138, 99, 0.22);
  position: relative;
  overflow: hidden;
}
.card::before {
  content: "";
  position: absolute;
  top: -18%;
  right: -14%;
  width: 62%;
  aspect-ratio: 1;
  background:
    radial-gradient(circle at 32% 30%, var(--accent) 0%, transparent 70%),
    radial-gradient(circle at 68% 65%, var(--accent-2) 0%, transparent 70%);
  opacity: 0.28;
  filter: blur(2px);
  pointer-events: none;
}

.field {
  flex: 1;
  padding: 20px 22px;
  display: flex;
  flex-direction: column;
  gap: 9px;
  justify-content: center;
  position: relative;
}
.field.field-original { border-left: 2px solid transparent; }
.field.field-translated { border-left: 2px solid transparent; }

.field-divider {
  height: 1px;
  background: rgba(255,255,255,0.08);
  margin: 0 22px;
}

.field-label {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  font-weight: 700;
}
.field-label::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}
.field-original .field-label::before { background: var(--accent); box-shadow: 0 0 8px var(--accent-dim); }
.field-translated .field-label::before { background: var(--accent-2); box-shadow: 0 0 8px var(--accent-2-dim); }

.field-text {
  font-size: 22px;
  line-height: 1.35;
  word-wrap: break-word;
  min-height: 30px;
}
.field-text:empty::before {
  content: attr(data-placeholder);
  color: var(--text-dim);
  font-weight: 400;
  font-size: 17px;
}
.field-text.original { font-style: italic; color: var(--text-dim); font-size: 17px; }
.field-text.translated {
  font-family: var(--display-font);
  font-weight: 800;
  font-size: 27px;
  letter-spacing: -0.01em;
  color: var(--text);
}
.field-text.translated.pop-in { animation: text-pop 0.32s ease both; }
@keyframes text-pop {
  from { opacity: 0; transform: translateY(4px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@media (prefers-reduced-motion: reduce) {
  .field-text.translated.pop-in { animation: none; }
}

.type-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(180deg, var(--card-bg), var(--card-bg-2));
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 999px;
  padding: 6px 8px 6px 18px;
  box-shadow: 0 10px 24px -14px rgba(0,0,0,0.6);
}
#typeInput {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 15px;
  outline: none;
}
#typeInput::placeholder { color: var(--text-dim); }

.controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 28px;
  padding: 6px 0 4px;
}
.controls-spacer { width: 40px; height: 40px; visibility: hidden; }

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.15s ease;
  flex-shrink: 0;
}
.icon-btn:hover { background: rgba(255,255,255,0.16); }
.icon-btn:active { transform: scale(0.93); }
.icon-btn svg { width: 20px; height: 20px; fill: var(--text); }
.icon-btn.muted svg { fill: var(--danger); }

.mic-btn {
  width: 76px;
  height: 76px;
  border-radius: 50%;
  border: none;
  background: radial-gradient(circle at 32% 28%, #86bcff, var(--accent) 70%);
  box-shadow: 0 10px 24px -4px rgba(91, 157, 255, 0.55), 0 2px 0 rgba(255,255,255,0.2) inset;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.2s ease;
  flex-shrink: 0;
}
.mic-btn:active { transform: scale(0.94); }
.mic-btn.listening {
  background: radial-gradient(circle at 32% 28%, #ffb49c, var(--accent-2) 70%);
  box-shadow: 0 0 0 8px rgba(255, 138, 99, 0.22), 0 10px 24px -4px rgba(255, 138, 99, 0.55);
  animation: pulse 1.2s infinite ease-in-out;
}
.mic-icon { width: 32px; height: 32px; fill: #0d1526; }

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(255, 138, 99, 0.5), 0 10px 24px -4px rgba(255, 138, 99, 0.55); }
  70% { box-shadow: 0 0 0 16px rgba(255, 138, 99, 0), 0 10px 24px -4px rgba(255, 138, 99, 0.55); }
  100% { box-shadow: 0 0 0 0 rgba(255, 138, 99, 0), 0 10px 24px -4px rgba(255, 138, 99, 0.55); }
}

.status {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(6px);
  padding: 7px 15px;
  border-radius: 999px;
  font-size: 12px;
  color: var(--text-dim);
  pointer-events: none;
  z-index: 20;
  opacity: 0;
  transition: opacity 0.3s ease;
  border: 1px solid rgba(255,255,255,0.08);
}
.status.show { opacity: 1; }

.history {
  position: fixed;
  inset: 0;
  background: rgba(8, 12, 24, 0.97);
  z-index: 40;
  padding: calc(env(safe-area-inset-top) + 20px) 16px 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.history.hidden { display: none; }
.history h2 {
  margin: 0 0 8px;
  font-family: var(--display-font);
  font-size: 18px;
  color: var(--text);
  font-weight: 800;
}

.history-item {
  background: linear-gradient(165deg, var(--card-bg), var(--card-bg-2));
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 14px;
  padding: 11px 15px;
}
.history-item .h-orig { font-size: 12px; color: var(--text-dim); font-style: italic; margin-bottom: 4px; }
.history-item .h-trans { font-size: 16px; font-weight: 600; }

.history-close {
  align-self: center;
  margin-top: auto;
  padding: 10px 24px;
  border-radius: 999px;
  border: none;
  background: var(--accent);
  color: #06122b;
  font-weight: 700;
  cursor: pointer;
}

.live-view {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: #000;
  display: flex;
  flex-direction: column;
}
.live-view.hidden { display: none; }

.live-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.live-top {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 14px) 16px 24px;
  background: linear-gradient(180deg, rgba(0,0,0,0.7), transparent);
}

.live-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--text);
  background: rgba(0,0,0,0.45);
  padding: 7px 13px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.1);
}
.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-2);
  box-shadow: 0 0 8px var(--accent-2);
  animation: pulse-dot 1.4s infinite ease-in-out;
}
@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.live-close {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.live-close svg { width: 18px; height: 18px; fill: var(--text); }
.live-close:active { transform: scale(0.93); }

.live-caption-wrap {
  position: relative;
  z-index: 2;
  margin-top: auto;
  padding: 22px 18px calc(env(safe-area-inset-bottom) + 26px);
  background: linear-gradient(0deg, rgba(0,0,0,0.88), rgba(0,0,0,0.5) 65%, transparent);
}

.live-caption {
  font-family: var(--display-font);
  font-weight: 800;
  font-size: 24px;
  line-height: 1.35;
  color: var(--text);
  text-shadow: 0 2px 10px rgba(0,0,0,0.6);
  cursor: pointer;
}
.live-caption.placeholder {
  font-family: inherit;
  font-weight: 500;
  font-size: 15px;
  color: rgba(255,255,255,0.62);
  cursor: default;
}

.live-hint {
  margin-top: 7px;
  font-size: 12px;
  color: rgba(255,255,255,0.5);
}
