@font-face {
  font-family: "Hakgyoansim Badasseugi L";
  src: url("./fonts/badasseugi-l.ttf") format("truetype");
  font-weight: 300;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Hakgyoansim Badasseugi B";
  src: url("./fonts/badasseugi-b.ttf") format("truetype");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --ink: #22304a;
  --muted: #68728a;
  --paper: #fffaf1;
  --blue: #44a7ff;
  --pink: #ff6fae;
  --yellow: #ffd84d;
  --green: #46d489;
  --purple: #8e7cff;
  --red: #ff5c6c;
  --display-font: "Hakgyoansim Badasseugi L", "Segoe UI", "Malgun Gothic", system-ui, sans-serif;
  --bold-font: "Hakgyoansim Badasseugi L", "Segoe UI", "Malgun Gothic", system-ui, sans-serif;
  --trace-font: "Hakgyoansim Badasseugi B", "Segoe UI", "Malgun Gothic", system-ui, sans-serif;
  --shadow: 0 18px 40px rgba(36, 46, 84, 0.16);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--display-font);
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 12%, rgba(255, 216, 77, 0.38), transparent 23%),
    radial-gradient(circle at 88% 14%, rgba(255, 111, 174, 0.28), transparent 22%),
    linear-gradient(135deg, #dff6ff 0%, #fff3bf 46%, #f0e8ff 100%);
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s ease;
}

button:active {
  transform: translateY(2px) scale(0.98);
}

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  height: 72px;
  display: grid;
  grid-template-columns: 64px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 10px clamp(12px, 3vw, 32px);
}

.brand {
  justify-self: center;
  font-family: var(--bold-font);
  font-size: clamp(22px, 4vw, 36px);
  color: #26376a;
  text-align: center;
}

.top-actions {
  display: flex;
  gap: 10px;
}

.icon-button {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: #ffffff;
  color: #26376a;
  font-family: var(--bold-font);
  font-size: 26px;
  box-shadow: var(--shadow);
}

main {
  flex: 1;
  position: relative;
  min-height: 0;
}

.view {
  display: none;
  min-height: calc(100vh - 72px);
  padding: clamp(16px, 4vw, 42px);
}

.view.active {
  display: flex;
}

.start-view,
.setup-view,
.finish-view {
  align-items: center;
  justify-content: center;
  gap: clamp(18px, 4vw, 42px);
}

.start-view {
  flex-wrap: wrap;
}

.start-art {
  display: grid;
  grid-template-columns: repeat(2, minmax(64px, 108px));
  gap: 12px;
}

.start-art span {
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border-radius: 22px;
  color: #ffffff;
  font-family: var(--bold-font);
  font-size: clamp(38px, 7vw, 68px);
  box-shadow: var(--shadow);
}

.start-art span:nth-child(1) { background: var(--blue); }
.start-art span:nth-child(2) { background: var(--pink); }
.start-art span:nth-child(3) { background: var(--green); }
.start-art span:nth-child(4) { background: var(--purple); }

.teacher-panel,
.example-panel,
.finish-card {
  width: min(560px, 100%);
  background: rgba(255, 255, 255, 0.86);
  border: 5px solid rgba(255, 255, 255, 0.82);
  border-radius: 28px;
  box-shadow: var(--shadow);
  padding: clamp(20px, 4vw, 36px);
}

.teacher-panel.narrow {
  width: min(640px, 100%);
}

.teacher-panel label,
.teacher-panel h1,
.example-panel h2 {
  display: block;
  margin: 0 0 16px;
  font-family: var(--bold-font);
  font-size: clamp(24px, 5vw, 42px);
}

.word-row {
  display: flex;
  gap: 12px;
}

.word-row input,
.setup-list input {
  min-width: 0;
  width: 100%;
  height: 68px;
  border: 4px solid #bce8ff;
  border-radius: 20px;
  padding: 0 20px;
  background: #ffffff;
  color: var(--ink);
  font-family: var(--bold-font);
  font-size: 30px;
  outline: none;
}

.word-row input:focus,
.setup-list input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 5px rgba(68, 167, 255, 0.22);
}

.hint {
  min-height: 26px;
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 17px;
}

.hint.error {
  color: #cc2749;
}

.primary-button,
.secondary-button,
.small-button,
.example-button {
  border-radius: 18px;
  font-family: var(--bold-font);
  box-shadow: var(--shadow);
}

.primary-button {
  min-width: 124px;
  height: 68px;
  padding: 0 26px;
  background: var(--pink);
  color: #ffffff;
  font-size: 25px;
}

.secondary-button {
  min-width: 116px;
  height: 60px;
  padding: 0 22px;
  background: #ffffff;
  color: #26376a;
  font-size: 22px;
}

.small-button {
  height: 44px;
  padding: 0 18px;
  background: var(--yellow);
  color: #493b00;
  font-size: 18px;
}

.panel-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}

.panel-title-row h2 {
  margin: 0;
}

.example-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.example-button {
  min-height: 68px;
  padding: 8px 12px;
  background: #ffffff;
  border: 4px solid #dcf3ff;
  color: #26376a;
  font-size: clamp(20px, 3.8vw, 30px);
}

.example-button:nth-child(1) { border-color: #91d8ff; }
.example-button:nth-child(2) { border-color: #ffadd0; }
.example-button:nth-child(3) { border-color: #8de9b8; }
.example-button:nth-child(4) { border-color: #c4b8ff; }

.setup-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.setup-actions,
.bottom-actions {
  display: flex;
  justify-content: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-top: 18px;
}

.trace-view #nextBtn {
  display: inline-grid;
  place-items: center;
}

.preview-view,
.trace-view,
.review-view {
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.word-progress {
  width: min(900px, 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  flex-wrap: wrap;
}

.word-strip {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.word-chip {
  width: clamp(52px, 10vw, 82px);
  height: clamp(52px, 10vw, 82px);
  display: grid;
  place-items: center;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.78);
  color: #5c6682;
  font-family: var(--bold-font);
  font-size: clamp(28px, 6vw, 48px);
  box-shadow: 0 10px 24px rgba(36, 46, 84, 0.12);
}

.word-chip.active {
  background: var(--yellow);
  color: #26376a;
  transform: scale(1.08);
}

.word-chip.done {
  background: var(--green);
  color: #ffffff;
  box-shadow: 0 12px 26px rgba(70, 212, 137, 0.34);
}

.word-chip.needs-more {
  background: #ffe2eb;
  color: #cc2749;
  box-shadow: 0 0 0 4px rgba(255, 111, 174, 0.2);
}

.stroke-counter {
  min-width: 150px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: #ffffff;
  color: #26376a;
  font-family: var(--bold-font);
  font-size: 18px;
  box-shadow: var(--shadow);
}

.practice-stage {
  width: min(94vw, calc((100vh - 230px) * 1.93), 1080px);
  aspect-ratio: 1080 / 560;
  position: relative;
  border-radius: 28px;
  background:
    linear-gradient(#e7f6ff 2px, transparent 2px),
    linear-gradient(90deg, #e7f6ff 2px, transparent 2px),
    #ffffff;
  background-size: 70px 70px;
  border: 6px solid #ffffff;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.practice-stage canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

#traceCanvas {
  cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='56' height='56' viewBox='0 0 56 56'%3E%3Cg transform='rotate(142 28 28)'%3E%3Cpath d='M25 8h8l3 30H22z' fill='%23ffd84d' stroke='%2326376a' stroke-width='3' stroke-linejoin='round'/%3E%3Cpath d='M22 38h14l-7 10z' fill='%23f7c7a8' stroke='%2326376a' stroke-width='3' stroke-linejoin='round'/%3E%3Cpath d='M27 47h4l-2 4z' fill='%2326376a'/%3E%3Cpath d='M25 8h8v-4h-8z' fill='%23ff6fae' stroke='%2326376a' stroke-width='3' stroke-linejoin='round'/%3E%3Cpath d='M23.5 16h11' stroke='%23ffffff' stroke-width='3' stroke-linecap='round' opacity='.9'/%3E%3C/g%3E%3C/svg%3E") 13 11, crosshair;
}

.trace-shell.wrong {
  animation: softWrong 0.22s ease;
}

@keyframes softWrong {
  0% { box-shadow: var(--shadow), inset 0 0 0 0 rgba(255, 92, 108, 0); }
  45% { box-shadow: var(--shadow), inset 0 0 0 16px rgba(255, 92, 108, 0.55); }
  100% { box-shadow: var(--shadow), inset 0 0 0 0 rgba(255, 92, 108, 0); }
}

.finish-view {
  position: relative;
  text-align: center;
}

.confetti {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.finish-card {
  position: relative;
  z-index: 1;
}

.finish-badge {
  width: 96px;
  height: 96px;
  display: grid;
  place-items: center;
  margin: 0 auto 14px;
  border-radius: 999px;
  background: var(--yellow);
  color: #ffffff;
  font-family: var(--bold-font);
  font-size: 54px;
  box-shadow: var(--shadow);
}

.finish-card h1 {
  margin: 0 0 14px;
  color: #26376a;
  font-family: var(--bold-font);
  font-size: clamp(34px, 7vw, 62px);
}

.finish-word {
  margin: 18px auto;
  color: var(--pink);
  font-family: var(--bold-font);
  font-size: clamp(50px, 13vw, 120px);
  letter-spacing: 0;
}

@media (max-width: 720px) {
  .topbar {
    grid-template-columns: 52px 1fr auto;
    height: 62px;
    gap: 8px;
  }

  .icon-button {
    width: 46px;
    height: 46px;
    border-radius: 12px;
    font-size: 23px;
  }

  .view {
    min-height: calc(100vh - 62px);
    padding: 14px;
  }

  .word-row {
    flex-direction: column;
  }

  .primary-button,
  .secondary-button {
    width: 100%;
  }

  .practice-stage {
    width: 94vw;
  }
}
