:root {
  color-scheme: dark;
  --bg: #0f1115;
  --surface: #1a1d23;
  --surface-2: #222633;
  --text: #f2f2f2;
  --muted: #9aa0a6;
  --accent: #4cc2d6;
  --danger: #ff6b6b;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --radius: 16px;
  --space-1: 8px;
  --space-2: 12px;
  --space-3: 16px;
  --space-4: 20px;
  --space-5: 24px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Google Sans", "Noto Sans Thai Looped", sans-serif;
  font-optical-sizing: auto;
  font-weight: 400;
  font-style: normal;
  font-variation-settings: "GRAD" 0;
  background: radial-gradient(circle at top, #171b22 0%, #0f1115 55%, #0a0c10 100%);
  color: var(--text);
  min-height: 100vh;
}

.material-symbols-outlined {
  font-family: "Material Symbols Outlined";
  font-weight: normal;
  font-style: normal;
  font-size: 24px;
  line-height: 1;
  letter-spacing: normal;
  text-transform: none;
  display: inline-block;
  white-space: nowrap;
  word-wrap: normal;
  direction: ltr;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
  margin: 0 0 12px 0;
  font-weight: 600;
}

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

.screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

#main-screen {
  display: block;
  padding: 0 0 24px;
}

.hidden {
  display: none !important;
}

.login-card {
  width: min(420px, 100%);
  background: var(--surface);
  padding: 32px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.login-card h1 {
  font-size: 2rem;
}

.subtitle {
  margin-bottom: 24px;
}

label {
  display: block;
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 16px;
}

input[type="text"],
input[type="password"],
input[type="search"] {
  width: 100%;
  padding: 12px 14px;
  margin-top: 8px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: var(--surface-2);
  color: var(--text);
  font-size: 1rem;
}

input:focus {
  outline: 2px solid rgba(76, 194, 214, 0.4);
}

button {
  border: none;
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 0.95rem;
  cursor: pointer;
  min-height: 44px;
}

button.primary {
  width: 100%;
  background: var(--accent);
  color: #0b0e12;
  font-weight: 600;
}

button.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--surface-2);
}

button.icon-button {
  background: var(--surface-2);
  color: var(--text);
  padding: 10px 14px;
  min-height: 40px;
}

.error {
  color: var(--danger);
  margin-top: 12px;
  font-size: 0.9rem;
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: rgba(15, 17, 21, 0.85);
  position: sticky;
  top: 0;
  backdrop-filter: blur(10px);
  z-index: 10;
}

.top-bar,
.toolbar,
main#content {
  width: min(920px, 100%);
  margin: 0 auto;
}

.title {
  font-weight: 600;
  letter-spacing: 0.5px;
}

.top-bar-actions {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.top-left-actions {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.btn-icon {
  font-size: 1.05rem;
  line-height: 1;
  display: none;
}

.toolbar {
  padding: var(--space-2) var(--space-4) 0;
  display: block;
}

.toolbar-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
}

.search-wrap input {
  width: 100%;
}

#shuffle-button {
  min-width: 40px;
  min-height: 40px;
  width: 40px;
  height: 40px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

#shuffle-button .material-symbols-outlined {
  font-size: 20px;
}

#shuffle-button.active {
  background: rgba(76, 194, 214, 0.2);
  border: 1px solid rgba(76, 194, 214, 0.45);
}

main#content {
  padding: var(--space-3) var(--space-4) 90px;
}

.list {
  display: grid;
  gap: var(--space-2);
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: var(--space-3);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}

.card.button {
  cursor: pointer;
}

.hanzi {
  font-size: 2rem;
  font-weight: 600;
  margin-bottom: 8px;
  font-family: "Noto Sans SC", sans-serif;
  font-optical-sizing: auto;
  font-style: normal;
}

.pinyin {
  font-size: 1rem;
  color: var(--muted);
  margin-bottom: 6px;
}

.review-count {
  font-size: 0.85rem;
  color: var(--muted);
}

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

.card-head-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.list-inline-row {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: center;
  column-gap: 12px;
  row-gap: 8px;
}

.list-inline-row .hanzi {
  margin-bottom: 0;
  flex: 0 0 auto;
  grid-column: 1;
}

.list-inline-row .pinyin {
  margin-bottom: 0;
  grid-column: 2;
  min-width: 0;
  font-size: 1.08rem;
}

.speaker-btn {
  grid-column: 3;
  justify-self: end;
  min-width: 36px;
  min-height: 36px;
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 999px;
  border: 1px solid var(--surface-2);
  background: rgba(34, 42, 61, 0.75);
  color: var(--text);
  font-size: 0.9rem;
  line-height: 1;
}

.speaker-btn .material-symbols-outlined {
  font-size: 20px;
  line-height: 1;
  font-variation-settings: "FILL" 0, "wght" 500, "GRAD" 0, "opsz" 24;
}

.speaker-btn:hover {
  background: #2a3040;
}

.list-card-tags {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.list-tag {
  min-height: auto;
  font-size: 0.85rem;
  padding: 6px 10px;
  border-radius: 999px;
}

.row-meta .pinyin {
  margin-bottom: 0;
}

.review-pill {
  font-size: 0.9rem;
  color: var(--muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.quick-review-actions {
  grid-column: 4;
  justify-self: end;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.quick-review-btn {
  min-width: 40px;
  min-height: 36px;
  padding: 6px 10px;
  line-height: 1;
  border: 1px solid transparent;
  border-radius: 10px;
  color: #0b0e12;
  font-weight: 700;
}

.quick-review-actions .review-pill {
  min-width: 24px;
  text-align: center;
}

.review-up {
  background: #79e3a3;
}

.review-down {
  background: #ff9f9f;
}

.filter-header-card {
  margin-bottom: 18px;
}

.filter-criteria-card {
  background: linear-gradient(140deg, rgba(41, 66, 104, 0.34), rgba(31, 37, 57, 0.78));
  border: 1px solid rgba(100, 175, 255, 0.25);
}

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

.criteria-kind {
  color: #9fc4ff;
  margin-bottom: 10px;
}

.criteria-value {
  color: #dfeaff;
}

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

.criteria-edit-btn {
  white-space: nowrap;
}

.criteria-value-auto-pinyin {
  font-family: "Google Sans", "Noto Sans Thai Looped", sans-serif;
  font-optical-sizing: auto;
  font-style: normal;
  font-variation-settings: "GRAD" 0;
}

.pagination {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 8px;
}

.pagination .ghost {
  min-width: 44px;
  min-height: 40px;
  padding: 8px 12px;
}

.pagination .ghost:disabled {
  opacity: 0.55;
  cursor: default;
}

.pagination .active-page {
  background: var(--accent);
  color: #0b0e12;
  border-color: transparent;
}

.detail {
  display: grid;
  gap: calc(var(--space-2) + 6px);
}

.detail .card {
  padding: var(--space-4) calc(var(--space-4) + 2px);
}

.detail h3 {
  margin-bottom: 14px;
}

.detail .hanzi {
  margin-bottom: 10px;
}

.detail .row-meta {
  align-items: center;
}

.detail .review-pill {
  font-size: 1rem;
}

#stroke-order-content {
  display: grid;
  gap: 12px;
}

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

.stroke-header-row h3 {
  margin-bottom: 0;
}

.stroke-char-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.stroke-stage {
  display: grid;
  gap: 10px;
}

.stroke-canvas {
  width: min(320px, 100%);
  aspect-ratio: 1 / 1;
  border: 1px solid var(--surface-2);
  border-radius: 12px;
  background: rgba(20, 27, 39, 0.75);
  display: grid;
  place-items: center;
}

.stroke-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.stroke-icon-btn {
  min-height: auto;
  padding: 6px 10px;
  font-size: 0.85rem;
  border-radius: 999px;
  line-height: 1.2;
}

.stroke-icon-btn .material-symbols-outlined {
  font-size: 18px;
  line-height: 1;
  font-variation-settings: "FILL" 0, "wght" 500, "GRAD" 0, "opsz" 24;
}

.stroke-empty {
  color: var(--muted);
  font-size: 0.9rem;
}

@media (max-width: 860px) {
  .list-inline-row {
    column-gap: 8px;
  }

  .quick-review-actions {
    gap: 4px;
  }

  .speaker-btn {
    min-width: 34px;
    min-height: 34px;
    width: 34px;
    height: 34px;
  }
}

@media (max-width: 560px) {
  .list-inline-row {
    grid-template-columns: auto 1fr auto auto;
  }

  .list-inline-row .pinyin {
    grid-column: 1 / 3;
    grid-row: 2;
  }
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
}

.auto-tag-section {
  margin-top: 20px;
}

.auto-tag-section:first-child {
  margin-top: 0;
}

.auto-tag-section h3 {
  margin-bottom: 14px;
}

.tag {
  padding: 6px 10px;
  background: var(--surface-2);
  border-radius: 999px;
  font-size: 0.85rem;
  cursor: pointer;
  display: inline-flex;
  gap: 6px;
  align-items: center;
}

.tag-add {
  background: var(--surface-2);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: var(--text);
  min-height: auto;
  padding: 6px 10px;
  font-size: 0.85rem;
}

.tag-add:hover {
  background: #2a3040;
}

.tag-separator {
  color: var(--muted);
  font-size: 0.95rem;
  padding: 0 2px;
  align-self: center;
}

.tag button {
  background: transparent;
  color: var(--muted);
  border: none;
  padding: 0;
  min-height: auto;
}

.fixed-action {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  padding: var(--space-3) var(--space-4) var(--space-5);
  background: linear-gradient(180deg, rgba(15, 17, 21, 0.2) 0%, rgba(15, 17, 21, 0.9) 60%);
}

.fixed-action-inner {
  width: min(920px, 100%);
  padding: 0 var(--space-4);
}

.fixed-action button {
  width: 100%;
  background: var(--accent);
  color: #0b0e12;
  font-weight: 600;
}

.fixed-action-dual {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.fixed-action-dual .ghost {
  color: var(--text);
  border-color: rgba(255, 255, 255, 0.25);
}

.fixed-action-dual .review-up,
.fixed-action-dual .review-down {
  width: 100%;
  font-weight: 700;
  color: #0b0e12;
}

.fixed-action-dual .review-up {
  background: #79e3a3;
}

.fixed-action-dual .review-down {
  background: #ff9f9f;
}

.definition-text {
  white-space: pre-line;
  line-height: 1.58;
}

.panel {
  position: fixed;
  inset: 0;
  background: rgba(5, 6, 9, 0.6);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 20;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

#filter-panel .panel-sheet {
  background: var(--surface);
  border-top-left-radius: 24px;
  border-top-right-radius: 24px;
  padding: 24px;
  width: min(600px, 100%);
  max-height: 80vh;
  overflow-y: auto;
}

.panel-section {
  margin-bottom: 24px;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}

.tag.active {
  background: var(--accent);
  color: #0b0e12;
}

.menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 180px;
  background: var(--surface);
  border: 1px solid var(--surface-2);
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
  z-index: 25;
}

.menu-item {
  width: 100%;
  display: block;
  text-align: left;
  background: transparent;
  color: var(--text);
  border: 0;
  border-bottom: 1px solid var(--surface-2);
  border-radius: 0;
  padding: 12px 14px;
  font-size: 0.95rem;
  cursor: pointer;
  margin: 0;
  min-height: 0;
  line-height: 1.25;
}

.menu-item:last-child {
  border-bottom: 0;
}

.menu-group-label {
  color: var(--text);
  border-bottom: 1px solid var(--surface-2);
  padding: 10px 14px 8px;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  opacity: 0.75;
}

.menu-subitem {
  padding-left: 22px;
  font-size: 0.9rem;
}

.menu-item:hover {
  background: var(--surface-2);
}

.danger-item {
  color: var(--text);
}

.import-item input {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(5, 6, 9, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 30;
  padding: 20px;
}

.modal-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  width: min(600px, 100%);
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}

.app-dialog-card {
  width: min(560px, 100%);
}

.dialog-body {
  color: var(--text);
  line-height: 1.45;
  white-space: pre-line;
}

#app-dialog-input {
  margin-top: 16px;
}

.dialog-actions {
  margin-top: 18px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.progress-track {
  margin-top: 14px;
  width: 100%;
  height: 12px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}

.progress-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #2f9bff, var(--accent));
  transition: width 120ms linear;
}

#app-dialog-confirm.danger {
  background: linear-gradient(135deg, #f05656, #d63b3b);
  color: #fff;
  font-weight: 700;
  box-shadow: 0 6px 20px rgba(214, 59, 59, 0.35);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.tag-manager-list {
  display: grid;
  gap: 12px;
}

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

.stats-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border-radius: 12px;
}

.stats-row-header {
  color: var(--muted);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 0;
  padding-left: 4px;
  padding-right: 4px;
}

.stats-row-item {
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: var(--surface-2);
  color: var(--text);
  text-align: left;
}

.stats-row-item:hover {
  border-color: rgba(76, 194, 214, 0.5);
}

.stats-empty {
  color: var(--muted);
  padding: 10px 4px 4px;
}

.tag-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface-2);
  padding: 12px;
  border-radius: 12px;
}

.tag-actions {
  display: flex;
  gap: 8px;
}

.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 90px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
  color: var(--text);
  padding: 12px 16px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  z-index: 40;
  text-align: center;
  min-width: 220px;
  max-width: min(92vw, 460px);
  white-space: nowrap;
}

@media (max-width: 900px) {
  .top-bar {
    gap: 8px;
  }

  .title {
    font-size: 1rem;
    letter-spacing: 0.2px;
    text-align: center;
  }

  .top-bar-actions {
    gap: 6px;
  }

  .top-left-actions {
    gap: 6px;
  }

  button.icon-button {
    min-width: 40px;
    min-height: 40px;
    padding: 9px 10px;
  }

  .nav-btn .btn-label {
    display: none;
  }

  .btn-icon {
    display: inline-block;
  }

  .nav-btn {
    justify-content: center;
  }
}
