/* Mobile-only layout. Desktop styling remains in style.css. */
@media (max-width: 820px) {
  :root {
    --card-width: 100%;
    --card-height: calc(100dvh - 150px);
    --greek-size: clamp(58px, 21vw, 118px);
    --definition-size: clamp(25px, 7vw, 40px);
    --prompt-size: clamp(16px, 4.6vw, 22px);
    --choice-button-size: clamp(16px, 4.4vw, 21px);
    --bottom-button-size: 13px;
    --audio-button-size: 13px;
  }

  html,
  body {
    width: 100%;
    min-height: 100dvh;
    overflow-x: hidden;
    overscroll-behavior-x: none;
  }

  body {
    padding: 0;
  }

  .app {
    min-height: 100dvh;
  }

  .mobile-header {
    position: fixed;
    inset: 0 0 auto 0;
    height: calc(58px + env(safe-area-inset-top));
    padding-top: env(safe-area-inset-top);
    display: grid;
    grid-template-columns: 54px minmax(0, 1fr) 54px;
    align-items: center;
    z-index: 120;
    background: linear-gradient(180deg, #121120, #151324);
    border-bottom: 1px solid rgba(255,255,255,.10);
    box-shadow: 0 5px 22px rgba(0,0,0,.28);
  }

  .mobile-title {
    min-width: 0;
    padding-inline: 8px;
    color: #f6f2e9;
    font-size: clamp(18px, 5.4vw, 23px);
    font-weight: 800;
    letter-spacing: .01em;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .mobile-icon-btn {
    width: 44px;
    height: 44px;
    justify-self: center;
    display: grid;
    place-items: center;
    padding: 0;
    border: 1px solid rgba(255,255,255,.16);
    border-radius: 12px;
    color: #f6f2e9;
    background: #1d2329;
    font-size: 25px;
    line-height: 1;
  }

  .mobile-backdrop {
    position: fixed;
    inset: 0;
    z-index: 90;
    display: none;
    background: rgba(0,0,0,.60);
    backdrop-filter: blur(1px);
  }

  body.mobile-panel-open .mobile-backdrop {
    display: block;
  }

  .topbar {
    position: fixed !important;
    inset: 0 auto 0 0;
    width: min(88vw, 390px);
    height: 100dvh;
    padding: calc(70px + env(safe-area-inset-top)) 16px calc(22px + env(safe-area-inset-bottom));
    overflow-y: auto;
    z-index: 110;
    transform: translateX(-106%);
    transition: transform .20s ease;
    border-right: 1px solid rgba(255,255,255,.14);
    border-bottom: 0;
    box-shadow: 18px 0 55px rgba(0,0,0,.46);
  }

  body.mobile-tools-open .topbar {
    transform: translateX(0);
  }

  .brand-row {
    justify-content: flex-start;
    margin-bottom: 16px;
    text-align: left;
  }

  .brand-row h1 {
    font-size: 28px;
    line-height: 1.04;
  }

  .brand-row p {
    font-size: 15px;
  }

  .control-row,
  .status-row {
    width: 100%;
    max-width: none;
    margin-inline: 0;
  }

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

  .primary-controls select,
  .primary-controls .btn,
  .primary-controls .check-label {
    width: 100%;
    min-width: 0;
  }

  .primary-controls .check-label {
    min-height: 44px;
    padding: 9px 11px;
    border: 1px solid rgba(255,255,255,.12);
    border-radius: 10px;
    background: rgba(255,255,255,.04);
  }

  .secondary-controls {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-top: 12px;
  }

  .secondary-controls .chip {
    width: 100%;
    padding: 10px 8px;
  }

  .status-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-top: 14px;
  }

  .status-row .pill {
    padding: 8px 8px;
    text-align: center;
  }

  .progress-track {
    grid-column: 1 / -1;
    width: 100%;
    min-width: 0;
    height: 12px;
  }

  .study-shell {
    width: 100%;
    max-width: none;
    margin: 0;
    padding: calc(66px + env(safe-area-inset-top)) 8px calc(78px + env(safe-area-inset-bottom));
  }

  .study-card {
    width: 100%;
    min-height: var(--card-height);
    border-radius: 15px;
  }

  .card-content,
  .study-card.flashcard-mode:not(.is-revealed) .card-content {
    min-height: var(--card-height);
    padding: 60px 14px 26px;
  }

  .study-card.flashcard-mode:not(.is-revealed) .greek-word {
    position: absolute;
    left: 50%;
    top: 43%;
    width: calc(100% - 28px);
    max-width: calc(100% - 28px);
    transform: translate(-50%, -50%);
  }

  .study-card.flashcard-mode:not(.is-revealed) .reveal-hint {
    top: 74%;
    width: calc(100% - 28px);
    max-width: none;
    white-space: normal;
    line-height: 1.25;
  }

  .study-card.is-revealed .card-content {
    justify-content: center;
    padding-top: 64px;
  }

  .study-card.multiple-choice-mode {
    min-height: calc(100dvh - 150px);
    overflow: visible;
  }

  .study-card.multiple-choice-mode .card-content {
    min-height: calc(100dvh - 150px);
    height: auto;
    justify-content: flex-start;
    padding: 76px 14px 26px;
  }

  .study-card.multiple-choice-mode .greek-word {
    width: 100%;
    margin-top: 6px;
  }

  .card-tools {
    position: absolute;
    top: 12px;
    right: 10px;
    left: auto;
    z-index: 5;
    gap: 6px;
    padding: 0;
  }

  .audio-btn {
    min-height: 35px;
    padding: 8px 9px;
    border-radius: 10px;
    font-size: var(--audio-button-size);
  }

  .type-label {
    position: absolute;
    top: 14px;
    left: 50%;
    max-width: 34%;
    margin: 0;
    transform: translateX(-50%);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .greek-word {
    display: block;
    width: 100%;
    max-width: 100%;
    font-size: var(--greek-size);
    line-height: 1.02;
    text-align: center;
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: normal;
    hyphens: none;
    text-wrap: balance;
  }

  .answer-area {
    width: 100%;
    max-width: 100%;
    margin-top: 14px;
  }

  .meaning-text {
    font-size: var(--definition-size);
  }

  .multiple-choice {
    width: 100%;
    grid-template-columns: 1fr;
    gap: 10px;
    margin-top: 12px;
  }

  .choice-btn {
    width: 100%;
    min-height: 54px;
    padding: 12px;
    font-size: var(--choice-button-size);
  }

  .card-nav-btn {
    display: none !important;
  }

  .bottom-controls {
    position: fixed;
    inset: auto 0 0 0;
    z-index: 85;
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr) minmax(0, .95fr) minmax(0, 1.25fr) 44px;
    gap: 5px;
    margin: 0;
    padding: 8px 7px calc(8px + env(safe-area-inset-bottom));
    background: linear-gradient(180deg, rgba(18,17,32,.94), #121120);
    border-top: 1px solid rgba(255,255,255,.10);
    box-shadow: 0 -6px 24px rgba(0,0,0,.34);
  }

  .bottom-controls .btn {
    width: 100%;
    min-width: 0;
    min-height: 48px;
    padding: 7px 4px;
    border-radius: 10px;
    font-size: var(--bottom-button-size);
    line-height: 1.08;
    white-space: normal;
  }

  .bottom-controls .nav-btn {
    min-width: 0 !important;
    font-size: 22px;
  }

  .settings-panel {
    width: min(92vw, 400px);
    padding: calc(70px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom));
    z-index: 115;
  }

  .settings-header {
    position: sticky;
    top: -1px;
    z-index: 3;
    margin: -12px -4px 14px;
    padding: 12px 4px;
    background: #12171b;
  }

  .settings-header h2 {
    font-size: 22px;
  }

  .settings-actions {
    display: grid;
    grid-template-columns: 1fr;
  }
}

@media (max-width: 430px) {
  .mobile-title {
    font-size: 19px;
  }

  .bottom-controls {
    grid-template-columns: 42px minmax(0, 1fr) minmax(0, .88fr) minmax(0, 1.18fr) 42px;
  }

  .bottom-controls .btn {
    font-size: 12px;
  }

  .audio-btn {
    padding-inline: 7px;
  }
}

@media (max-width: 360px) {
  .bottom-controls {
    grid-template-columns: 40px minmax(0, 1fr) minmax(0, .82fr) minmax(0, 1.05fr) 40px;
    gap: 4px;
    padding-inline: 5px;
  }

  .bottom-controls .btn {
    font-size: 11px;
  }
}
