/* ===== CSS VARIABLES ===== */
:root {
  --bg: #fdf6e3;
  --bg-card: #ffffff;
  --text: #2d3436;
  --text-light: #636e72;
  --accent: #6c5ce7;
  --accent-hover: #5a4bd1;
  --gold: #f9ca24;
  --gold-dark: #f39c12;
  --green: #a8e6cf;
  --green-dark: #00b894;
  --red: #ffcccc;
  --red-dark: #e17055;
  --danger: #d63031;
  --danger-hover: #c0392b;
  --border: #ddd;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.12);
  --font: 'OpenDyslexic', 'Comic Sans MS', sans-serif;
  --max-width: 600px;
}

/* ===== RESET & BASE ===== */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
}

body {
  font-family: var(--font);
  font-size: 1.2rem;
  line-height: 1.5;
  letter-spacing: 0.12em;
  word-spacing: 0.16em;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ===== LAYOUT ===== */
#app {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 1rem 2rem;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.content {
  padding-top: 1rem;
}

.content.centered {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.hidden {
  display: none !important;
}

/* ===== HEADER ===== */
.app-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1.5rem 0 0.5rem;
  border-bottom: 2px solid var(--gold);
  margin-bottom: 1rem;
}

.app-title {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.app-icon {
  width: 40px;
  height: 40px;
}

.app-header h1 {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text);
}

/* ===== BACK BUTTON ===== */
.btn-back {
  background: none;
  border: none;
  font-size: 1.8rem;
  cursor: pointer;
  color: var(--accent);
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-sm);
  line-height: 1;
  min-width: 48px;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-back:hover {
  background: rgba(108, 92, 231, 0.1);
}

/* ===== BUTTONS ===== */
.btn {
  font-family: var(--font);
  font-size: 1.1rem;
  letter-spacing: 0.08em;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  padding: 0.75rem 1.5rem;
  transition: background 0.2s, transform 0.1s;
  min-height: 48px;
}

.btn:active {
  transform: scale(0.97);
}

.btn-large {
  font-size: 1.2rem;
  padding: 1rem 2rem;
  width: 100%;
}

.btn-small {
  font-size: 0.95rem;
  padding: 0.5rem 1rem;
}

.btn-primary {
  background: var(--accent);
  color: white;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: transparent;
  color: var(--accent);
  border: 2px solid var(--accent);
}

.btn-secondary:hover {
  background: rgba(108, 92, 231, 0.08);
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 2px solid var(--danger);
}

.btn-danger:hover {
  background: rgba(214, 48, 49, 0.08);
}

/* ===== SUBTITLE ===== */
.subtitle {
  font-size: 1.15rem;
  color: var(--text-light);
  margin-bottom: 1.25rem;
}

/* ===== HOME: LIST CARDS ===== */
#list-container {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.list-card {
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow);
  gap: 0.75rem;
}

.list-card-info {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  flex: 1;
  min-width: 0;
}

.list-card-name {
  font-size: 1.15rem;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list-card-meta {
  font-size: 0.9rem;
  color: var(--text-light);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.lang-badge {
  background: var(--accent);
  color: white;
  font-size: 0.75rem;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  font-weight: 700;
  text-transform: uppercase;
}

.list-card-actions {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}

.btn-card {
  font-family: var(--font);
  font-size: 0.95rem;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  padding: 0.5rem 1rem;
  min-height: 48px;
  min-width: 48px;
  transition: background 0.2s;
}

.btn-practice {
  background: var(--gold);
  color: var(--text);
  font-weight: 700;
}

.btn-practice:hover {
  background: var(--gold-dark);
}

.btn-edit {
  background: transparent;
  color: var(--accent);
  border: 2px solid var(--accent);
}

.btn-edit:hover {
  background: rgba(108, 92, 231, 0.08);
}

.home-actions {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.empty-state {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-light);
}

/* ===== FORMS ===== */
.form-group {
  margin-bottom: 1.25rem;
}

.form-group label {
  display: block;
  font-weight: 700;
  margin-bottom: 0.4rem;
  font-size: 1rem;
}

input[type='text'],
input[type='password'],
select {
  font-family: var(--font);
  font-size: 1.1rem;
  letter-spacing: 0.1em;
  padding: 0.75rem 1rem;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  width: 100%;
  background: var(--bg-card);
  color: var(--text);
  transition: border-color 0.2s;
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(108, 92, 231, 0.15);
}

select {
  cursor: pointer;
}

.input-row {
  display: flex;
  gap: 0.5rem;
}

.input-row input {
  flex: 1;
}

.field-status {
  font-size: 0.9rem;
  margin-top: 0.3rem;
  min-height: 1.4em;
}

.field-status.success {
  color: var(--green-dark);
}

.field-status.error {
  color: var(--danger);
}

/* ===== WORD ROWS (EDITOR) ===== */
#word-rows {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.word-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.word-row-number {
  font-weight: 700;
  color: var(--text-light);
  min-width: 1.5em;
  text-align: right;
  font-size: 0.95rem;
}

.word-row input[type='text'] {
  flex: 1;
  padding: 0.6rem 0.75rem;
  font-size: 1rem;
}

.word-row .word-hint {
  flex: 0.7;
}

.btn-remove-word {
  font-family: var(--font);
  background: transparent;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 1.3rem;
  min-width: 48px;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
}

.btn-remove-word:hover {
  background: rgba(214, 48, 49, 0.08);
}

.editor-actions {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 1.5rem;
}

/* ===== MODE SELECTOR ===== */
.mode-choices {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: 100%;
  margin-top: 1rem;
}

.btn-mode {
  font-family: var(--font);
  background: var(--bg-card);
  border: 3px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  box-shadow: var(--shadow);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.btn-mode:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-lg);
}

.mode-icon {
  font-size: 3rem;
}

.mode-label {
  font-size: 1.2rem;
  font-weight: 700;
}

/* ===== PRACTICE ===== */
.progress-bar-container {
  width: 100%;
  height: 12px;
  background: var(--border);
  border-radius: 6px;
  overflow: hidden;
  margin-bottom: 0.5rem;
}

.progress-bar {
  height: 100%;
  background: var(--gold);
  border-radius: 6px;
  transition: width 0.4s ease;
  width: 0%;
}

.practice-counter {
  font-size: 1rem;
  color: var(--text-light);
  margin-bottom: 1.5rem;
}

/* Speaker button */
.btn-speak {
  font-family: var(--font);
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 50%;
  width: 120px;
  height: 120px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  box-shadow: var(--shadow-lg);
  transition: transform 0.15s, background 0.2s;
  margin-bottom: 1.5rem;
}

.btn-speak span {
  font-size: 0.7rem;
  letter-spacing: 0.05em;
}

.btn-speak:hover {
  background: var(--accent-hover);
  transform: scale(1.05);
}

.btn-speak:active {
  transform: scale(0.95);
}

.btn-speak.speaking {
  animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.08);
  }
}

/* Practice input */
.practice-input-area {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.practice-input {
  font-family: var(--font);
  font-size: 2rem;
  letter-spacing: 0.15em;
  text-align: center;
  padding: 1rem;
  border: 3px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  color: var(--text);
  width: 100%;
}

.practice-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(108, 92, 231, 0.15);
}

/* Paper mode */
.practice-paper-area {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  align-items: center;
}

.paper-instruction {
  font-size: 1.1rem;
  color: var(--text-light);
}

/* ===== FEEDBACK ===== */
.feedback-area {
  width: 100%;
  margin-top: 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

/* Star celebration */
.star-container {
  position: relative;
  width: 120px;
  height: 120px;
  margin: 0 auto;
}

.star-main {
  width: 120px;
  height: 120px;
  animation: star-entrance 0.8s cubic-bezier(0.68, -0.55, 0.27, 1.55) forwards,
    star-glow 1.5s 0.8s ease-in-out infinite;
}

@keyframes star-entrance {
  0% {
    transform: scale(0) rotate(0deg);
    opacity: 0;
  }
  50% {
    transform: scale(1.3) rotate(180deg);
    opacity: 1;
  }
  100% {
    transform: scale(1) rotate(360deg);
    opacity: 1;
  }
}

@keyframes star-glow {
  0%,
  100% {
    filter: drop-shadow(0 0 10px var(--gold));
  }
  50% {
    filter: drop-shadow(0 0 25px var(--gold-dark));
  }
}

.star-particle {
  position: absolute;
  width: 20px;
  height: 20px;
  top: 50%;
  left: 50%;
  animation: particle-fly 0.8s ease-out forwards;
}

@keyframes particle-fly {
  0% {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
  }
  100% {
    transform: translate(
        calc(-50% + var(--dx) * 1px),
        calc(-50% + var(--dy) * 1px)
      )
      scale(0);
    opacity: 0;
  }
}

.correct-text {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--green-dark);
}

/* Diff display */
.diff-display {
  width: 100%;
}

.feedback-label {
  font-size: 1.1rem;
  color: var(--text-light);
  margin-bottom: 0.75rem;
}

.diff-chars {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 2px;
  margin-bottom: 1rem;
}

.diff-char {
  display: inline-block;
  font-size: 2rem;
  padding: 0.15em 0.15em;
  border-radius: 4px;
  letter-spacing: 0.15em;
}

.diff-correct {
  color: var(--text);
}

.diff-missing {
  background: var(--green);
  color: var(--text);
  border-bottom: 3px solid var(--green-dark);
}

.diff-extra {
  background: var(--red);
  color: var(--text-light);
  text-decoration: line-through;
}

.feedback-correct-label {
  font-size: 0.95rem;
  color: var(--text-light);
  margin-bottom: 0.25rem;
}

.feedback-correct-word {
  font-size: 2.2rem;
  font-weight: 700;
  color: var(--text);
}

/* Revealed word (paper mode) */
.revealed-word {
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--text);
  padding: 1rem;
  background: var(--bg-card);
  border: 3px solid var(--gold);
  border-radius: var(--radius);
  width: 100%;
}

/* Self-assessment */
.self-assess {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  width: 100%;
}

.btn-assess {
  font-family: var(--font);
  font-size: 1.1rem;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  padding: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  min-height: 56px;
  transition: transform 0.1s;
}

.btn-assess:active {
  transform: scale(0.97);
}

.btn-assess-correct {
  background: var(--gold);
  color: var(--text);
  font-weight: 700;
}

.btn-assess-correct:hover {
  background: var(--gold-dark);
}

.assess-star {
  width: 28px;
  height: 28px;
}

.btn-assess-retry {
  background: transparent;
  color: var(--text);
  border: 2px solid var(--border);
}

.btn-assess-retry:hover {
  background: rgba(0, 0, 0, 0.03);
}

/* Practice navigation */
.practice-nav {
  display: flex;
  gap: 0.75rem;
  width: 100%;
}

.practice-nav .btn {
  flex: 1;
}

/* ===== SUMMARY ===== */
.summary-stars {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
  margin: 1rem 0;
}

.summary-star {
  width: 50px;
  height: 50px;
  opacity: 0.25;
}

.summary-star.earned {
  opacity: 1;
  animation: star-entrance 0.5s cubic-bezier(0.68, -0.55, 0.27, 1.55) forwards;
}

.summary-text {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.summary-message {
  font-size: 1.1rem;
  color: var(--text-light);
  margin-bottom: 2rem;
  max-width: 45ch;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 480px) {
  html {
    font-size: 14px;
  }

  .word-row {
    flex-wrap: wrap;
  }

  .word-row .word-hint {
    flex: 1 1 100%;
  }

  .list-card {
    flex-wrap: wrap;
  }
}
