:root {
  --bg: #0f172a;
  --panel-bg: rgba(15, 23, 42, 0.92);
  --accent: #38bdf8;
  --accent-strong: #0ea5e9;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --error: #f87171;
  --warning: #fbbf24;
  --success: #4ade80;
  --card-radius: 18px;
  font-family: 'Noto Sans TC', system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: radial-gradient(circle at top, rgba(56, 189, 248, 0.15), transparent 55%),
              radial-gradient(circle at bottom, rgba(14, 165, 233, 0.12), transparent 70%),
              var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.app {
  width: min(1100px, 95vw);
  margin: 40px auto 80px;
}

.app__header {
  text-align: center;
  margin-bottom: 32px;
}

.app__header h1 {
  margin: 0 0 12px;
  font-size: clamp(2rem, 4vw, 2.6rem);
  letter-spacing: 0.04em;
}

.app__header p {
  margin: 0;
  color: var(--muted);
  font-size: 1rem;
}

.panel {
  background: var(--panel-bg);
  border: 1px solid rgba(148, 163, 184, 0.15);
  border-radius: var(--card-radius);
  padding: 24px;
  margin-bottom: 24px;
  box-shadow: 0 25px 50px -20px rgba(56, 189, 248, 0.25);
  backdrop-filter: blur(12px);
}

.panel h2 {
  margin-top: 0;
  font-size: 1.4rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.field {
  display: flex;
  flex-direction: column;
  margin-bottom: 16px;
}

.field label {
  font-weight: 600;
  margin-bottom: 6px;
}

.field--user {
  gap: 10px;
}

.user-id-control {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-id-control input {
  flex: 1;
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.4);
  background: rgba(15, 23, 42, 0.6);
  color: var(--text);
  padding: 12px 16px;
  font-size: 1rem;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.user-id-control input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.25);
}

select,
textarea {
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.4);
  background: rgba(15, 23, 42, 0.6);
  color: var(--text);
  padding: 12px 16px;
  font-size: 1rem;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.25);
}

textarea {
  resize: vertical;
  min-height: 110px;
}

.field--file input[type="file"] {
  border-radius: 12px;
  border: 1px dashed rgba(148, 163, 184, 0.4);
  background: rgba(15, 23, 42, 0.35);
  color: var(--text);
  padding: 12px 16px;
  font-size: 1rem;
  cursor: pointer;
}

.field--file input[type="file"]::file-selector-button,
.field--file input[type="file"]::-webkit-file-upload-button {
  border: none;
  border-radius: 999px;
  background: rgba(56, 189, 248, 0.2);
  color: var(--accent);
  padding: 8px 14px;
  margin-right: 14px;
  font-weight: 600;
  cursor: pointer;
}

.hint--compact {
  margin-top: 8px;
  font-size: 0.85rem;
}

.actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.btn {
  border: none;
  border-radius: 999px;
  padding: 12px 24px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  background: rgba(148, 163, 184, 0.25);
  color: var(--text);
  transition: transform 0.15s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 16px 30px -18px rgba(56, 189, 248, 0.8);
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.btn--primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #0f172a;
}

.btn--secondary {
  background: rgba(56, 189, 248, 0.2);
  color: var(--accent);
}

.btn--danger {
  background: rgba(248, 113, 113, 0.18);
  color: var(--error);
}

.btn--danger:hover:not(:disabled) {
  background: rgba(248, 113, 113, 0.25);
  color: #fff;
}

.btn--small {
  padding: 8px 16px;
  font-size: 0.9rem;
}

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

.hint[data-state="error"] {
  color: var(--error);
}

.hint[data-state="success"] {
  color: var(--success);
}

.scoreboard {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin: 16px 0 24px;
}

.score {
  padding: 16px;
  border-radius: 14px;
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid rgba(56, 189, 248, 0.12);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.score__label {
  color: var(--muted);
  letter-spacing: 0.05em;
  font-size: 0.9rem;
}

.score__value {
  font-size: 2rem;
  font-weight: 700;
}

.chart-wrapper {
  background: rgba(15, 23, 42, 0.7);
  border-radius: 14px;
  padding: 16px;
  border: 1px solid rgba(56, 189, 248, 0.12);
}

.recognized-text {
  margin-top: 20px;
}

.recognized-text h3 {
  margin: 0 0 8px;
  font-size: 1.1rem;
}

.recognized-text p {
  margin: 0;
  padding: 12px 16px;
  background: rgba(15, 23, 42, 0.65);
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.25);
  min-height: 52px;
}

.word-highlights {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 16px;
  background: rgba(15, 23, 42, 0.7);
  border-radius: 14px;
  border: 1px solid rgba(56, 189, 248, 0.12);
  min-height: 84px;
  line-height: 1.6;
}

.word {
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 600;
  position: relative;
}

.word::after {
  content: attr(data-score);
  position: absolute;
  inset: auto 0 -22px 0;
  font-size: 0.7rem;
  text-align: center;
  color: var(--muted);
}

.word--good {
  background: rgba(74, 222, 128, 0.2);
  color: var(--success);
}

.word--ok {
  background: rgba(251, 191, 36, 0.18);
  color: var(--warning);
}

.word--bad {
  background: rgba(248, 113, 113, 0.2);
  color: var(--error);
}

.panel--history table {
  width: 100%;
  border-collapse: collapse;
  background: rgba(15, 23, 42, 0.7);
  border-radius: 14px;
  overflow: hidden;
}

.panel--history th,
.panel--history td {
  padding: 12px 16px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.12);
  text-align: left;
  font-size: 0.95rem;
}

.panel--history thead {
  background: rgba(56, 189, 248, 0.12);
}

.panel--history tbody tr:last-child td {
  border-bottom: none;
}

.panel--csv {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.materials-panel {
  border-radius: 16px;
  border: 1px solid rgba(56, 189, 248, 0.12);
  background: rgba(15, 23, 42, 0.55);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

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

.materials-panel__header h3 {
  margin: 0;
  font-size: 1.1rem;
}

.materials-panel__actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.materials-list {
  border-radius: 12px;
  border: 1px solid rgba(56, 189, 248, 0.12);
  background: rgba(15, 23, 42, 0.4);
  max-height: 220px;
  overflow-y: auto;
  padding: 0;
}

.materials-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.12);
  cursor: pointer;
  transition: background 0.15s ease;
}

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

.materials-item:hover {
  background: rgba(56, 189, 248, 0.12);
}

.materials-item--active {
  background: rgba(56, 189, 248, 0.22);
  color: var(--accent);
}

.materials-item__info {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  min-width: 0;
}

.materials-item__name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.materials-item__meta {
  font-size: 0.8rem;
  color: var(--muted);
}

.materials-item__delete {
  background: rgba(248, 113, 113, 0.18);
  color: var(--error);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.8rem;
  border: 1px solid transparent;
}

.materials-item__delete:hover {
  background: rgba(248, 113, 113, 0.25);
}

.csv-table-container {
  border-radius: 16px;
  border: 1px solid rgba(56, 189, 248, 0.12);
  background: rgba(15, 23, 42, 0.65);
  overflow: hidden;
  position: relative;
}

.csv-table-container--empty {
  padding: 24px;
}

.csv-table-container table {
  width: 100%;
  border-collapse: collapse;
}

.csv-table-container th,
.csv-table-container td {
  padding: 12px 16px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.12);
  font-size: 0.95rem;
}

.csv-table-container thead {
  background: rgba(56, 189, 248, 0.12);
}

.csv-table-container tbody tr:last-child td {
  border-bottom: none;
}

.csv-table-container td {
  cursor: pointer;
  transition: background 0.15s ease;
}

.csv-table-container td:hover {
  background: rgba(56, 189, 248, 0.12);
}

.csv-table-cell--active {
  background: rgba(56, 189, 248, 0.18);
  color: var(--accent);
}

.csv-table-scroll {
  max-height: 260px;
  overflow: auto;
}

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  padding: 24px;
  pointer-events: none;
  z-index: 200;
}

.overlay.hidden {
  display: none;
}

.overlay__content {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(15, 23, 42, 0.92);
  padding: 16px 20px;
  border-radius: 16px;
  text-align: left;
  box-shadow: 0 20px 40px -18px rgba(56, 189, 248, 0.35);
  border: 1px solid rgba(56, 189, 248, 0.25);
  pointer-events: auto;
}

.spinner {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 4px solid rgba(148, 163, 184, 0.3);
  border-top-color: var(--accent);
  margin: 0;
  animation: spin 0.85s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

@media (max-width: 768px) {
  .panel {
    padding: 20px;
  }

  .word::after {
    display: none;
  }

  .actions {
    flex-direction: column;
    align-items: stretch;
  }

  .btn {
    width: 100%;
    text-align: center;
  }

  .materials-panel__actions {
    width: 100%;
  }

  .materials-panel__actions .btn {
    flex: 1;
  }
}

.app__back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 0.9rem;
  text-decoration: none;
  transition: color 0.2s ease;
}

.app__back-link:hover {
  color: var(--accent);
}

.home {
  width: min(960px, 94vw);
  margin: 64px auto 96px;
}

.home__header {
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 48px;
}

.home__eyebrow {
  margin: 0;
  font-size: 0.9rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 600;
}

.home__header h1 {
  margin: 0;
  font-size: clamp(2.2rem, 5vw, 2.8rem);
  letter-spacing: 0.05em;
}

.home__lead {
  margin: 0;
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.6;
}

.home__grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 24px;
}

.home-card {
  position: relative;
  background: var(--panel-bg);
  border: 1px solid rgba(148, 163, 184, 0.15);
  border-radius: var(--card-radius);
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: 0 25px 45px -18px rgba(56, 189, 248, 0.2);
  backdrop-filter: blur(10px);
}

.home-card h2 {
  margin: 0;
  font-size: 1.6rem;
}

.home-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.home-card__highlights {
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 10px;
  color: rgba(226, 232, 240, 0.85);
  font-size: 0.95rem;
}

.home-card__highlights li::before {
  content: '•';
  margin-right: 8px;
  color: var(--accent);
}

.home-card__cta {
  margin-top: auto;
  align-self: flex-start;
}

.home-card--coming {
  border: 1px dashed rgba(148, 163, 184, 0.35);
  background: rgba(15, 23, 42, 0.6);
}

.home-card__badge {
  align-self: flex-start;
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(56, 189, 248, 0.2);
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.08em;
}

.home-card--coming .home-card__cta {
  opacity: 0.6;
  cursor: not-allowed;
}

@media (max-width: 640px) {
  .home {
    margin: 48px auto 72px;
  }

  .home-card {
    padding: 24px;
  }

  .home-card__highlights {
    gap: 8px;
  }
}

.vocab {
  width: min(1100px, 95vw);
  margin: 40px auto 80px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.vocab__header {
  margin-bottom: 0;
}

.settings-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-top: 12px;
}

.vocab__sources {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 20px;
}

.vocab-source {
  display: flex;
  flex-direction: column;
  gap: 12px;
  border-radius: 18px;
  border: 1px solid rgba(56, 189, 248, 0.16);
  background: rgba(15, 23, 42, 0.55);
  padding: 20px;
}

.vocab-source__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}


.category-select {
  width: 100%;
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.4);
  background: rgba(15, 23, 42, 0.6);
  color: var(--text);
  padding: 12px 16px;
  font-size: 1rem;
  margin-top: 4px;
}

.category-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.25);
}

.deck-list {
  display: grid;
  gap: 10px;
  max-height: 320px;
  overflow-y: auto;
  padding-right: 4px;
}

.category-item,
.deck-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
  border-radius: 14px;
  border: 1px solid rgba(56, 189, 248, 0.12);
  background: rgba(15, 23, 42, 0.4);
  padding: 12px 14px;
  cursor: pointer;
  transition: border 0.2s ease, background 0.2s ease, transform 0.2s ease;
}

.category-item:hover,
.deck-item:hover {
  border-color: rgba(56, 189, 248, 0.4);
  transform: translateY(-1px);
}

.category-item--active,
.deck-item--active {
  border-color: rgba(56, 189, 248, 0.8);
  background: rgba(56, 189, 248, 0.15);
}

.category-item__title,
.deck-item__title {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-weight: 600;
}

.category-item__meta,
.deck-item__meta {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 0.85rem;
  color: var(--muted);
}

.vocab__workspace {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.workspace__topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
}

.workspace__deck-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.workspace__search {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 240px;
}

.workspace__search input {
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.4);
  background: rgba(15, 23, 42, 0.6);
  color: var(--text);
  padding: 10px 14px;
}

.workspace__search input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.25);
}

.vocab-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  padding: 14px 18px;
  border-radius: 16px;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid rgba(56, 189, 248, 0.12);
  color: rgba(226, 232, 240, 0.85);
  font-size: 0.95rem;
}

.vocab-stats__item {
  cursor: pointer;
  transition: color 0.2s ease, text-decoration-color 0.2s ease;
  display: inline-block;
  width: 100%;
}

.vocab-stats__item:hover,
.vocab-stats__item:focus {
  color: var(--accent);
}

.vocab-stats__item:focus-visible {
  outline: 2px solid rgba(56, 189, 248, 0.5);
  outline-offset: 2px;
}

.vocab-stats__item--active {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-decoration-color: rgba(56, 189, 248, 0.9);
}

.vocab-card {
  border-radius: 22px;
  border: 1px solid rgba(56, 189, 248, 0.18);
  background: radial-gradient(circle at top, rgba(56, 189, 248, 0.1), transparent 70%),
              rgba(15, 23, 42, 0.7);
  padding: 32px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-height: 260px;
  box-shadow: 0 26px 52px -28px rgba(56, 189, 248, 0.4);
}

.vocab-card__body {
  display: flex;
  gap: 20px;
  align-items: stretch;
}

.vocab-card__term-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1 1 50%;
  max-width: 50%;
}

.vocab-card__translation {
  flex: 1 1 50%;
  max-width: 50%;
  font-size: 1.4rem;
  font-weight: 600;
  color: rgba(226, 232, 240, 0.85);
  line-height: 1.4;
  text-align: left;
  margin-left: 0;
  padding-left: 16px;
  white-space: pre-line;
  overflow-wrap: anywhere;
}

.vocab-card__status {
  font-size: 0.9rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 600;
}

.vocab-card__term {
  font-size: clamp(2.2rem, 6vw, 3rem);
  font-weight: 700;
  letter-spacing: 0.04em;
  word-break: normal;
  overflow-wrap: anywhere;
}

.vocab-card__term ruby {
  font-size: inherit;
}

.vocab-card__term rt {
  font-size: 0.6em;
  letter-spacing: 0.08em;
  color: rgba(226, 232, 240, 0.7);
}

.vocab-card__reading {
  color: var(--muted);
  font-size: 0.95rem;
  letter-spacing: 0.04em;
}

.vocab-card__definition {
  margin: 0;
  font-size: 1.1rem;
  line-height: 1.8;
  color: rgba(226, 232, 240, 0.9);
  transition: opacity 0.2s ease;
}

.vocab-card__definition--hidden {
  opacity: 0;
  height: 0;
  overflow: hidden;
  pointer-events: none;
}

.vocab-card__extras {
  display: grid;
  gap: 12px;
}

.vocab-extra {
  border-radius: 14px;
  border: 1px solid rgba(148, 163, 184, 0.16);
  background: rgba(15, 23, 42, 0.55);
  padding: 12px 16px;
}

.vocab-extra__title {
  margin: 0 0 6px;
  font-size: 0.85rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.vocab-extra__content {
  margin: 0;
  font-size: 1rem;
  line-height: 1.5;
  color: rgba(226, 232, 240, 0.9);
  white-space: pre-wrap;
}

.tag-chip {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(56, 189, 248, 0.18);
  color: var(--accent);
  font-size: 0.8rem;
  margin: 2px 6px 2px 0;
}

.vocab-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: space-between;
}

.vocab-controls__group {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.vocab-controls .btn {
  min-width: 110px;
}

.vocab__create {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.create-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.create-grid textarea {
  min-height: 68px;
}

.create-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.hidden {
  display: none !important;
}

@media (max-width: 768px) {
  .vocab {
    margin: 32px auto 64px;
  }

  .vocab-card {
    padding: 24px;
  }

  .vocab-controls {
    flex-direction: column;
    align-items: stretch;
  }

  .vocab-controls__group {
    justify-content: stretch;
  }

  .vocab-controls .btn {
    flex: 1;
  }

  .workspace__search {
    width: 100%;
  }

  .vocab-card__body {
    flex-direction: column;
    gap: 12px;
  }

  .vocab-card__translation {
    min-width: auto;
    text-align: left;
    margin-left: 0;
    padding-left: 0;
    max-width: 100%;
    flex: 1 1 100%;
  }

  .vocab-card__term-stack {
    max-width: 100%;
    flex: 1 1 100%;
  }
}
