:root {
  color-scheme: light;
  --bg: #f8fafc;
  --panel: #ffffff;
  --soft: #eef2f7;
  --text: #101828;
  --muted: #667085;
  --line: #d7dee8;
  --blue: #1a73e8;
  --blue-strong: #1558b0;
  --green: #0f9f6e;
  --danger: #c23b3b;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

button,
select,
textarea,
input {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  width: min(760px, 100%);
  min-height: 100svh;
  margin: 0 auto;
  padding: env(safe-area-inset-top) 14px calc(18px + env(safe-area-inset-bottom));
}

.top-bar {
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 22px;
  font-weight: 700;
}

h2 {
  font-size: 18px;
  font-weight: 700;
}

.icon-button,
.swap-button {
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  display: grid;
  place-items: center;
}

.icon-button span,
.swap-button span {
  font-weight: 700;
}

.language-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 42px minmax(0, 1fr);
  gap: 8px;
  align-items: end;
  padding-bottom: 14px;
}

.language-field,
.stacked-field {
  display: grid;
  gap: 5px;
}

.language-field {
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.language-field span,
.stacked-field span,
.output-meta {
  font-size: 12px;
  color: var(--muted);
}

select,
input {
  min-width: 0;
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
}

select {
  appearance: none;
  font-size: 14px;
  font-weight: 650;
  line-height: 1.25;
  text-overflow: ellipsis;
}

.translate-area {
  display: grid;
  gap: 14px;
}

.input-card,
.output-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.input-card {
  overflow: hidden;
}

textarea {
  width: 100%;
  min-height: 210px;
  display: block;
  resize: vertical;
  border: 0;
  outline: 0;
  padding: 16px;
  color: var(--text);
  background: var(--panel);
  font-size: 20px;
  line-height: 1.35;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  padding: 12px;
  border-top: 1px solid var(--line);
}

.primary-button,
.secondary-button {
  min-height: 42px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0 16px;
  font-weight: 700;
}

.primary-button {
  background: var(--blue);
  color: #fff;
}

.primary-button:active {
  background: var(--blue-strong);
}

.primary-button:disabled,
.secondary-button:disabled {
  opacity: 0.58;
}

.secondary-button {
  background: var(--soft);
  color: var(--text);
  border-color: var(--line);
}

.secondary-button span {
  margin-right: 6px;
}

.output-card {
  min-height: 190px;
  padding: 16px;
}

.output-text {
  margin-top: 8px;
  white-space: pre-wrap;
  font-size: 22px;
  line-height: 1.34;
}

.support-text {
  margin-top: 12px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.4;
  white-space: pre-wrap;
}

.support-text.error {
  color: var(--danger);
}

dialog {
  width: min(560px, calc(100% - 24px));
  border: 0;
  border-radius: 10px;
  padding: 0;
  background: transparent;
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.36);
}

.dialog-card,
.camera-sheet {
  background: var(--panel);
  border-radius: 10px;
  padding: 14px;
}

.dialog-card header,
.camera-sheet header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.dialog-card input {
  height: 46px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
}

.fine-print {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.hidden {
  display: none;
}

menu {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin: 16px 0 0;
  padding: 0;
}

.camera-dialog {
  width: min(720px, calc(100% - 16px));
}

.camera-frame {
  position: relative;
  overflow: hidden;
  border-radius: 8px;
  background: #111827;
  aspect-ratio: 3 / 4;
}

.live-result {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 10px;
  max-height: 38%;
  overflow: auto;
  padding: 12px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.93);
  color: var(--text);
  font-size: 19px;
  line-height: 1.28;
  white-space: pre-wrap;
  box-shadow: 0 8px 26px rgba(15, 23, 42, 0.18);
}

.live-result:empty {
  display: none;
}

video,
canvas {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

canvas {
  display: none;
}

#photoInput {
  display: none;
}

@media (min-width: 700px) {
  .app-shell {
    padding-top: 18px;
  }

  .translate-area {
    grid-template-columns: 1fr 1fr;
    align-items: stretch;
  }

  .output-card {
    min-height: 294px;
  }
}

@media (max-width: 420px) {
  .camera-sheet .action-row {
    justify-content: stretch;
  }

  .camera-sheet .primary-button,
  .camera-sheet .secondary-button {
    flex: 1 1 auto;
    padding: 0 12px;
  }
}
