:root {
  --sky-50: #f4fbff;
  --sky-100: #e3f6ff;
  --sky-200: #c5ecff;
  --sky-300: #91d9ff;
  --sky-500: #35a7ff;
  --sky-700: #1269ac;
  --mint: #58c9a9;
  --mint-soft: #dff8ef;
  --sun: #ffd166;
  --sun-soft: #fff4cf;
  --coral: #ff7f7a;
  --coral-soft: #ffe5e2;
  --violet: #8e7cf6;
  --ink: #203040;
  --muted: #697a8c;
  --line: #d9e9f4;
  --card: #ffffff;
  --soft-shadow: 0 14px 35px rgba(36, 103, 143, 0.14);
  --small-shadow: 0 8px 20px rgba(36, 103, 143, 0.1);
  font-family:
    "Inter", "PingFang SC", "Microsoft YaHei", system-ui, -apple-system,
    BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  min-height: 100%;
  overflow-x: hidden;
  background: var(--sky-50);
  -webkit-text-size-adjust: 100%;
  touch-action: pan-y;
}

body {
  min-height: 100%;
  margin: 0;
  overflow-x: hidden;
  overscroll-behavior-x: none;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(227, 246, 255, 0.95), rgba(244, 251, 255, 1) 420px),
    repeating-linear-gradient(
      135deg,
      rgba(53, 167, 255, 0.04) 0,
      rgba(53, 167, 255, 0.04) 12px,
      transparent 12px,
      transparent 28px
    );
}

button,
input,
select,
textarea {
  font: inherit;
  touch-action: manipulation;
}

button {
  border: 0;
}

.app-shell {
  width: min(1180px, 100%);
  min-height: 100vh;
  min-height: var(--app-height, 100dvh);
  margin: 0 auto;
  overflow-x: clip;
  padding: 18px 18px 96px;
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
}

.app-shell.is-studying {
  width: min(760px, 100%);
  padding: 12px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0 18px;
}

.brand {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 10px;
}

.brand-mark {
  width: 52px;
  height: 52px;
  flex: 0 0 auto;
  filter: drop-shadow(0 8px 14px rgba(18, 105, 172, 0.18));
}

.brand-title {
  margin: 0;
  font-size: 1.35rem;
  line-height: 1.15;
}

.brand-subtitle {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.profile-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.74);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: var(--small-shadow);
}

.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.avatar {
  width: 34px;
  height: 34px;
  object-fit: cover;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--sun-soft);
}

.page-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 18px;
}

.section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin: 4px 0 12px;
}

.section-head h2,
.section-head h3 {
  margin: 0;
}

.section-head p {
  margin: 4px 0 0;
  color: var(--muted);
}

.dashboard {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.metric-card,
.pack-card,
.resource-card,
.card-row,
.admin-panel,
.profile-panel,
.empty-state,
.modal-panel {
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--small-shadow);
}

.metric-card {
  min-height: 82px;
  padding: 10px 12px;
  overflow: hidden;
}

.metric-label {
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.2;
}

.metric-value {
  margin-top: 4px;
  font-size: 1.42rem;
  font-weight: 800;
  line-height: 1.05;
  color: var(--sky-700);
}

.metric-note {
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.25;
}

.pack-grid,
.resource-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.pack-card,
.resource-card {
  display: grid;
  grid-template-columns: 124px minmax(0, 1fr);
  gap: 14px;
  min-height: 166px;
  padding: 12px;
}

.resource-card.locked {
  color: #778899;
  background: rgba(255, 255, 255, 0.62);
  filter: saturate(0.42);
}

.resource-card.completed {
  background: rgba(255, 255, 255, 0.82);
  border-style: dashed;
}

.pack-cover {
  width: 100%;
  height: 142px;
  object-fit: cover;
  border-radius: 8px;
  background: var(--sky-100);
  border: 1px solid rgba(255, 255, 255, 0.76);
}

.pack-content {
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 12px;
}

.pack-title {
  margin: 0 0 5px;
  font-size: 1.05rem;
}

.pack-desc {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
  font-size: 0.9rem;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 9px;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  color: var(--sky-700);
  background: var(--sky-100);
  border: 1px solid var(--sky-200);
  border-radius: 999px;
  font-size: 0.78rem;
  white-space: nowrap;
}

.tag.sun {
  color: #8d6400;
  background: var(--sun-soft);
  border-color: #ffe49a;
}

.tag.mint {
  color: #1d755e;
  background: var(--mint-soft);
  border-color: #b6ead9;
}

.tag.coral {
  color: #9c3834;
  background: var(--coral-soft);
  border-color: #ffc4c0;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  gap: 7px;
  padding: 8px 12px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(18, 105, 172, 0.07);
  transition:
    transform 0.12s ease,
    box-shadow 0.12s ease,
    border-color 0.12s ease,
    background 0.12s ease;
}

.btn:hover {
  transform: translateY(-1px);
  border-color: var(--sky-300);
  box-shadow: 0 6px 12px rgba(18, 105, 172, 0.12);
}

.btn:active {
  transform: translateY(0);
  box-shadow: 0 2px 0 rgba(18, 105, 172, 0.09);
}

.btn.primary {
  color: #fff;
  background: var(--sky-500);
  border-color: var(--sky-500);
}

.btn.mint {
  color: #064b39;
  background: #a8efd9;
  border-color: #8bddc7;
}

.btn.sun {
  color: #5d4100;
  background: var(--sun);
  border-color: #f3bd3e;
}

.btn.coral {
  color: #fff;
  background: var(--coral);
  border-color: var(--coral);
}

.btn.danger {
  color: #9b1c1c;
  background: #fff5f5;
  border-color: #fecaca;
}

.btn.ghost {
  background: rgba(255, 255, 255, 0.66);
}

.btn.icon-only {
  width: 40px;
  padding: 0;
}

.btn[disabled] {
  cursor: not-allowed;
  opacity: 0.55;
  transform: none;
}

.icon {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.tabbar {
  position: fixed;
  left: 50%;
  bottom: 14px;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  width: min(760px, calc(100% - 24px));
  padding: 8px;
  transform: translateX(-50%);
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--soft-shadow);
  backdrop-filter: blur(14px);
}

.tab-btn {
  min-height: 48px;
  padding: 4px;
  color: var(--muted);
  background: transparent;
  border-radius: 10px;
  cursor: pointer;
}

.tab-btn.active {
  color: var(--sky-700);
  background: var(--sky-100);
}

.tab-btn .icon {
  display: block;
  margin: 0 auto 2px;
}

.tab-label {
  display: block;
  font-size: 0.76rem;
}

.study-stage {
  min-height: calc(var(--app-height, 100dvh) - 160px);
  display: grid;
  place-items: center;
}

.app-shell.is-studying .page-grid,
.app-shell.is-studying .study-stage {
  min-height: calc(var(--app-height, 100dvh) - 24px - env(safe-area-inset-bottom));
}

.study-wrap {
  width: min(560px, 100%);
  min-width: 0;
}

.study-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.study-progress {
  flex: 1;
  height: 10px;
  overflow: hidden;
  background: #d8ecf7;
  border: 0;
  border-radius: 999px;
}

.study-progress::-webkit-progress-bar {
  background: #d8ecf7;
  border-radius: 999px;
}

.study-progress::-webkit-progress-value {
  background: linear-gradient(90deg, var(--mint), var(--sky-500));
  border-radius: 999px;
}

.study-progress::-moz-progress-bar {
  background: linear-gradient(90deg, var(--mint), var(--sky-500));
  border-radius: 999px;
}

.study-bottom-actions {
  justify-content: center;
  margin-top: 10px;
}

.study-card {
  display: flex;
  flex-direction: column;
  min-height: min(650px, calc(var(--app-height, 100dvh) - 86px - env(safe-area-inset-bottom)));
  padding: 10px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--soft-shadow);
}

.study-image-frame {
  display: grid;
  place-items: center;
  width: 100%;
  min-height: clamp(240px, 48dvh, 360px);
  flex: 0 0 auto;
  background: #f8fcff;
  border: 1px solid #eaf4fb;
  border-radius: 7px;
  overflow: hidden;
}

.study-image {
  display: block;
  width: auto;
  height: auto;
  max-width: calc(100% - 12px);
  max-height: calc(100% - 12px);
  object-fit: contain;
}

.study-answer {
  min-height: clamp(96px, 17dvh, 126px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 10px;
  padding: 16px 8px;
  text-align: center;
}

.word-answer {
  margin: 0;
  font-size: 2rem;
  font-weight: 850;
  color: var(--sky-700);
  line-height: 1.16;
  white-space: pre-line;
}

.sentence-answer {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.rating-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  padding: 0 0 2px;
}

.rating-btn {
  display: flex;
  min-height: clamp(54px, 8dvh, 62px);
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 7px 6px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}

.rating-btn strong {
  font-size: 0.92rem;
}

.rating-btn span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.73rem;
}

.rating-btn.again {
  background: var(--coral-soft);
  border-color: #ffc5c1;
}

.rating-btn.hard {
  background: var(--sun-soft);
  border-color: #ffdf8d;
}

.rating-btn.good {
  background: var(--sky-100);
  border-color: var(--sky-200);
}

.rating-btn.easy {
  background: var(--mint-soft);
  border-color: #b6ead9;
}

.library-tools,
.admin-tools {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(180px, 0.7fr) auto;
  gap: 10px;
  margin-bottom: 14px;
}

.field,
.select,
.textarea {
  width: 100%;
  min-height: 40px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
  padding: 9px 11px;
}

.field:focus,
.select:focus,
.textarea:focus {
  border-color: var(--sky-500);
  box-shadow: 0 0 0 3px rgba(53, 167, 255, 0.14);
}

.textarea {
  min-height: 108px;
  resize: vertical;
}

.word-field {
  min-height: 74px;
  line-height: 1.45;
}

.card-list {
  display: grid;
  gap: 10px;
}

.card-row {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr);
  gap: 12px;
  padding: 10px;
}

.card-thumb {
  width: 96px;
  height: 118px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--sky-100);
}

.card-row h3 {
  margin: 0 0 4px;
  font-size: 1rem;
  white-space: pre-line;
}

.card-row p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
  font-size: 0.88rem;
}

.card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0 10px;
}

.empty-state {
  padding: 26px;
  text-align: center;
}

.empty-state h3 {
  margin: 0 0 6px;
}

.empty-state p {
  margin: 0;
  color: var(--muted);
}

.admin-grid,
.profile-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px;
}

.admin-panel,
.profile-panel {
  padding: 14px;
}

.admin-panel h3,
.profile-panel h3 {
  margin: 0 0 12px;
}

.cloud-admin-panel {
  margin-bottom: 14px;
}

.cloud-admin-head {
  margin-top: 0;
}

.user-table {
  display: grid;
  gap: 8px;
}

.user-row {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) repeat(4, auto);
  align-items: center;
  gap: 8px;
  padding: 9px;
  background: var(--sky-50);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.profile-actions {
  margin-top: 14px;
}

.restore-progress-control {
  position: relative;
  overflow: hidden;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.form-grid .full {
  grid-column: 1 / -1;
}

.file-note {
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.45;
}

.admin-code-list {
  display: grid;
  gap: 8px;
}

.code-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px;
  background: var(--sky-50);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.code-row.book-locked {
  color: var(--muted);
  background: #eef6fb;
  border-style: dashed;
}

.clickable-row,
.resource-card.locked {
  cursor: pointer;
}

.code-text {
  font-weight: 800;
  color: var(--sky-700);
}

.pack-card-editor {
  display: grid;
  gap: 10px;
  padding: 12px;
  background: #f8fbfe;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.pack-card-editor-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.pack-card-list {
  display: grid;
  gap: 8px;
  max-height: 360px;
  overflow: auto;
}

.pack-card-row {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 8px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.pack-card-row strong {
  white-space: pre-line;
}

.pack-card-thumb {
  width: 52px;
  height: 52px;
  object-fit: cover;
  border-radius: 7px;
  background: var(--sky-50);
}

.pack-card-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(20, 38, 56, 0.38);
  backdrop-filter: blur(6px);
}

.modal-panel {
  width: min(520px, 100%);
  max-height: calc(var(--app-height, 100dvh) - 36px);
  overflow: auto;
  padding: 18px;
}

.pack-manage-panel {
  width: min(1120px, 100%);
  padding: 22px;
}

.card-edit-panel {
  width: min(720px, 100%);
}

.pack-manage-panel .pack-card-editor {
  padding: 14px;
}

.pack-manage-panel .pack-card-list {
  grid-template-columns: repeat(auto-fill, minmax(172px, 1fr));
  align-items: stretch;
  max-height: clamp(420px, 58dvh, 640px);
}

.pack-manage-panel .pack-card-row {
  display: flex;
  height: 248px;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  overflow: hidden;
  padding: 10px;
  box-shadow: 0 4px 12px rgba(36, 103, 143, 0.06);
}

.pack-manage-panel .pack-card-thumb {
  width: 100%;
  height: 102px;
  flex: 0 0 auto;
  border: 1px solid var(--line);
}

.pack-manage-panel .pack-card-row > div:not(.pack-card-actions) {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.pack-manage-panel .pack-card-row strong {
  display: -webkit-box;
  min-height: auto;
  max-height: 2.3em;
  overflow: hidden;
  font-size: 0.95rem;
  line-height: 1.15;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.pack-manage-panel .pack-card-row .file-note {
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 0.76rem;
  line-height: 1.28;
  white-space: nowrap;
}

.pack-manage-panel .pack-card-row .file-note + .file-note {
  display: -webkit-box;
  white-space: normal;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 1;
}

.pack-manage-panel .pack-card-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 0.72fr);
  gap: 6px;
  margin-top: auto;
}

.pack-manage-panel .pack-card-actions .btn {
  min-height: 32px;
  padding: 5px 6px;
  justify-content: center;
  min-width: 0;
  font-size: 0.84rem;
  white-space: nowrap;
}

.pack-manage-panel .modal-actions {
  position: sticky;
  bottom: -22px;
  z-index: 2;
  padding-top: 14px;
  padding-bottom: 4px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0), #fff 28%);
}

.modal-panel h2 {
  margin: 0 0 8px;
}

.modal-panel p {
  color: var(--muted);
  line-height: 1.5;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.qr-box {
  width: 210px;
  height: 210px;
  margin: 14px auto;
  padding: 14px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--small-shadow);
}

.qr-image,
.qr-preview {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 7px;
}

.qr-preview {
  max-width: 180px;
  height: 180px;
  margin: 0 auto;
  border: 1px solid var(--line);
}

.qr-art {
  width: 100%;
  height: 100%;
  background:
    linear-gradient(90deg, #203040 10px, transparent 10px) 0 0 / 24px 24px,
    linear-gradient(#203040 10px, transparent 10px) 0 0 / 24px 24px,
    linear-gradient(90deg, transparent 6px, #203040 6px 12px, transparent 12px) 6px
      6px / 30px 30px,
    #fff;
  border: 9px solid #203040;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 92px;
  z-index: 80;
  max-width: calc(100% - 36px);
  padding: 11px 14px;
  color: #fff;
  background: #203040;
  border-radius: 8px;
  box-shadow: var(--soft-shadow);
  transform: translateX(-50%);
}

.hidden {
  display: none !important;
}

.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;
}

@media (max-width: 820px) {
  .app-shell {
    padding: 14px 12px 92px;
    padding-bottom: calc(92px + env(safe-area-inset-bottom));
  }

  .topbar {
    align-items: flex-start;
  }

  .brand-title {
    font-size: 1.12rem;
  }

  .brand-subtitle {
    display: none;
  }

  .dashboard {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
  }

  .metric-card {
    min-height: 74px;
    padding: 8px;
  }

  .metric-value {
    font-size: 1.18rem;
  }

  .metric-label {
    font-size: 0.74rem;
  }

  .metric-note {
    font-size: 0.66rem;
  }

  .pack-grid,
  .resource-grid,
  .admin-grid,
  .profile-grid {
    grid-template-columns: 1fr;
  }

  .pack-card,
  .resource-card {
    grid-template-columns: 104px minmax(0, 1fr);
    gap: 10px;
  }

  .pack-cover {
    height: 128px;
  }

  .library-tools,
  .admin-tools {
    grid-template-columns: 1fr;
  }

  .user-row {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .pack-manage-panel,
  .card-edit-panel {
    width: 100%;
    padding: 16px;
  }

  .pack-manage-panel .pack-card-list {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    max-height: clamp(320px, 52dvh, 520px);
  }

  .pack-manage-panel .pack-card-row {
    height: 232px;
  }

  .pack-manage-panel .pack-card-thumb {
    height: 88px;
  }

  .pack-manage-panel .pack-card-actions {
    grid-template-columns: 1fr 0.72fr;
  }

  .pack-manage-panel .pack-card-actions .btn {
    flex: initial;
  }

  .tabbar {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 0;
    border-radius: 14px;
  }

  .tab-label {
    font-size: 0.68rem;
  }

  .study-card {
    min-height: min(590px, calc(var(--app-height, 100dvh) - 78px - env(safe-area-inset-bottom)));
  }

  .study-image-frame {
    min-height: clamp(220px, 48dvh, 310px);
  }

  .rating-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 520px) {
  .app-shell.is-studying {
    padding: 8px 10px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
  }

  .app-shell.is-studying .page-grid,
  .app-shell.is-studying .study-stage {
    min-height: auto;
  }

  .study-top {
    gap: 8px;
    margin-bottom: 8px;
  }

  .study-top .btn.icon-only {
    width: 38px;
    min-height: 38px;
  }

  .profile-pill span {
    display: none;
  }

  .dashboard {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .pack-card,
  .resource-card,
  .card-row {
    grid-template-columns: 88px minmax(0, 1fr);
  }

  .pack-cover,
  .card-thumb {
    width: 88px;
    height: 112px;
  }

  .pack-card-row {
    grid-template-columns: 44px minmax(0, 1fr);
  }

  .pack-card-actions {
    grid-column: 1 / -1;
    width: 100%;
  }

  .pack-card-actions .btn {
    flex: 1 1 120px;
  }

  .pack-manage-panel .pack-card-list {
    grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  }

  .pack-card-thumb {
    width: 44px;
    height: 44px;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .study-card {
    min-height: 0;
    padding: 8px;
  }

  .study-image-frame {
    height: clamp(260px, 48dvh, 420px);
    min-height: 0;
  }

  .study-answer {
    min-height: 92px;
    padding: 12px 6px;
  }

  .study-bottom-actions {
    margin-top: 4px;
  }

  .word-answer {
    font-size: 1.7rem;
  }
}

@media (orientation: portrait) and (min-width: 521px) and (max-width: 900px) {
  .app-shell {
    width: min(720px, 100%);
    padding-inline: 14px;
  }

  .dashboard {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .pack-grid,
  .resource-grid,
  .profile-grid,
  .admin-grid {
    grid-template-columns: 1fr;
  }

  .app-shell.is-studying {
    width: min(620px, 100%);
  }

  .app-shell.is-studying .study-stage {
    align-items: start;
  }

  .study-wrap {
    width: 100%;
  }

  .study-card {
    min-height: 0;
  }

  .study-image-frame {
    height: clamp(360px, 52dvh, 560px);
    min-height: 0;
  }

  .study-image {
    max-width: calc(100% - 12px);
    max-height: calc(100% - 12px);
  }
}

@media (orientation: landscape) and (max-height: 620px) {
  .app-shell.is-studying {
    width: min(980px, 100%);
    padding: 8px 10px;
  }

  .app-shell.is-studying .study-stage {
    min-height: calc(var(--app-height, 100dvh) - 16px);
  }

  .study-wrap {
    width: min(920px, 100%);
  }

  .study-card {
    display: grid;
    grid-template-columns: minmax(0, 1.05fr) minmax(260px, 0.95fr);
    grid-template-rows: auto auto 1fr;
    gap: 10px;
    min-height: calc(var(--app-height, 100dvh) - 70px);
  }

  .study-image-frame {
    grid-row: 1 / 4;
    min-height: 0;
    height: calc(var(--app-height, 100dvh) - 92px);
  }

  .study-image {
    max-height: calc(var(--app-height, 100dvh) - 112px);
  }

  .study-answer {
    min-height: 0;
    padding: 10px 6px;
  }

  .rating-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
