  *,
  *::before,
  *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
  }

  body {
    font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
    background: #f5f5f5;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 2rem 1rem;
    color: #222;
    visibility: hidden;
  }

  body.lang-zh {
    font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Source Han Sans SC", "WenQuanYi Micro Hei", sans-serif;
  }

  body.no-transition,
  body.no-transition * {
    transition: none !important;
  }

  .container {
    width: 100%;
    max-width: 480px;
  }

  body.mode-ref .container {
    max-width: 860px;
  }

  /* ── Settings panel ── */
  details {
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    margin-bottom: 1.5rem;
  }

  summary {
    padding: 0.75rem 1rem;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
    color: #555;
    user-select: none;
    list-style: none;
  }

  summary::-webkit-details-marker {
    display: none;
  }

  summary::before {
    content: "▸ ";
  }

  details[open] summary::before {
    content: "▾ ";
  }

  .settings-body {
    padding: 0.75rem 1rem 1rem;
    border-top: 1px solid #eee;
  }

  .setting-row {
    margin-bottom: 0.75rem;
    display: flex;
    flex-direction: column;
  }

  .mode-selector {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
  }

  #verb-settings, #word-settings, #sentence-settings {
    border-top: 1px solid #f0f0f0;
    padding-top: 0.75rem;
    margin-top: 0.5rem;
  }

  .setting-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: #777;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.4rem;
  }

  .chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
  }

  .chips input[type=checkbox],
  .chips input[type=radio] {
    display: none;
  }

  .chips label {
    padding: 0.3rem 0.7rem;
    border: 1.5px solid #ddd;
    border-radius: 20px;
    font-size: 0.85rem;
    cursor: pointer;
    color: #555;
    transition: all 0.1s;
  }

  .chips input:checked+label {
    border-color: #4a90d9;
    background: #e8f2fc;
    color: #1a5fa8;
    font-weight: 600;
  }

  .toggles {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
  }

  .toggle-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-size: 0.9rem;
    cursor: pointer;
  }

  .toggle-row input[type=checkbox] {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: #4a90d9;
  }

  /* ── Quiz card ── */
  #quiz-card {
    position: relative;
  }

  .card {
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 12px;
    padding: 2rem;
    text-align: center;
  }

  .target-gap {
    font-weight: bold;
    color: #4a90d9;
    text-decoration: underline;
  }

  .noun {
    font-size: 2.8rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-bottom: 0.5rem;
    cursor: pointer;
  }

  .noun:hover {
    color: #4a90d9;
  }

  .prompt {
    font-size: 1rem;
    color: #666;
    margin-bottom: 1.5rem;
  }

  .prompt strong {
    color: #222;
  }

  #hint-row {
    display: none;
    margin-bottom: 1rem;
  }

  #case-hint {
    font-size: 0.9rem;
    font-weight: 600;
    color: #777;
  }

  #btn-hint {
    display: none;
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    background: none;
    border: 1px solid #ddd;
    color: #aaa;
    font-size: 0.75rem;
    padding: 0.2rem 0.55rem;
    border-radius: 20px;
    font-weight: 400;
  }

  #btn-hint:hover {
    border-color: #bbb;
    color: #888;
  }

  input[type=text] {
    width: 100%;
    font-size: 1.2rem;
    padding: 0.6rem 0.8rem;
    border: 2px solid #ddd;
    border-radius: 8px;
    outline: none;
    transition: border-color 0.15s;
  }

  input[type=text]:focus {
    border-color: #4a90d9;
  }

  input[type=text]:disabled {
    background: #fafafa;
    color: #888;
  }

  .buttons {
    display: flex;
    gap: 0.6rem;
    margin-top: 0.75rem;
  }

  button {
    padding: 0.55rem 1.2rem;
    font-size: 0.95rem;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: opacity 0.1s;
  }

  button:hover {
    opacity: 0.85;
  }

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

  #btn-check {
    background: #4a90d9;
    color: white;
    flex: 1;
  }

  #btn-skip {
    background: #eee;
    color: #555;
  }

  #btn-next {
    background: #555;
    color: white;
    width: 100%;
    margin-top: 0.75rem;
    display: none;
  }

  #result {
    margin-top: 1rem;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    font-size: 0.95rem;
    display: none;
  }

  #result.correct {
    background: #e6f4ea;
    color: #1e7e34;
  }

  #result.incorrect {
    background: #fdecea;
    color: #b71c1c;
  }

  #result.skipped {
    background: #fff8e1;
    color: #795548;
  }

  /* ══════════════════════════════════════════════════════
       Reference panel
       ══════════════════════════════════════════════════════ */

  #ref-panel {
    display: none;
  }

  /* ── Main Tabs (Top Level) ── */
  .main-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    border-bottom: 2px solid #ddd;
    padding-bottom: 0.5rem;
  }

  .main-tab-btn {
    padding: 0.5rem 1.25rem;
    background: none;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 700;
    font-size: 1.1rem;
    color: #888;
    transition: all 0.2s;
  }

  .main-tab-btn:hover {
    color: #444;
    background: #eee;
  }

  .main-tab-btn.active {
    color: #4a90d9;
    background: #e8f2fc;
  }

  .main-tab-content {
    display: none;
  }

  .main-tab-content.active {
    display: block;
  }

  /* ── Case Tabs (Secondary Level) ── */
  #ref-panel .tabs {
    display: flex;
    gap: 0.25rem;
    margin-bottom: -1px;
    overflow-x: auto;
    scrollbar-width: none;
  }

  #ref-panel .tabs::-webkit-scrollbar {
    display: none;
  }

  #ref-panel .tab-btn {
    padding: 0.6rem 1.1rem;
    background: #e0e0e0;
    border: 1px solid #ccc;
    border-bottom: none;
    border-radius: 8px 8px 0 0;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.88rem;
    color: #666;
    white-space: nowrap;
    transition: all 0.1s;
  }

  #ref-panel .tab-btn.active {
    background: white;
    border-color: #e0e0e0;
    border-bottom-color: white;
    color: #4a90d9;
    position: relative;
    z-index: 1;
  }

  #ref-panel .tab-content {
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 0 0 12px 12px;
    padding: 1.25rem 1.5rem 1.5rem;
    display: none;
  }

  #ref-panel .tab-content.active {
    display: block;
  }

  @keyframes refFadeIn {
    from {
      opacity: 0;
      transform: translateY(4px);
    }

    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  #ref-panel h2 {
    font-size: 1.3rem;
    margin-bottom: 0.75rem;
    color: #333;
  }

  #ref-panel .usage-box {
    background: #f8fbff;
    border-left: 4px solid #4a90d9;
    padding: 0.65rem 1rem;
    margin-bottom: 1rem;
    font-size: 0.84rem;
    line-height: 1.6;
  }

  #ref-panel .usage-box b {
    color: #333;
  }

  #ref-panel .usage-box ul {
    margin: 0.3rem 0 0 1.1rem;
  }

  #ref-panel .usage-box li {
    margin-bottom: 0.15rem;
  }

  #ref-panel .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 1rem;
  }

  #ref-panel table {
    border-collapse: collapse;
    font-size: 0.81rem;
    width: 100%;
  }

  #ref-panel th,
  #ref-panel td {
    border: 1px solid #d4d4d4;
    padding: 0.28rem 0.55rem;
    text-align: center;
    vertical-align: middle;
    white-space: nowrap;
  }

  #ref-panel thead th {
    background: #ececf4;
    font-weight: 700;
    font-size: 0.76rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #444;
  }

  #ref-panel thead tr:first-child th {
    border-bottom: 1px solid #bbb;
  }

  #ref-panel thead tr:last-child th {
    font-size: 0.72rem;
    color: #555;
  }

  #ref-panel .lbl {
    text-align: left;
    padding-left: 0.6rem;
    font-weight: 700;
    font-size: 0.78rem;
    color: #333;
    width: 110px;
    min-width: 90px;
  }

  #ref-panel .sec-hd td {
    background: #e8e8ee;
    font-weight: 700;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #555;
    padding: 0.22rem 0.6rem;
    text-align: left;
  }

  #ref-panel .row-end td {
    background: #f4f8ff;
  }

  #ref-panel .row-end .lbl {
    color: #1a5fa8;
  }

  #ref-panel .e {
    color: #1a5fa8;
    font-weight: 700;
  }

  #ref-panel .same {
    color: #aaa;
    font-style: italic;
    font-size: 0.75rem;
  }

  #ref-panel .eg {
    display: block;
    color: #666;
    font-weight: 400;
    font-style: italic;
    font-size: 0.73rem;
    margin-top: 0.15rem;
    white-space: normal;
    line-height: 1.4;
  }

  #ref-panel .notes {
    margin-top: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
  }

  #ref-panel .hi {
    color: #1a5fa8;
    font-weight: 700;
  }

  #ref-panel .warn {
    color: #b05000;
    font-weight: 600;
  }

  #ref-panel .note-box {
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    overflow: hidden;
  }

  #ref-panel .note-box-title {
    padding: 0.5rem 0.75rem;
    background: #f2f2f7;
    font-weight: 700;
    font-size: 0.82rem;
    color: #444;
  }

  #ref-panel .note-box-body {
    padding: 0.65rem 0.85rem 0.75rem;
    font-size: 0.82rem;
    line-height: 1.6;
  }

  #ref-panel .note-box-body p {
    margin-bottom: 0.4rem;
  }

  #ref-panel .note-box-body p:last-child {
    margin-bottom: 0;
  }

  #ref-panel .alt-wrap {
    overflow-x: auto;
    margin-top: 0.4rem;
  }

  #ref-panel .alt-table {
    font-size: 0.79rem;
    border-collapse: collapse;
    width: auto;
  }

  #ref-panel .alt-table td {
    border: 1px solid #d4d4d4;
    padding: 0.2rem 0.5rem;
    text-align: left;
    white-space: nowrap;
    vertical-align: middle;
  }

  #ref-panel .alt-table .from {
    font-weight: 700;
    color: #c0392b;
    width: 1.8rem;
  }

  #ref-panel .alt-table .to {
    font-weight: 700;
    color: #1a5fa8;
    width: 2.2rem;
  }

  #ref-panel .alt-table .exa {
    color: #555;
  }

  #ref-panel .mnemonic {
    display: inline-block;
    margin-top: 0.35rem;
    background: #fff8e1;
    border: 1px solid #f0c040;
    border-radius: 4px;
    padding: 0.25rem 0.55rem;
    font-size: 0.8rem;
    font-weight: 600;
    color: #6b4800;
  }

  /* ── Conjugation layout ── */
  .conj-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 1.25rem 2.5rem;
  }

  .conj-section {
    flex: 1 1 200px;
  }

  .conj-section-title {
    font-size: 1rem;
    font-weight: 700;
    color: #333;
    margin-bottom: 0.6rem;
  }

  .table-title {
    font-size: 0.82rem;
    font-weight: 600;
    color: #555;
    margin: 0.5rem 0 0.25rem;
  }

  .table-note {
    font-size: 0.8rem;
    color: #666;
    margin-bottom: 0.3rem;
    font-style: italic;
  }

  .conj-section .table-wrap table {
    width: auto;
  }

  .conj-section .table-wrap td:not(.lbl) {
    text-align: left;
    min-width: 6rem;
  }

  @media (max-width: 600px) {
    #ref-panel .tab-btn {
      padding: 0.5rem 0.75rem;
      font-size: 0.82rem;
    }

    #ref-panel .tab-content {
      padding: 1rem;
    }
  }

  /* ── Preposition chips & detail panel ── */
  .prep-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-bottom: 1.25rem;
  }

  .prep-chip {
    padding: 0.28rem 0.65rem;
    background: #f0f0f5;
    border: 1.5px solid #d8d8e0;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    color: #444;
    font-family: inherit;
    transition: all 0.1s;
  }

  .prep-chip:hover {
    background: #e4e4ee;
    border-color: #bbb;
  }

  .prep-chip.active {
    background: #4a90d9;
    border-color: #3a7bc8;
    color: white;
  }

  .prep-panel {
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 1rem 1.25rem 1.25rem;
    background: white;
    animation: refFadeIn 0.15s ease-out;
  }

  .prep-detail { display: none; }
  .prep-detail.active { display: block; }

  .prep-header {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    margin-bottom: 0.9rem;
    padding-bottom: 0.6rem;
    border-bottom: 1px solid #eee;
  }

  .prep-name {
    font-size: 1.4rem;
    font-weight: 700;
    color: #222;
  }

  .prep-gloss {
    font-size: 0.9rem;
    color: #888;
    font-style: italic;
  }

  .prep-case-block {
    margin-bottom: 0.85rem;
  }

  .prep-case-block:last-child {
    margin-bottom: 0;
  }

  .case-badge {
    display: inline-block;
    padding: 0.12rem 0.5rem;
    border-radius: 4px;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.4rem;
  }

  .badge-gen  { background: #fde8d8; color: #9a3800; }
  .badge-dat  { background: #d8f0e8; color: #006040; }
  .badge-acc  { background: #d8e8fd; color: #003090; }
  .badge-inst { background: #ede8fd; color: #4a0090; }
  .badge-loc  { background: #fdf5d8; color: #5a4800; }

  .prep-desc {
    font-size: 0.83rem;
    color: #555;
    margin-bottom: 0.35rem;
    line-height: 1.5;
  }

  .prep-examples {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.18rem;
  }

  .prep-examples li {
    font-size: 0.83rem;
    line-height: 1.5;
    color: #444;
  }

  .prep-examples em {
    color: #1a5fa8;
    font-style: normal;
    font-weight: 600;
  }

  /* ── Verb government ── */
  .gov-verb-list {
    list-style: none;
    padding: 0;
    margin: 0.5rem 0 0;
    display: flex;
    flex-direction: column;
  }

  .gov-verb-item {
    padding: 0.35rem 0;
    border-bottom: 1px solid #f0f0f5;
  }

  .gov-verb-item:last-child { border-bottom: none; }

  .gov-verb-row {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    flex-wrap: wrap;
  }

  .gov-verb-pl {
    font-weight: 700;
    color: #222;
    min-width: 130px;
  }

  .gov-verb-en {
    color: #555;
    font-size: 0.84rem;
  }

  .gov-verb-note {
    margin-top: 0.25rem;
    padding-left: 0.6rem;
    border-left: 2px solid #e0e0e8;
    font-size: 0.79rem;
    color: #666;
    font-style: italic;
    line-height: 1.5;
  }

  /* ── Motion verbs ── */
  .motion-pair {
    border: 1px solid #e8e8ee;
    border-radius: 8px;
    padding: 0.85rem 1rem 0.9rem;
    margin-bottom: 0.85rem;
  }

  .motion-pair:last-of-type { margin-bottom: 0; }

  .motion-verbs-header {
    display: flex;
    align-items: baseline;
    gap: 0.4rem;
    flex-wrap: wrap;
    padding-bottom: 0.4rem;
    margin-bottom: 0.6rem;
    border-bottom: 1px solid #e8e8ee;
  }

  .motion-det   { font-size: 1.05rem; font-weight: 700; color: #1a5fa8; }
  .motion-sep   { color: #aaa; }
  .motion-indet { font-size: 1.05rem; font-weight: 700; color: #4a90d9; }

  .motion-examples {
    list-style: none;
    padding: 0;
    margin: 0.5rem 0 0;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
  }

  .motion-examples li {
    font-size: 0.84rem;
    color: #555;
    font-style: italic;
    padding-left: 0.65rem;
    border-left: 2px solid #c8ddf0;
  }

  /* ── Language switching ── */
  body .lang-pl,
  body .lang-uk {
    display: none;
  }

  body.lang-pl .lang-pl {
    display: block;
  }

  body.lang-pl .lang-en {
    display: none;
  }

  body.lang-uk .lang-uk {
    display: block;
  }

  body.lang-uk .lang-en {
    display: none;
  }
  .dictionary-search input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #ddd;
    border-radius: 8px;
    margin-bottom: 1rem;
    font-size: 1rem;
  }

  .dict-results {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
  }

  .dict-result-item {
    padding: 0.75rem;
    border: 1px solid #eee;
    border-radius: 8px;
    cursor: pointer;
    background: #fdfdfd;
    transition: background 0.1s;
    text-align: left;
  }

  .dict-result-item:hover {
    background: #f5f5f5;
  }

  .dict-result-item .word {
    font-weight: bold;
    color: #222;
  }

  .dict-result-item .pos {
    font-size: 0.8rem;
    color: #666;
    margin-left: 0.5rem;
  }

  .dict-entry-header {
    margin-bottom: 1rem;
  }

  .dict-entry-header h2 {
    margin-top: 0;
    margin-bottom: 0.25rem;
    font-size: 1.3rem;
  }

  .dict-aspect {
    font-size: 0.85rem;
    color: #555;
    font-weight: normal;
    margin-left: 0.3rem;
  }

  .dict-counterpart {
    font-size: 0.85rem;
    color: #555;
    font-weight: normal;
    margin-left: 0.2rem;
  }

  .dict-entry-detail h2 {
    margin-top: 0;
    margin-bottom: 0.5rem;
  }

  .dict-entry-detail .pos {
    font-style: italic;
    color: #666;
    margin-bottom: 1rem;
    display: block;
  }

  .dict-usage-note {
    font-size: 0.85rem;
    color: #666;
  }

  .dict-synonyms {
    font-size: 0.85rem;
    color: #555;
    margin: 0.25rem 0 0.4rem 1.5rem;
  }

  .dict-syn-link {
    color: #4a90d9;
    cursor: pointer;
  }

  .dict-syn-link:hover {
    text-decoration: underline;
  }

  .dict-sense {
    margin-bottom: 1.5rem;
    text-align: left;
  }

  .dict-gloss {
    font-size: 1rem;
    line-height: 1.4;
    color: #333;
    margin-bottom: 0.5rem;
  }

  .dict-examples {
    list-style: none;
    padding: 0;
    margin: 0;
    font-size: 0.9rem;
    color: #555;
    border-left: 3px solid #eee;
    padding-left: 0.75rem;
  }

  .dict-example {
    margin-bottom: 0.4rem;
  }

  .back-to-search {
    background: none;
    border: none;
    color: #4a90d9;
    cursor: pointer;
    font-size: 0.9rem;
    padding: 0;
    margin-bottom: 1.5rem;
    display: block;
  }

  .back-to-search:hover {
    text-decoration: underline;
  }

  .declension-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1.5rem;
    font-size: 0.9rem;
  }

  .declension-table th, .declension-table td {
    border: 1px solid #eee;
    padding: 0.5rem;
    text-align: left;
  }

  .declension-table th {
    background: #f9f9f9;
    font-weight: 600;
  }

  .verb-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1.5rem;
    font-size: 0.9rem;
  }

  .verb-table th, .verb-table td {
    border: 1px solid #eee;
    padding: 0.5rem;
    text-align: left;
  }

  .verb-table th {
    background: #f9f9f9;
    font-weight: 600;
  }

  /* Make chunks clickable in quiz */
  .target-gap {
    cursor: pointer;
  }

  .target-gap:hover {
    background: #e8f2fc;
  }
