@font-face {
  font-family: 'Andika';
  src: url('fonts/Andika-Regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: block;
}
@font-face {
  font-family: 'Andika';
  src: url('fonts/Andika-Bold.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: block;
}

:root {
  --purple: #6C5CE7;
  --purple-light: #A281F7;
  --bg: #F4F1FF;
  --ink: #2D2A4A;
  --coral: #FF7A59;
  --pink: #FF6B9D;
  --yellow: #FFC93C;
  --green: #2ECC71;
  --grey-line: #D9D4F5;
  --card-bg: #FFFFFF;
  --radius: 22px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  overscroll-behavior: none;
}

body {
  margin: 0;
  font-family: 'Comic Sans MS', 'Chalkboard SE', 'Segoe UI Rounded',
    system-ui, -apple-system, sans-serif;
  background: linear-gradient(160deg, var(--bg), #EDE7FF 60%, #F9F0FF);
  color: var(--ink);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

#app {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

.screen {
  position: absolute;
  inset: 0;
  padding: calc(16px + var(--safe-top)) 16px calc(16px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  animation: fade-in .25s ease;
}

@keyframes fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- shared bits ---------- */

.icon-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: var(--card-bg);
  box-shadow: 0 4px 12px rgba(108, 92, 231, .18);
  font-size: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex: none;
}
.icon-btn:active { transform: scale(.92); }

.top-left { position: absolute; top: calc(16px + var(--safe-top)); left: 16px; }
.top-right { position: absolute; top: calc(16px + var(--safe-top)); right: 16px; }

.btn {
  font-family: inherit;
  font-weight: 700;
  border: none;
  border-radius: 999px;
  padding: 14px 28px;
  font-size: 18px;
  cursor: pointer;
  color: white;
  background: var(--purple);
  box-shadow: 0 6px 0 #4E3FC4;
}
.btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #4E3FC4; }

.btn-huge { padding: 20px 40px; font-size: 22px; width: 100%; max-width: 360px; }
.btn-primary { background: linear-gradient(135deg, var(--coral), var(--pink)); box-shadow: 0 6px 0 #C24E37; }
.btn-primary:active { box-shadow: 0 2px 0 #C24E37; }
.btn-secondary { background: var(--purple); }
.btn-ghost {
  background: white;
  color: var(--purple);
  box-shadow: 0 4px 0 var(--grey-line);
}
.btn-ghost:active { box-shadow: 0 1px 0 var(--grey-line); }
.btn-danger { color: #E74C3C; }

/* ---------- home ---------- */

.home-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  text-align: center;
}

.mascot { font-size: 72px; }

#home-greeting {
  font-size: clamp(32px, 8vw, 48px);
  margin: 0;
  color: var(--purple);
}

.subtitle { margin: 0 0 8px; font-size: 18px; opacity: .8; }

.profile-switcher {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  margin-bottom: 2px;
}
.profile-pill {
  font-family: inherit;
  font-weight: 700;
  font-size: 15px;
  padding: 8px 18px;
  border-radius: 999px;
  border: none;
  background: white;
  color: var(--ink);
  opacity: .55;
  box-shadow: 0 3px 8px rgba(108, 92, 231, .15);
  cursor: pointer;
}
.profile-pill.active {
  opacity: 1;
  color: white;
  background: linear-gradient(135deg, var(--coral), var(--pink));
}

.stars-summary {
  display: flex;
  align-items: center;
  gap: 8px;
  background: white;
  padding: 8px 18px;
  border-radius: 999px;
  box-shadow: 0 4px 12px rgba(108, 92, 231, .15);
  font-weight: 700;
  margin-bottom: 6px;
}

.ios-hint {
  max-width: 320px;
  font-size: 14px;
  opacity: .7;
  margin-top: 4px;
}

/* ---------- settings / word select panels ---------- */

.panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-width: 480px;
  width: 100%;
  margin: 0 auto;
  padding-top: 64px;
  overflow-y: auto;
}

.panel h2 { color: var(--purple); margin: 0 0 4px; }

.field-label { font-weight: 700; font-size: 15px; margin-bottom: 2px; }

.text-input {
  font-family: inherit;
  font-size: 20px;
  padding: 14px 16px;
  border-radius: 14px;
  border: 2px solid var(--grey-line);
  background: white;
  -webkit-user-select: text;
  user-select: text;
}
.text-input:focus { outline: none; border-color: var(--purple); }

.field-group { border: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }

.radio-row, .switch-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: white;
  padding: 12px 16px;
  border-radius: 14px;
  font-size: 16px;
  justify-content: flex-start;
}
.switch-row { justify-content: space-between; }
.radio-row input, .switch-row input { width: 20px; height: 20px; }
.radio-row em { opacity: .6; font-style: normal; }

.settings-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }

.profile-list { display: flex; flex-direction: column; gap: 8px; }
.profile-row { display: flex; gap: 8px; align-items: center; }
.profile-row .text-input { flex: 1; }
.profile-remove { width: 44px; height: 44px; font-size: 16px; flex: none; }

.word-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 8px;
}

.word-chip {
  flex: 1 1 auto;
  min-width: 120px;
  background: white;
  border: none;
  border-radius: 18px;
  padding: 18px;
  font-family: inherit;
  font-size: 22px;
  font-weight: 700;
  color: var(--ink);
  box-shadow: 0 4px 12px rgba(108, 92, 231, .15);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.word-chip:active { transform: scale(.96); }
.word-chip .word-chip-stars { font-size: 13px; color: var(--purple); font-weight: 700; }

/* ---------- trace screen ---------- */

.screen-trace { padding-left: 10px; padding-right: 10px; }

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

.trace-header-title {
  flex: 1;
  text-align: center;
  font-size: clamp(16px, 4.5vw, 20px);
  font-weight: 700;
  color: var(--purple);
}

.trace-progress-bar-wrap {
  height: 10px;
  border-radius: 999px;
  background: var(--grey-line);
  overflow: hidden;
  margin: 10px auto 4px;
  width: 100%;
  max-width: 560px;
  flex: none;
}
.trace-progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--coral), var(--yellow));
  transition: width .15s ease;
}

.trace-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 14px;
  padding: 8px 0 4px;
  max-width: 560px;
  width: 100%;
  margin: 0 auto;
}

.word-block { display: flex; flex-direction: column; gap: 4px; animation: fade-in .3s ease; }

.word-caption {
  font-size: 17px;
  font-weight: 700;
  color: var(--purple);
  opacity: .75;
  padding: 0 4px;
  text-align: center;
}
.word-caption.word-caption-done { color: var(--green); opacity: 1; }

.canvas-scroll {
  overflow-x: auto;
  overflow-y: hidden;
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(108, 92, 231, .18);
  background: white;
  -webkit-overflow-scrolling: touch;
}

.letter-canvas {
  display: block;
  touch-action: none;
  -webkit-touch-callout: none;
}

.trace-controls {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}
.trace-controls .btn { flex: 1 1 0; min-width: 100px; padding: 14px 10px; font-size: 15px; }

/* ---------- celebrate ---------- */

#screen-celebrate {
  align-items: center;
  justify-content: center;
}

#confetti-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.celebrate-content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
  margin: auto;
}

.celebrate-emoji { font-size: 80px; }
#celebrate-title { color: var(--purple); margin: 0; font-size: clamp(30px, 8vw, 44px); }
#celebrate-subtitle { margin: 0 0 6px; opacity: .8; font-size: 18px; }

.celebrate-stars {
  font-size: 30px;
  letter-spacing: 4px;
  margin-bottom: 10px;
}

[hidden] { display: none !important; }
