/* Simple, touch-friendly layout for phones and tablets. */

:root {
  --color-primary: #1d6fd8;
  --color-danger: #c62828;
  --color-correct: #2e7d32;
  --color-border: #c5ccd6;
  --color-background: #f4f6fa;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 18px;
  background: var(--color-background);
  color: #1b1f27;
}

#app {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px;
}

/* Wide layout (see js/ui/LayoutToggle.js): more room for the text fields when editing on a computer. */
body.wide #app {
  max-width: 1200px;
}

.layout-bar {
  display: flex;
  justify-content: center;
  padding-top: 8px;
}

/* On a phone the app is narrow anyway, so the switch would do nothing. */
@media (max-width: 700px) {
  .layout-bar {
    display: none;
  }
}

.view {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

h1 {
  margin: 0;
  font-size: 1.5rem;
}

/* Large touch targets (at least 48 px high). */
button,
input[type='text'],
select {
  min-height: 48px;
  font: inherit;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 8px 14px;
  background: #fff;
}

button {
  cursor: pointer;
}

button:disabled {
  opacity: 0.5;
  cursor: default;
}

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

button.danger {
  color: var(--color-danger);
}

button.link {
  border: none;
  background: none;
  color: var(--color-primary);
  text-decoration: underline;
  padding: 4px 8px;
  min-height: 0;
}

button.layout-toggle {
  min-height: 36px;
  font-size: 0.85rem;
  padding: 4px 12px;
  color: #5a6472;
}

button.icon {
  min-width: 48px;
  padding: 0;
}

input:focus-visible,
button:focus-visible,
select:focus-visible {
  outline: 3px solid #f2b705;
  outline-offset: 2px;
}

.actions,
.scan-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.language-selection {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.language-selection label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.9rem;
}

.status {
  min-height: 1.4em;
  margin: 0;
}

h2 {
  margin: 8px 0 0;
  font-size: 1.2rem;
}

.hint {
  margin: 0;
  color: #5a6472;
}

/* --- Labels (home screen and label screen) --- */

.label-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.label-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 4px 4px 12px;
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: 8px;
}

/* The checkbox, the name and the entry count fill the row; the "Öffnen" button sits on the right. */
.label-row .choice {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}

.label-count {
  margin-left: auto;
  color: #5a6472;
  font-size: 0.9rem;
}

.select-all {
  padding-left: 13px;
  font-size: 0.9rem;
}

.header-buttons {
  display: flex;
  gap: 8px;
}

/* Scanned entries that are not saved yet. */
.entry-card.pending {
  border-left: 6px solid var(--color-primary);
}

.label-name-input {
  font-size: 1.2rem;
  font-weight: 600;
}

/* --- Entry editor --- */

.column-titles {
  margin: 0;
  color: #5a6472;
}

.entry-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.entry-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: 8px;
}

.pair-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 8px;
}

.pair-row input {
  min-width: 0;
}

.pair-row.example input {
  font-size: 0.9rem;
  background: #f8f9fb;
}

/* --- Practice --- */

fieldset {
  border: 1px solid var(--color-border);
  border-radius: 8px;
}

.choice {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
}

.choice input {
  width: 24px;
  height: 24px;
}

.progress {
  margin: 0;
  color: #5a6472;
}

.prompt {
  margin: 24px 0 0;
  font-size: 1.8rem;
  font-weight: 600;
  text-align: center;
  overflow-wrap: anywhere;
}

.practice-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.answer-input {
  font-size: 1.3rem;
}

.feedback {
  min-height: 1.5em;
  margin: 0;
  font-size: 1.2rem;
  text-align: center;
}

.feedback.correct {
  color: var(--color-correct);
}

.feedback.wrong {
  color: var(--color-danger);
}

/* --- Crop dialog --- */

.crop-dialog {
  width: min(96vw, 800px);
  max-height: 96vh;
  padding: 12px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
}

.crop-dialog h2 {
  margin: 0 0 4px;
  font-size: 1.1rem;
}

.crop-surface {
  position: relative;
  display: block;
  width: fit-content;
  max-width: 100%;
  margin: 0 auto;
  touch-action: none;
  user-select: none;
  cursor: crosshair;
}

.crop-surface img {
  display: block;
  max-width: 100%;
  max-height: 65vh;
  pointer-events: none;
}

.crop-selection {
  position: absolute;
  border: 2px solid var(--color-primary);
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.45); /* dims everything outside the selection */
  cursor: move;
  pointer-events: none;
}

.crop-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

/* --- Spoken answers (V3) --- */

.answer-row {
  display: flex;
  gap: 8px;
}

.answer-row .answer-input {
  flex: 1;
  min-width: 0;
}

button.microphone {
  font-size: 1.3rem;
}

button.microphone.listening {
  background: var(--color-danger);
  border-color: var(--color-danger);
  animation: listening-pulse 1s ease-in-out infinite;
}

@keyframes listening-pulse {
  50% { opacity: 0.55; }
}
