:root {
  --bg: #f4f7fb;
  --panel: rgba(255, 255, 255, 0.88);
  --panel-strong: #ffffff;
  --text: #17324d;
  --muted: #6d8299;
  --primary: #4f7cff;
  --primary-dark: #325fe0;
  --secondary: #eef3ff;
  --success: #13b67c;
  --warning: #ffb545;
  --border: rgba(111, 141, 174, 0.18);
  --shadow: 0 18px 45px rgba(47, 82, 140, 0.12);
  --radius-lg: 28px;
  --radius-md: 20px;
  --radius-sm: 14px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Inter", system-ui, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(107, 168, 255, 0.28), transparent 28%),
    radial-gradient(circle at top right, rgba(133, 110, 255, 0.2), transparent 24%),
    linear-gradient(180deg, #f7faff 0%, #edf3fb 100%);
}

body.focus-mode {
  height: 100vh;
  height: 100dvh;
  height: 100svh;
  min-height: -webkit-fill-available;
  overflow: hidden;
  margin: 0;
}

body.focus-mode .app-shell {
  width: min(1000px, calc(100% - 24px));
  height: 100%;
  padding: 16px 0;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
}

body.focus-mode .hero,
body.focus-mode .controls-panel,
body.focus-mode .stats-grid,
body.focus-mode .progress-panel,
body.focus-mode .wordlist-panel {
  display: none;
}

body.focus-mode .layout {
  flex: 1;
  min-height: 0;
  margin-top: 0;
  display: flex;
  flex-direction: column;
}

body.focus-mode .study-grid {
  grid-template-columns: 1fr;
  flex: 1;
  min-height: 0;
  height: 100%;
}

body.focus-mode .flashcard-panel {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 16px;
  background: rgba(255, 255, 255, 0.96);
  box-sizing: border-box;
  overflow: hidden;
}

body.focus-mode .flashcard-panel .panel__header {
  flex-shrink: 0;
  margin-bottom: 8px;
}

body.focus-mode .flashcard {
  flex: 1 1 0;
  min-height: 0;
  overflow: hidden;
}

body.focus-mode .flashcard__inner {
  height: 100%;
  min-height: 0;
}

body.focus-mode .flashcard__face {
  padding: 16px;
  box-shadow: 0 24px 80px rgba(18, 33, 59, 0.2);
  overflow-y: auto;
}

body.focus-mode .flashcard-actions {
  flex-shrink: 0;
  margin-top: 8px;
}

body.focus-mode .flashcard h3 {
  font-size: clamp(2.8rem, 6vw, 4.8rem);
}

body.focus-mode .phonetic,
body.focus-mode .example,
body.focus-mode .hint {
  font-size: 1.1rem;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
  border: none;
}

.app-shell {
  width: min(1200px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 48px;
}

.hero {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  padding: 32px;
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, #1e66f5 0%, #5b8cff 46%, #8f70ff 100%);
  color: white;
  box-shadow: var(--shadow);
}

.hero__content h1 {
  margin: 10px 0 12px;
  font-size: clamp(2rem, 4vw, 3.2rem);
  line-height: 1.1;
}

.hero__content p {
  margin: 0;
  max-width: 640px;
  color: rgba(255, 255, 255, 0.88);
  font-size: 1rem;
}

.hero__eyebrow {
  display: inline-flex;
  align-items: center;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
  color: rgba(255, 255, 255, 0.95);
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.hero__badge {
  min-width: 180px;
  align-self: flex-start;
  padding: 20px;
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.14);
  backdrop-filter: blur(12px);
}

.hero__badge span {
  display: block;
  color: rgba(255, 255, 255, 0.8);
  font-size: 0.9rem;
}

.hero__badge strong {
  display: block;
  margin-top: 10px;
  font-size: 1.6rem;
}

.layout {
  display: grid;
  gap: 20px;
  margin-top: 0px;
}

.panel {
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.panel__header h2 {
  margin: 0;
  font-size: 1.15rem;
}

.panel__header span {
  color: var(--muted);
  font-size: 0.95rem;
}

.flashcard-panel__tools {
  display: inline-flex;
  align-items: center;
  gap: 12px;
}

.controls-grid,
.stats-grid,
.study-grid {
  display: grid;
  gap: 18px;
}

.controls-grid {
  grid-template-columns: minmax(0, 1.7fr) repeat(5, minmax(0, 1fr));
}

.field {
  display: grid;
  gap: 8px;
}

.field span {
  font-weight: 600;
  color: var(--muted);
}

.field input,
.field select {
  width: 100%;
  height: 52px;
  padding: 0 16px;
  border: 1px solid rgba(106, 127, 153, 0.22);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.95);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.field input:focus,
.field select:focus {
  border-color: rgba(79, 124, 255, 0.6);
  box-shadow: 0 0 0 4px rgba(79, 124, 255, 0.12);
}

.stats-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.stat-card {
  display: grid;
  gap: 10px;
}

.stat-card__label {
  color: var(--muted);
  font-weight: 600;
}

.stat-card strong {
  font-size: 1.9rem;
}

.progress-track {
  overflow: hidden;
  height: 16px;
  border-radius: 999px;
  background: #e7eef9;
}

.progress-bar {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #18c98b 0%, #53d769 100%);
  transition: width 0.25s ease;
}

.study-grid {
  grid-template-columns: minmax(0, 1.1fr) minmax(320px, 0.9fr);
  align-items: start;
}

.flashcard-panel,
.wordlist-panel {
  min-height: 100%;
}

.flashcard {
  position: relative;
  min-height: 340px;
  perspective: 1400px;
  border-radius: 26px;
  outline: none;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-drag: none;
  transition: transform 0.25s ease, box-shadow 0.25s ease;
}

.flashcard:hover {
  transform: translateY(-2px);
}

.flashcard__inner {
  position: relative;
  width: 100%;
  min-height: 340px;
  transform-style: preserve-3d;
  transition: transform 0.7s ease;
}

.flashcard.is-flipped .flashcard__inner {
  transform: rotateY(180deg);
}

.flashcard__face {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 14px;
  padding: 20px;
  border-radius: 26px;
  backface-visibility: hidden;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.35);
}

.flashcard__face--front {
  background: linear-gradient(145deg, #fefeff 0%, #edf4ff 100%);
}

.flashcard__face--back {
  transform: rotateY(180deg);
  background: linear-gradient(145deg, #152f52 0%, #214a7b 100%);
  color: white;
}

.flashcard__meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.flashcard-word-row,
.word-item__title-group {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
}

.flashcard h3 {
  margin: 0;
  font-size: clamp(2rem, 4vw, 3rem);
  line-height: 1.1;
}

.phonetic,
.example,
.example-translation,
.hint {
  margin: 0;
}

.phonetic,
.hint {
  color: var(--muted);
}

.example-translation {
  font-size: 0.98rem;
  font-weight: 500;
  color: rgba(23, 50, 77, 0.78);
}

.flashcard__face--back .hint,
.flashcard__face--back .example,
.flashcard__face--back .example-translation {
  color: rgba(255, 255, 255, 0.82);
}

.topic-badge,
.pos-badge,
.status-pill,
.word-item__topic,
.word-item__status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
}

.topic-badge {
  background: rgba(79, 124, 255, 0.12);
  color: var(--primary-dark);
}

.pos-badge {
  background: rgba(255, 181, 69, 0.18);
  color: #ad6e00;
}

.status-pill,
.word-item__status {
  background: rgba(19, 182, 124, 0.16);
  color: #0e8c60;
}

.status-pill.is-unlearned,
.word-item__status.is-unlearned {
  background: rgba(108, 129, 153, 0.14);
  color: #607489;
}

.flashcard-actions {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  gap: 10px;
  margin-top: 18px;
  width: 100%;
}

.flashcard-actions button {
  flex: 1 1 0px;
  min-width: 0;
  white-space: nowrap;
  text-align: center;
}

.primary-button,
.secondary-button,
.mark-button,
.ghost-button {
  min-height: 52px;
  padding: 12px 18px;
  border-radius: 16px;
  font-weight: 700;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.2s ease;
}

.primary-button:hover,
.secondary-button:hover,
.mark-button:hover,
.ghost-button:hover,
.word-item:hover {
  transform: translateY(-1px);
}

.primary-button {
  color: white;
  background: linear-gradient(135deg, var(--primary) 0%, #7b77ff 100%);
}

.secondary-button {
  color: var(--text);
  background: var(--secondary);
}

.mark-button {
  color: white;
  background: linear-gradient(135deg, var(--success) 0%, #49d18e 100%);
}

.mark-button.is-active {
  background: linear-gradient(135deg, #ffb34b 0%, #ff8a4c 100%);
}

.ghost-button {
  color: var(--primary-dark);
  background: rgba(79, 124, 255, 0.12);
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 42px;
  min-height: 42px;
  padding: 0;
  border-radius: 999px;
  color: var(--primary-dark);
  background: rgba(79, 124, 255, 0.12);
  font-size: 1rem;
  line-height: 1;
}

.icon-button:hover {
  transform: translateY(-1px);
}

.word-list {
  display: grid;
  gap: 12px;
  max-height: 640px;
  overflow: auto;
  padding-right: 4px;
}

.word-item {
  width: 100%;
  display: grid;
  gap: 10px;
  padding: 16px;
  text-align: left;
  border: 1px solid rgba(106, 127, 153, 0.16);
  border-radius: 18px;
  background: var(--panel-strong);
  box-shadow: 0 10px 24px rgba(67, 92, 127, 0.08);
}

.word-item.is-selected {
  border-color: rgba(79, 124, 255, 0.45);
  box-shadow: 0 14px 28px rgba(79, 124, 255, 0.18);
}

.word-item__top,
.word-item__footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.word-item__title-group {
  justify-content: flex-start;
}

.word-item__word {
  font-size: 1.05rem;
}

.word-item__meaning,
.word-item__phonetic {
  margin: 0;
  color: var(--muted);
}

.word-list__empty {
  padding: 28px 16px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed rgba(106, 127, 153, 0.3);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.7);
}

@media (max-width: 960px) {

  .hero,
  .study-grid,
  .controls-grid,
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .hero {
    flex-direction: column;
  }

  .hero__badge {
    width: 100%;
  }
}

@media (max-width: 640px) {
  .app-shell {
    width: min(100% - 20px, 1000px);
    padding-top: 0px;
  }

  .flashcard-panel__tools {
    width: 100%;
    justify-content: space-between;
  }

  .hero,
  .panel {
    padding: 18px;
    border-radius: 22px;
  }

  .flashcard,
  .flashcard__inner {
    min-height: 300px;
  }

  /* In focus mode, override min-height so flashcard can shrink with flex */
  body.focus-mode .flashcard,
  body.focus-mode .flashcard__inner {
    min-height: 0 !important;
  }

  body.focus-mode .app-shell {
    width: calc(100% - 16px);
    padding: 8px 0;
  }

  body.focus-mode .flashcard-panel {
    padding: 10px;
  }

  body.focus-mode .flashcard__face {
    padding: 10px;
  }

  .flashcard__face {
    padding: 16px;
  }

  .flashcard-actions {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 4px;
  }

  .flashcard-actions button {
    flex: 1 1 0px;
    min-width: 0;
    white-space: nowrap;
    text-align: center;
  }

  .primary-button,
  .secondary-button,
  .mark-button {
    min-height: 42px;
    padding: 6px 2px;
    font-size: 0.78rem;
  }

  .word-list {
    max-height: none;
  }
}