:root {
  --bg: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --border: #e5e7eb;
  --header-bg: #f3f4f6;
  --link: #1d4ed8;

  --red: #ff6b6b;
  --red-hi: #e11d48;
  --teal: #0f766e;
  --teal-hi: #0b5c56;
  --green: #2e7d32;
  --green-hi: #166534;
  --blue: #1e40af;
  --blue-hi: #1d4ed8;
  --ipa: #ffa07a;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --text: #e5e7eb;
    --muted: #9ca3af;
    --border: #243145;
    --header-bg: #111b2e;
    --link: #93c5fd;
  }
}

/* Explicit theme override */
html[data-theme="dark"] {
  --bg: #0b1220;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --border: #243145;
  --header-bg: #111b2e;
  --link: #93c5fd;
}

html[data-theme="light"] {
  --bg: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --border: #e5e7eb;
  --header-bg: #f3f4f6;
  --link: #1d4ed8;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  font-size: 18px;
  line-height: 1.35;
  color: var(--text);
  background: var(--bg);
}

button,
input {
  font: inherit;
  color: inherit;
}

a {
  color: var(--link);
}

.links a {
  text-decoration: none;
}

.links a:hover {
  text-decoration: underline;
}

.footer-meta {
  margin: 14px 0 28px 0;
  color: var(--muted);
  font-size: 13px;
}

.footer-line {
  display: block;
  margin-top: 4px;
}

.footer-line:first-child {
  margin-top: 0;
}

.footer-line.attribution {
  font-size: 12px;
  opacity: 0.8;
}

.footer-line.attribution a {
  opacity: 0.9;
}

.container {
  max-width: 1320px;
  margin: 0 auto;
  padding: 14px;
}

header h1 {
  margin: 0 0 10px 0;
}

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

.title-row h1 {
  margin: 0;
}

.btn-theme {
  padding: 8px 10px;
  font-size: 18px;
  line-height: 1;
}

.links {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  margin: 0 0 14px 0;
  align-items: center;
}

.search {
  position: relative;
  z-index: 200;
  background: var(--bg);
  padding: 10px 0;
  margin: 10px 0 12px 0;
}

.search-inner {
  position: relative;
}

.search.floating {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%) translateY(-10px);
  width: min(980px, calc(100% - 24px));
  margin: 0;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.08);
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 180ms ease,
    transform 220ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.search.floating.show {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}

.search.floating .status {
  display: none;
}

.search.floating.show #irrRow {
  display: none;
}

#searchPlaceholder {
  height: 0;
}

#q {
  width: 100%;
  padding: 10px 12px;
  font-size: 18px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
}

.search ::placeholder {
  color: var(--muted);
}

.search-row {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 10px;
  width: min(980px, 100%);
}

.irr-row {
  display: flex;
  gap: 6px;
  align-items: center;
  justify-content: flex-end;
}

.btn-irr {
  padding: 8px 10px;
  font-size: 14px;
  line-height: 1;
}

.btn-irr-yellow {
  border-color: rgba(234, 179, 8, 0.55);
  background: rgba(234, 179, 8, 0.2);
}

.btn-irr-orange {
  border-color: rgba(249, 115, 22, 0.55);
  background: rgba(249, 115, 22, 0.16);
}

.btn-irr-red {
  border-color: rgba(225, 29, 72, 0.45);
  background: rgba(225, 29, 72, 0.12);
}

#q {
  min-width: 0;
}

.btn {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 16px;
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover {
  background: var(--header-bg);
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  border-color: rgba(29, 78, 216, 0.35);
  background: rgba(29, 78, 216, 0.14);
}

.btn-primary:hover {
  background: rgba(29, 78, 216, 0.2);
}

.btn-random {
  border-color: rgba(234, 179, 8, 0.45);
  background: linear-gradient(135deg, rgba(234, 179, 8, 0.25), rgba(236, 72, 153, 0.18));
  position: relative;
  overflow: hidden;
}

.btn-random::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 30% 20%, rgba(255, 255, 255, 0.35), transparent 45%);
  opacity: 0;
  transition: opacity 160ms ease;
}

.btn-random:hover::after {
  opacity: 1;
}

.btn-icon {
  margin-right: 6px;
}

.status {
  margin-top: 6px;
  color: var(--muted);
  font-size: 14px;
}

.suggestions {
  position: absolute;
  top: 100%;
  margin-top: 6px;
  width: min(720px, 100%);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.08);
  display: none;
  z-index: 500;
  max-height: 420px;
  overflow-y: auto;
}

.suggestions.visible {
  display: block;
}

.suggestion {
  padding: 10px 12px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.suggestion:hover,
.suggestion[aria-selected="true"] {
  background: var(--header-bg);
}

.suggestion small {
  color: var(--muted);
}

.legend-wrapper {
  margin: 10px 0 0 0;
}

/* Desktop: show legend normally */
.legend-desktop {
  display: block;
}

/* Mobile: hide desktop legend */
@media (max-width: 700px) {
  .legend-desktop {
    display: none;
  }
}

/* Mobile legend toggle button */
.legend-toggle-mobile {
  display: none;
  padding: 8px 12px;
  font-size: 12px;
  line-height: 1;
  background: var(--header-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  color: var(--text);
}

.legend-toggle-mobile:hover {
  background: var(--border);
}

/* Show legend button on mobile */
@media (max-width: 700px) {
  .legend-toggle-mobile {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
}

/* Mobile overlay */
.legend-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.legend-overlay[hidden] {
  display: none;
}

.legend-overlay-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
}

.legend-overlay-content {
  position: relative;
  background: var(--bg);
  border-radius: 12px;
  padding: 20px;
  margin: 20px;
  max-width: 320px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
  z-index: 1001;
}

.legend-close {
  position: absolute;
  top: 8px;
  right: 12px;
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--muted);
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}

.legend-close:hover {
  background: var(--border);
  color: var(--text);
}

.legend-overlay-body {
  font-size: 14px;
  line-height: 1.5;
}

.legend-overlay-body .legend {
  margin-bottom: 12px;
}

.legend-overlay-body .legend-random {
  margin: 12px 0;
  font-size: 13px;
}

.legend-overlay-body .legend-hint {
  margin-top: 12px;
  font-size: 13px;
}

.legend-overlay-body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 12px 0;
}

.legend {
  margin: 0;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

.main-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.main-table tr,
.main-table td {
  background: var(--bg);
}

.main-table th,
.main-table td {
  border: 1px solid var(--border);
  padding: 10px;
  vertical-align: top;
  text-align: left;
  overflow-wrap: normal;
  word-break: normal;
  overflow: visible;
}

.main-table th {
  background: var(--header-bg);
  white-space: nowrap;
}

.col-inf {
  width: 12%;
}

.col-part {
  width: 10%;
}

.cell-label {
  display: none;
}

.main-table tr:focus {
  outline: 2px solid rgba(29, 78, 216, 0.45);
  outline-offset: -2px;
}

.main-table tr:focus-visible {
  outline: 2px solid rgba(29, 78, 216, 0.65);
}

.main-table tr {
  scroll-margin-top: 90px;
}

.verb {
  font-weight: 700;
  font-size: 20px;
}

.irregularity {
  font-size: 20px;
  display: inline-block;
  margin-top: 0;
  line-height: 1.1;
}

.speaker {
  margin-left: 6px;
  font-weight: 400;
}

.clickable-audio {
  cursor: pointer;
  user-select: none;
}

.clickable-audio:hover {
  text-decoration: underline;
}

.speaker.clickable-audio:hover {
  text-decoration: none;
}

.wiktionary-link {
  font-size: 12px;
  font-weight: 400;
}

.alt-badge {
  display: inline-block;
  font-size: 11px;
  padding: 1px 6px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--header-bg);
  color: var(--text);
  vertical-align: baseline;
}

.lemma-ipa {
  font-style: italic;
  color: var(--blue);
}

.ipa-link {
  text-decoration: none;
  font-style: italic;
  color: var(--ipa);
}

.ipa-link,
.lemma-ipa {
  font-family:
    "Noto Sans IPA",
    "Noto Sans",
    "DejaVu Sans",
    "Segoe UI",
    Arial,
    sans-serif;
  font-variant-ligatures: none;
  font-feature-settings: "liga" 0, "clig" 0;
}

.ipa-link:hover {
  text-decoration: underline;
}

.participles {
  text-align: center;
  font-size: 16px;
}

.inf-row {
  display: block;
}

.inf-links {
  margin-top: 6px;
}

.part-grid {
  display: block;
}

.part-item {
  white-space: nowrap;
}

.part-ipaline {
  margin-top: 2px;
}

.part-ipa {
  white-space: nowrap;
}

.tense-grid {
  display: none;
}

.tense-pron {
  display: none;
}

.tense-form {
  white-space: nowrap;
}

.tense-ipa {
  margin-top: 2px;
}

.part-form {
  display: inline-block;
  white-space: nowrap;
  vertical-align: bottom;
}

/* Single horizontal scrollbar for a whole cell */
.cell-scroll {
  overflow-x: auto;
  max-width: 100%;
}

.cell-scroll > * {
  width: max-content;
}

table.tense-table {
  width: max-content;
  display: table;
  font-size: 14px;
  border-collapse: collapse;
  table-layout: auto;
}

table.tense-table td {
  padding: 2px 6px;
  border: none;
  overflow: visible;
}

.tense-row-col {
  white-space: nowrap;
}

.tense-ipa-inline {
  white-space: nowrap;
  margin-left: 6px;
}

.tense-cell[data-ipa-below="1"] .tense-row {
  white-space: normal;
}

.tense-cell[data-ipa-below="1"] .tense-ipa-inline {
  display: block;
  margin-left: 0;
}

.tense-scroll {
  overflow-x: auto;
  max-width: 100%;
}

.tense-row {
  white-space: nowrap;
  font-kerning: none;
  font-feature-settings: "kern" 0;
}

.tense-form-inline {
  white-space: nowrap;
}

.tense-cell {
  vertical-align: top;
  overflow: hidden;
}

.c-red {
  color: var(--red);
  font-weight: 700;
}

.c-black {
  color: var(--text);
  font-weight: 700;
}

.c-red-hi {
  color: var(--red-hi);
  font-weight: 700;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

.c-teal {
  color: var(--teal);
  font-weight: 700;
}

.c-teal-hi {
  color: var(--teal-hi);
  font-weight: 700;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

.c-green {
  color: var(--green);
  font-weight: 700;
}

.c-green-hi {
  color: var(--green-hi);
  font-weight: 700;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

.c-blue {
  color: var(--blue);
  font-weight: 700;
}

.c-blue-hi {
  color: var(--blue-hi);
  font-weight: 700;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

.c-black,
.c-red,
.c-red-hi,
.c-teal,
.c-teal-hi,
.c-green,
.c-green-hi,
.c-blue,
.c-blue-hi {
  font-kerning: none;
  font-feature-settings: "kern" 0;
}

.audiofrench-link {
  text-decoration: none;
  color: inherit;
  cursor: pointer;
}

.audiofrench-link:hover {
  text-decoration: underline;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Mobile: stack cells vertically to avoid horizontal scrolling */
@media (max-width: 700px) and (orientation: portrait) {
  .container {
    padding: 8px 12px;
  }

  header.container {
    padding-bottom: 4px;
  }

  body {
    font-size: 16px;
  }

  header h1 {
    font-size: 20px;
  }

  .btn-theme {
    font-size: 16px;
    padding: 8px 10px;
  }

  .legend {
    font-size: 14px;
  }

  .legend small {
    font-size: 12px;
  }

  .search-row {
    grid-template-columns: 1fr 1fr;
  }

  #q {
    grid-column: 1 / -1;
  }

  #searchBtn {
    grid-column: 1;
    padding: 10px 12px;
    font-size: 14px;
  }

  #randomBtn {
    grid-column: 2;
    padding: 10px 12px;
    font-size: 14px;
  }

  #irrRow {
    grid-column: 1 / -1;
    justify-content: space-between;
  }

  /* Reduce spacing after status on mobile */
  .status {
    margin-top: 4px;
    margin-bottom: 0;
  }

  .search {
    margin-bottom: 4px;
    padding-bottom: 4px;
  }

  /* Remove legend wrapper spacing on mobile */
  .legend-wrapper {
    margin: 0;
    display: none;
  }

  /* Reduce main padding on mobile */
  main.container {
    padding-top: 4px;
  }

  .btn-irr {
    padding: 8px 10px;
    font-size: 14px;
    flex: 1;
  }

  .search.floating .search-row {
    grid-template-columns: 1fr auto;
    gap: 0;
  }

  .search.floating #q {
    grid-column: 1;
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
  }

  .search.floating #searchBtn {
    grid-column: 2;
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
    border-left: none;
    min-width: 52px;
    padding: 10px 12px;
  }

  .search.floating.show #randomBtn {
    display: none;
  }

  .search.floating.show #irrRow {
    display: none;
  }

  .links a {
    font-size: 13px;
  }

  .btn-theme {
    font-size: 13px;
    padding: 8px 10px;
  }

  .table-wrap {
    overflow-x: visible;
  }

  .main-table thead {
    display: none;
  }

  .main-table,
  .main-table tbody,
  .main-table tr,
  .main-table td {
    display: block;
    width: 100%;
  }

  .main-table tr {
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 12px;
    background: var(--bg);
  }

  .main-table td {
    border: none;
    border-top: 1px solid var(--border);
  }

  .main-table td:first-child {
    border-top: none;
  }

  .cell-label {
    display: block;
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 6px;
    font-weight: 600;
  }

  .verb {
    font-size: 18px;
  }

  /* Compact, horizontal-first layout in portrait */
  .inf-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 6px 10px;
    align-items: start;
  }

  .inf-left {
    min-width: 0;
  }

  .inf-word {
    display: inline-block;
    margin-right: 4px;
  }

  .inf-right {
    flex: none;
    text-align: right;
    align-self: start;
  }

  .cell-scroll > * {
    width: 100%;
  }

  .inf-wordline {
    grid-column: 1;
    grid-row: 1;
  }

  .inf-marker {
    grid-column: 2;
    grid-row: 1;
    margin-top: 0;
  }

  .inf-ipaline {
    grid-column: 1;
    grid-row: 2;
  }

  .inf-links {
    grid-column: 2;
    grid-row: 2;
    margin-top: 0;
  }

  .participles {
    text-align: left;
  }

  .part-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .part-item {
    display: flex;
    flex-wrap: nowrap;
    gap: 6px 10px;
    align-items: baseline;
    min-width: 0;
  }

  .part-item .ipa-link {
    white-space: nowrap;
  }

  .part-item {
    min-width: 0;
  }

  .part-form {
    white-space: nowrap;
    min-width: 0;
  }

  .part-ipa {
    flex: none;
  }

  td.participles[data-ipa-below="1"] .part-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
  }

  td.participles[data-ipa-below="1"] .part-ipaline {
    margin-top: 0;
  }

  table.tense-table {
    display: none;
  }

  .tense-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 10px;
  }

  .tense-grid[data-layout="2x3"] {
    grid-template-columns: 1fr 1fr;
  }

.tense-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
  min-width: 0;
  scroll-margin-top: 96px;
}

.tense-item.picked {
  outline: 2px solid rgba(29, 78, 216, 0.55);
  outline-offset: 2px;
}

.part-form.picked {
  outline: 2px solid rgba(29, 78, 216, 0.55);
  outline-offset: 2px;
  border-radius: 2px;
}

  .tense-pron {
    display: block;
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 4px;
    font-weight: 600;
  }

  .tense-form {
    white-space: nowrap;
    overflow-x: auto;
  }

  .tense-ipa {
    margin-top: 4px;
  }
}

.to-top {
  position: fixed;
  right: 14px;
  bottom: 14px;
  padding: 10px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  opacity: 0;
  transform: translateY(14px);
  pointer-events: none;
  display: inline-flex;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.12);
  transition:
    opacity 180ms ease,
    transform 220ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

html[data-theme="dark"] .to-top {
  background: rgba(17, 27, 46, 0.9);
}

.to-top.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
  align-items: center;
  gap: 6px;
}
