/* ============================================================
   Limpidi Simboli – Main Stylesheet
   Extracted from index.html for modularity.
   WCAG 2.1 AA compliant – focus indicators, contrast, touch targets
   ============================================================ */

/* ---------- Custom Properties ---------- */
:root {
  --bg: #f7f7f9;
  --card: #ffffff;
  --text: #222;
  --muted: #6b7280;
  --brand: #2a9df4;
  --brand-600: #1e7ec8;
  --danger: #b91c1c;
  --ring: rgba(42, 157, 244, 0.35);
  --btn-blue: #0D5891;
}

/* ---------- Reset & Base ---------- */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  padding: 24px;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}
h1 { text-align: center; margin: 0 0 8px; font-weight: 800; }
.sub { text-align: center; margin-bottom: 16px; color: var(--muted); }

/* ---------- WCAG: Focus visible for all interactive elements ---------- */
:focus-visible {
  outline: 3px solid var(--brand);
  outline-offset: 2px;
}

/* ---------- Skip navigation link (WCAG) ---------- */
.skip-link {
  position: absolute;
  top: -100%;
  left: 0;
  background: var(--btn-blue);
  color: #fff;
  padding: 12px 16px;
  z-index: 100000;
  font-weight: 700;
  border-radius: 0 0 8px 0;
  text-decoration: none;
}
.skip-link:focus {
  top: 0;
}

/* ---------- Toolbar & Controls ---------- */
.toolbar {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  max-width: 1400px;
  margin: 0 auto 12px;
  align-items: center;
}
.controls {
  display: grid;
  grid-template-columns: 6fr repeat(3, max-content);
  gap: 8px;
  align-items: center;
  background: var(--card);
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 10px;
  box-shadow: 0 2px 6px rgba(0,0,0,.06);
}
.controls input[type="text"] {
  width: 100%;
  padding: 12px;
  font-size: 1rem;
  border: 1px solid #d1d5db;
  border-radius: 10px;
}
.controls input[type="text"]:focus {
  outline: 2px solid var(--ring);
  border-color: var(--brand);
}
.controls select,
.controls label { font-size: .95rem; color: #111827; }
.controls select,
.controls input[type="checkbox"] { margin-left: 6px; }

/* ---------- Buttons ---------- */
.button {
  appearance: none;
  border: 0;
  background: var(--brand);
  color: #fff;
  padding: 12px 16px;
  border-radius: 10px;
  font-weight: 700;
  cursor: pointer;
}
.button:hover { background: var(--brand-600); }
.ghost {
  background: transparent;
  color: var(--brand);
  border: 1px solid var(--brand);
}

/* Larger touch targets for WCAG (min 44×44 px) */
.button,
.button.ghost,
.lang-flag {
  min-height: 44px;
  padding-top: 10px;
  padding-bottom: 10px;
}
.lang-flag { padding-left: 12px; padding-right: 12px; }

/* ---------- Language Flag Buttons ---------- */
.lang-flag {
  background: transparent;
  border: 1px solid transparent;
  padding: 6px 8px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 56px;
  box-sizing: border-box;
}
.lang-flag .lang-abbr {
  margin-left: 0;
  font-weight: 700;
  font-size: 0.85rem;
  vertical-align: middle;
  display: inline-block;
}
.lang-flag svg {
  width: 22px;
  height: 14px;
  vertical-align: middle;
  display: inline-block;
  flex: 0 0 auto;
}
.lang-flag.active {
  border-color: var(--brand);
  box-shadow: 0 0 0 4px var(--ring);
  transform: translateY(0);
}
.lang-flag:hover { background: #f3f4f6; }

/* ---------- Default button colour scheme (--btn-blue) ---------- */
.button, .button.ghost, .lang-flag, .merge-btn {
  background: transparent !important;
  color: var(--btn-blue) !important;
  border-color: transparent !important;
}
.button.ghost { border-color: var(--btn-blue) !important; }
.button, .button.ghost, .lang-flag {
  transition: background-color 150ms ease, color 150ms ease, border-color 150ms ease;
}

/* Translate button outline */
#translateButton {
  border: 1px solid var(--btn-blue) !important;
  background: transparent !important;
  color: var(--btn-blue) !important;
}

/* Hover state */
.button:hover,
.button.ghost:hover,
.lang-flag:hover,
.merge-btn:hover,
.gpt-symbol-btn:hover,
.abc-btn:hover,
.add-symbol-btn:hover,
.ghost:hover,
#translateButton:hover,
.button[data-hoverable]:hover {
  background: var(--btn-blue) !important;
  color: #ffffff !important;
  border-color: var(--btn-blue) !important;
}

/* Active / pressed state */
.button.active, .button[aria-pressed="true"],
.button.ghost.active, .button.ghost[aria-pressed="true"],
.lang-flag.active, .merge-btn.visible {
  background: var(--btn-blue) !important;
  color: #ffffff !important;
  border-color: var(--btn-blue) !important;
  box-shadow: 0 0 0 4px var(--ring) !important;
}

/* ---------- Result Grid ---------- */
.result {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 14px;
  max-width: 1100px;
  margin: 0 auto;
}
.sentence-box {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 15px;
  padding-right: 75px;
  margin-bottom: 10px;
  border-radius: 8px;
  width: 100%;
  min-height: 120px;
  box-sizing: border-box;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  position: relative;
}
.sentence-box-even {
  background-color: #e3f2fd;
  border: 2px solid #2196f3;
}
.sentence-box-odd {
  background-color: #fff3e0;
  border: 2px solid #ff9800;
}

/* ---------- Tiles ---------- */
.tile {
  background: var(--card);
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 10px;
  text-align: center;
  box-shadow: 0 2px 6px rgba(0,0,0,.06);
  min-height: 184px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: relative;
  min-width: 120px;
  flex: 0 0 auto;
  height: auto;
}
.tile img {
  max-width: 100%;
  max-height: 130px;
  object-fit: contain;
  display: block;
  margin: 0 auto;
}
.word {
  font-weight: 700;
  font-size: 1.3rem;
  word-wrap: break-word;
  overflow-wrap: break-word;
  hyphens: auto;
  padding: 0 4px;
  max-width: 100%;
}
.miss { color: var(--danger); font-size: .85rem; }

/* Pronoun insertion highlight */
.tile.inserted { border: 2px solid var(--danger); }
.tile.inserted .word { color: var(--danger); }

/* Selected tiles for merging */
.tile.selected {
  border: 3px solid var(--brand);
  background: #e0f2fe;
  box-shadow: 0 4px 12px rgba(42, 157, 244, 0.3);
}
.tile.selected .word { color: var(--brand); }

/* ---------- Badges ---------- */
.badges {
  position: static;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
  margin-top: 4px;
}
.badges .badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #ffffffee;
  border: 1px solid #e5e7eb;
  border-radius: 999px;
  padding: 2px 6px;
}
.badges .badge img {
  max-height: 20px;
  max-width: 20px;
}

/* ---------- Status & Footer ---------- */
.status { max-width: 1100px; margin: 10px auto 18px; color: var(--muted); }
.footer { max-width: 1100px; margin: 28px auto 0; color: var(--muted); font-size: .9rem; text-align: center; }
.footer a { color: var(--brand); }

/* ---------- Tile Action Buttons ---------- */
.add-symbol-btn {
  position: absolute;
  top: 8px;
  left: 8px;
  background: #ffffffcc;
  border: 1px solid #e5e7eb;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  font-weight: 700;
  font-size: 18px;
  line-height: 20px;
  text-align: center;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.add-symbol-btn:hover { background: #f3f4f6; }

.gpt-symbol-btn {
  background: #ffffffcc;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 16px;
  cursor: pointer;
  margin-top: auto;
  min-height: 28px;
  align-self: stretch;
}
.gpt-symbol-btn:hover { background: #f3f4f6; }

.remove-symbol-btn {
  position: absolute;
  top: 35px;
  right: 8px;
  background: #ef4444cc;
  color: white;
  border: none;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  font-weight: 700;
  font-size: 18px;
  line-height: 20px;
  text-align: center;
  cursor: pointer;
  z-index: 2;
}

.abc-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: #ffffffcc;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  padding: 2px 6px;
  font-weight: 700;
  font-size: 12px;
  cursor: pointer;
}
.abc-btn:hover { background: #f3f4f6; }

.action-buttons-container {
  display: flex;
  gap: 6px;
  margin-top: auto;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
}

/* Prevent button overflow inside tiles */
.action-buttons-container > button,
.tile > button,
.tile .gpt-symbol-btn,
.tile .abc-btn,
.tile .add-symbol-btn {
  flex: 0 1 auto;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Hide tile action buttons by default (simple mode) */
body:not(.show-tile-actions) .action-buttons-container,
body:not(.show-tile-actions) .remove-symbol-btn {
  display: none !important;
}

/* ---------- Merge Button ---------- */
.merge-btn {
  background: #10b981;
  color: white;
  border: none;
  padding: 10px 16px;
  border-radius: 8px;
  font-weight: 700;
  cursor: pointer;
  display: none;
}
.merge-btn:hover { background: #059669; }
.merge-btn.visible { display: inline-block; }

/* ---------- Symbol Gallery & Cards ---------- */
.symbol-card {
  border: 2px solid #e5e7eb;
  border-radius: 8px;
  padding: 10px;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
  background: white;
  overflow: hidden;
}
.symbol-card img {
  max-width: 100%;
  max-height: 100px;
  object-fit: contain;
  margin-bottom: 8px;
  display: block;
}
.symbol-card:hover {
  border-color: #3b82f6;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
  transform: translateY(-2px);
}

.symbol-card.small {
  position: relative;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  padding: 6px;
  background: #f9fafb;
  text-align: center;
  min-height: 80px;
}
.symbol-card.small img {
  width: 100%;
  height: 60px;
  object-fit: contain;
  display: block;
  margin-bottom: 4px;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.symbols-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 8px;
}

/* ---------- Custom Symbols Panel ---------- */
.custom-word-item {
  margin-bottom: 12px;
  padding: 12px;
  background: white;
  border-radius: 8px;
  border: 1px solid #e5e7eb;
}
.custom-word-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.custom-word-title {
  font-weight: 600;
  color: #1e293b;
  font-size: 1.05rem;
}
.delete-word-btn {
  padding: 4px 10px;
  font-size: 0.85rem;
  background: #fee;
  color: #c00;
}
.symbol-delete-btn {
  position: absolute;
  top: 2px;
  right: 2px;
  background: #ef4444;
  color: white;
  border: none;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  line-height: 1;
}

/* ---------- Exercise Module ---------- */
.symbol-wrapper {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
}
.symbol-wrapper.center { justify-content: center; }
.symbol-wrapper.start { justify-content: flex-start; }

.cloned-symbol-img {
  max-width: 160px;
  max-height: 140px;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
}
.symbol-placeholder {
  width: 120px;
  height: 120px;
  border-radius: 10px;
  border: 1px dashed #e5e7eb;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  color: #64748b;
  font-weight: 700;
  cursor: pointer;
}
.mic-btn { padding: 12px; border-radius: 8px; min-width: 56px; font-size: 18px; }
.ex-choices-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
}
.choice-btn {
  padding: 10px;
  border-radius: 8px;
  border: 1px solid #e5e7eb;
  background: #f8fafc;
  text-align: center;
}
.ex-feedback { margin-top: 8px; }

/* ---------- Dialogs & Overlays ---------- */
.custom-dialog {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: white;
  padding: 20px;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  z-index: 10000;
  text-align: center;
  max-width: 500px;
}
.preview-img {
  max-width: 400px;
  max-height: 400px;
  border-radius: 8px;
  margin-bottom: 16px;
}
.dialog-message { font-size: 1.1rem; margin-bottom: 16px; }
.dialog-btn-container { display: flex; gap: 12px; justify-content: center; }
.crop-btn { padding: 10px 20px; background: #f59e0b; }
.dialog-button { padding: 10px 20px; }
.dialog-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.5);
  z-index: 9999;
}

/* ---------- Karaoke ---------- */
.karaoke-overlay {
  position: fixed;
  left: 50%;
  top: 14%;
  transform: translateX(-50%);
  background: #ffffff;
  border-radius: 12px;
  padding: 12px 14px;
  box-shadow: 0 8px 30px rgba(2,6,23,0.25);
  z-index: 20000;
  max-width: 90%;
  min-width: 320px;
  display: flex;
  gap: 12px;
  align-items: center;
}
.karaoke-words {
  flex: 1;
  line-height: 1.6;
  font-size: 1.15rem;
  color: #0f172a;
}
.karaoke-word {
  padding: 2px 4px;
  border-radius: 6px;
  display: inline-block;
}
.karaoke-word.karaoke-highlight {
  background: #fde68a;
  color: #92400e;
  box-shadow: 0 2px 6px rgba(15,23,42,0.08);
}
.karaoke-symbol-highlight {
  outline: 3px solid #93c5fd !important;
  box-shadow: 0 4px 18px rgba(37,99,235,0.15);
}

@keyframes karaokePulse {
  0%   { box-shadow: 0 6px 22px rgba(37,99,235,0.18); transform: scale(1);    }
  50%  { box-shadow: 0 10px 30px rgba(37,99,235,0.28); transform: scale(1.03); }
  100% { box-shadow: 0 6px 22px rgba(37,99,235,0.18); transform: scale(1);    }
}
.tile.karaoke-symbol-highlight-tile {
  outline: 3px solid #60a5fa !important;
  border-radius: 10px;
  animation: karaokePulse 1000ms ease-in-out infinite;
}

.karaoke-stop-button {
  background: #ef4444;
  color: #fff;
  border: none;
  padding: 8px 12px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 700;
}
.karaoke-stop-button[aria-pressed="true"] { opacity: 0.8; }

/* ---------- Status bar error state ---------- */
#live.error {
  color: #b30000 !important;
  font-weight: bold;
  background: #fff0f0;
  padding: 0.3em 0.7em;
  border-radius: 6px;
  font-size: 1.3em;
  min-height: 2.2em;
  transition: background 0.2s;
}

/* ---------- Guide Modals ---------- */
.guide-modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.7);
  z-index: 10001;
  align-items: center;
  justify-content: center;
  overflow-y: auto;
  padding: 20px;
}
.guide-modal-content {
  background: white;
  padding: 32px;
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.3);
  max-width: 900px;
  width: 95%;
  max-height: 85vh;
  overflow-y: auto;
  margin: auto;
  position: relative;
}
.guide-modal-content h1,
.guide-modal-content h2,
.guide-modal-content h3 {
  color: var(--brand);
  margin-top: 1.5em;
  margin-bottom: 0.5em;
}
.guide-modal-content h1 { font-size: 2rem; margin-top: 0; }
.guide-modal-content h2 {
  font-size: 1.5rem;
  border-bottom: 2px solid #e5e7eb;
  padding-bottom: 0.3em;
}
.guide-modal-content h3 { font-size: 1.2rem; }
.guide-modal-content code {
  background: #f3f4f6;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'Courier New', monospace;
  font-size: 0.9em;
}
.guide-modal-content pre {
  background: #1e293b;
  color: #e2e8f0;
  padding: 16px;
  border-radius: 8px;
  overflow-x: auto;
  font-size: 0.9em;
}
.guide-modal-content pre code { background: none; color: inherit; padding: 0; }
.guide-modal-content ul,
.guide-modal-content ol { line-height: 1.8; margin: 1em 0; }
.guide-modal-content li { margin: 0.5em 0; }
.guide-modal-content table { width: 100%; border-collapse: collapse; margin: 1em 0; }
.guide-modal-content th,
.guide-modal-content td { border: 1px solid #e5e7eb; padding: 10px; text-align: left; }
.guide-modal-content th { background: #f9fafb; font-weight: 600; }
.guide-modal-content a { color: var(--brand); text-decoration: none; }
.guide-modal-content a:hover { text-decoration: underline; }

.guide-close-btn {
  position: sticky;
  top: 0;
  right: 0;
  float: right;
  background: #ef4444;
  color: white;
  border: none;
  border-radius: 8px;
  padding: 8px 16px;
  font-weight: 700;
  cursor: pointer;
  font-size: 1rem;
  margin-bottom: 16px;
  z-index: 10;
}
.guide-close-btn:hover { background: #dc2626; }

/* ---------- Logo ---------- */
#asphiLogo {
  height: 48px;
  width: auto;
  display: inline-block;
  vertical-align: middle;
  transition: transform 120ms ease, opacity 120ms ease;
  cursor: pointer;
}
#asphiLogoLink { display: inline-block; line-height: 1; }
#asphiLogoLink:hover #asphiLogo { transform: scale(1.05); opacity: 0.95; }

/* ---------- Toolbar right column alignment ---------- */
.toolbar-right {
  display: flex !important;
  flex-wrap: wrap !important;
  gap: 8px !important;
  align-items: center !important;
  justify-content: flex-end !important;
  min-width: 160px;
}
.toolbar-right > * { margin-bottom: 0 !important; }
.toolbar-right .button,
.toolbar-right .button.ghost,
.toolbar-right .merge-btn,
.toolbar-right .lang-flag {
  margin-bottom: 0 !important;
  height: 44px !important;
  padding: 8px 12px !important;
  display: inline-flex !important;
  align-items: center !important;
  gap: 8px !important;
  box-sizing: border-box !important;
}
.listen-group {
  display: flex !important;
  gap: 8px !important;
  align-items: center !important;
}
.listen-group .button { min-width: unset !important; }
#symbolsLegendWrapper { display: inline-flex; align-items: center; }

/* ---------- Legend Responsive ---------- */
#symbolsLegend > div {
  display: inline-flex;
  gap: 14px;
  align-items: flex-start;
  flex-wrap: wrap;
}

/* ---------- Settings Modal Responsive ---------- */
@media (max-width: 768px) {
  #settingsModal > div {
    padding: 16px !important;
    width: 95% !important;
    max-height: 95vh !important;
  }
  #settingsModal h2 { font-size: 1.2rem !important; }
  #settingsModal input,
  #settingsModal select,
  #settingsModal button { padding: 10px !important; font-size: 0.95rem !important; }
  #customSymbolsList { max-height: 200px !important; }
  .guide-modal-content { padding: 20px; max-width: 100%; }
  .guide-modal-content h1 { font-size: 1.5rem; }
  .guide-modal-content h2 { font-size: 1.3rem; }
  .guide-modal-content h3 { font-size: 1.1rem; }
}

@media (max-width: 480px) {
  #settingsModal > div { padding: 12px !important; }
  #settingsModal h2 { font-size: 1.1rem !important; margin-bottom: 16px !important; }
}

/* ---------- Responsive: Tablets ---------- */
@media (max-width: 900px) {
  .toolbar-right { min-width: unset !important; align-items: flex-end; }
  .toolbar-right button { font-size: 0.95rem; }
  .listen-group { gap: 6px; }
}

/* ---------- Responsive: Small Screens ---------- */
@media (max-width: 720px) {
  body { padding: 12px; padding-bottom: 110px; }
  .toolbar { grid-template-columns: 1fr !important; gap: 12px; }
  .toolbar > div {
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
  }
  #textInput { font-size: 1.15rem !important; min-height: 4.5em !important; padding: 12px !important; }
  .lang-flag { padding: 10px 12px; min-width: 50px; border-radius: 10px; }
  .lang-flag .lang-abbr { font-size: 0.9rem; }
  .toolbar .button,
  .toolbar .button.ghost,
  .toolbar .merge-btn,
  .toolbar .merge-btn.visible {
    width: 100% !important;
    box-sizing: border-box;
    padding: 12px !important;
    font-size: 1rem !important;
  }
  #selectLocalFolderButton,
  #guidaRapidaButton,
  #guidaAvanzataButton,
  #videoTutorialButton { width: 100% !important; }
  .result {
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 12px;
    padding-bottom: 90px;
  }
  .tile {
    width: 100% !important;
    min-height: 96px;
    flex-direction: row;
    gap: 12px;
    align-items: center;
    padding: 8px;
  }
  .tile img { width: 88px; height: 88px; object-fit: contain; margin: 0; }
  .tile .word { font-size: 1.05rem; white-space: normal; }
  .badges { justify-content: flex-start; margin-top: 0; }
  .add-symbol-btn, .abc-btn, .remove-symbol-btn {
    top: auto !important;
    right: 8px !important;
    bottom: 8px !important;
  }
  .action-buttons-container { justify-content: flex-end !important; gap: 6px !important; }
  .status {
    position: fixed !important;
    left: 8px !important;
    right: 8px !important;
    bottom: 8px !important;
    background: rgba(255,255,255,0.95) !important;
    padding: 10px 14px !important;
    border-radius: 12px !important;
    box-shadow: 0 8px 22px rgba(0,0,0,0.14) !important;
    z-index: 9999 !important;
    text-align: center !important;
  }
  .guide-modal-content {
    padding: 16px !important;
    width: 100% !important;
    max-width: 100% !important;
    border-radius: 12px !important;
  }
  #settingsModal > div { width: 95% !important; padding: 12px !important; }
  #customSymbolsList { max-height: 220px !important; }
  #asphiLogo { height: 36px; }
  .button, .button.ghost, .lang-flag {
    min-height: 48px;
    padding: 12px 14px;
    font-size: 1.02rem;
  }
}

@media (max-width: 640px) {
  .toolbar-right {
    width: 100% !important;
    flex-direction: row !important;
    align-items: center !important;
    justify-content: flex-end !important;
    gap: 8px;
  }
  .toolbar-right > * { margin-bottom: 0 !important; }
  .listen-group { flex-wrap: wrap; width: auto; }
  .listen-group button, .toolbar-right button { flex: 0 1 auto; padding: 8px 10px; }
  #translateButton, #createExercisesButton { width: 100%; }
}

@media (max-width: 460px) {
  #symbolsLegend > div {
    display: flex !important;
    flex-direction: column !important;
    gap: 8px !important;
    align-items: stretch !important;
    padding: 6px 8px !important;
  }
  #symbolsLegend > div > div[role="listitem"] {
    min-width: 0 !important;
    width: 100% !important;
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    gap: 8px !important;
  }
  #symbolsLegend > div > div[role="listitem"] span { display: inline-block; }
  .toolbar-right {
    flex-direction: column !important;
    align-items: stretch !important;
    justify-content: flex-start !important;
  }
  .listen-group {
    display: flex;
    flex-direction: row;
    gap: 8px;
    justify-content: flex-start;
  }
  .listen-group button { flex: 1 1 48%; }
  .karaoke-overlay {
    left: 50%;
    transform: translateX(-50%);
    top: 8%;
    max-width: 96%;
    min-width: unset;
    padding: 10px;
  }
  #settingsModal > div, .guide-modal-content { width: 95% !important; }
  #exModalPreview { max-height: 40vh; }
  .karaoke-words { font-size: 1rem; max-height: 28vh; }
  .karaoke-words .karaoke-word { padding: 1px 3px; }
}

@media (max-width: 360px) {
  #asphiLogo { height: 30px; }
  #textInput { font-size: 1.05rem !important; }
}

@media (max-width: 340px) {
  #symbolsLegend, #symbolsLegend > div { font-size: 0.9rem !important; }
}

/* ---------- Sentence Actions ---------- */
.sentence-actions {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 10;
  background: rgba(255, 255, 255, 0.95);
  padding: 6px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
.sentence-action-btn {
  padding: 6px 10px;
  font-size: 0.9rem;
  min-width: unset;
}
.sentence-action-btn-delete {
  padding: 6px 10px;
  font-size: 0.9rem;
  min-width: unset;
  background: #fee;
  color: #c00;
}
.sentence-action-btn-explain {
  padding: 6px 10px;
  font-size: 1.1rem;
  font-weight: bold;
  min-width: unset;
}

/* ---------- Repo Badge (OpenSymbols) ---------- */
.repo-badge {
  background: #e0e7ef;
  color: #1e293b;
  font-size: .75rem;
  font-weight: bold;
  border-radius: 6px;
  padding: 2px 6px;
  margin-left: 8px;
}

/* ---------- WCAG: Reduced motion preference ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---------- WCAG: High contrast mode support ---------- */
@media (forced-colors: active) {
  .tile { border: 2px solid ButtonText; }
  .button, .button.ghost { border: 2px solid ButtonText !important; }
  .lang-flag.active { outline: 3px solid Highlight; }
}

/* ---------- Crop Editor ---------- */
.crop-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.9);
  z-index: 10000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.crop-title {
  color: white;
  margin-bottom: 20px;
  font-size: 1.5rem;
}
.crop-instruction {
  color: #ccc;
  margin-bottom: 10px;
}
.crop-canvas-container {
  position: relative;
  margin-bottom: 20px;
}
.crop-canvas {
  max-width: 90vw;
  max-height: 60vh;
  cursor: crosshair;
  border: 2px solid white;
}
.crop-btn-container {
  display: flex;
  gap: 12px;
}
.crop-confirm-btn {
  padding: 12px 24px;
  font-size: 1.1rem;
}
.crop-cancel-btn {
  padding: 12px 24px;
  font-size: 1.1rem;
  color: white;
  border-color: white;
}
