* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  min-height: 100vh;
  background: #777269;
  font-family: Arial, Helvetica, sans-serif;
  display: flex;
  justify-content: center;
  padding: 16px;
}

button {
  font: inherit;
}

.app-frame {
  width: 360px;
  height: 760px;
  background: #ddd3b8;
  border: 5px solid #000;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.screen {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

.hidden {
  display: none !important;
}

/* ================= START SCREEN ================= */

.start-wrap {
  height: 100%;
  min-height: 0;
}

.compact-start {
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.mode-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  flex: 0 0 auto;
}

.mode-btn {
  appearance: none;
  border: 4px solid #000;
  background: #d7d1c1;
  color: #000;
  font-size: 16px;
  font-weight: 700;
  padding: 11px 8px;
  border-radius: 14px;
  cursor: pointer;
}

.mode-btn.active {
  background: #9bdce7;
}

.compact-curriculum {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow: hidden;
}

.menu-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.menu-section-title {
  font-family: "Noto Serif KR", serif;
  font-size: 18px;
  font-weight: 600;
  color: #000;
  text-align: center;
  margin-bottom: 2px;
  letter-spacing: 0.5px;
}

.menu-row {
  display: flex;
  flex-direction: column;
}

.menu-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  column-gap: 10px;
  row-gap: 10px;
}

.stage-btn {
  appearance: none;
  border: 3px solid #000;
  border-radius: 12px;
  background: #cbc7bc;
  color: #000;
  cursor: pointer;
  font-weight: 700;
  text-align: center;
}

.menu-stage-btn {
  height: 44px;
  min-height: 44px;
  padding: 4px 2px;
  font-size: 14px;
  letter-spacing: 0;
}

.menu-stage-btn.mix {
  background: #e4d099;
}

.stage-btn.selected {
  outline: 3px solid #000;
  outline-offset: -4px;
}

.stage-btn.guide-cleared {
  background: #efe4a8;
}

.stage-btn.memory-cleared {
  background: #bfe3b7;
}

.stage-btn.locked {
  opacity: 0.35;
  cursor: not-allowed;
}

#start-btn {
  flex: 0 0 auto;
  appearance: none;
  border: 4px solid #000;
  background: #79c7c7;
  color: #000;
  font-size: 18px;
  font-weight: 700;
  padding: 13px 10px;
  border-radius: 14px;
  cursor: pointer;
}

#start-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ================= PRACTICE SCREEN ================= */

#practice-screen {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
}

.top-bar {
  flex: 0 0 104px;
  min-height: 104px;
  border-bottom: 4px solid #000;
  display: grid;
  grid-template-columns: 56px 1fr 56px;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  background: #a5e0f1;
}

.top-center {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

#romanization {
  display: block;
  width: 100%;
  text-align: center;
  font-size: 42px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #000;
}

.icon-btn {
  appearance: none;
  border: 3px solid #000;
  background: #d7d1c1;
  color: #000;
  font-size: 28px;
  font-weight: 700;
  width: 48px;
  height: 48px;
  padding: 0;
  cursor: pointer;
  border-radius: 12px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn.disabled,
.icon-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

#speak-btn img {
  width: 24px;
  height: 24px;
  display: block;
  pointer-events: none;
}

.practice-area {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: #ececec;
}

.canvas-panel {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  background: #ececec;
}

.canvas-inner {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  background:
    radial-gradient(rgba(0, 0, 0, 0.015) 1px, transparent 1px),
    #e9e0c8;
  background-size: 4px 4px;
  transition: background 0.25s ease;
  touch-action: none;
}

#draw-canvas {
  position: relative;
  z-index: 2;
  display: block;
  width: 100%;
  height: 100%;
  background: transparent;
  touch-action: none;
  cursor: crosshair;
}

.result-footer {
  flex: 0 0 80px;
  min-height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #e3dac3;
  color: #000;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
}

#result-text {
  opacity: 0;
  transition: opacity 0.2s ease;
  font-size: 24px;
  font-weight: 700;
  color: #000;
}

.result-footer.visible #result-text {
  opacity: 1;
}

.controls {
  flex: 0 0 84px;
  min-height: 84px;
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.controls button {
  appearance: none;
  border: none;
  border-top: 4px solid #000;
  background: #9bdce7;
  color: #000;
  font-size: 22px;
  font-weight: 700;
  padding: 14px 10px;
  cursor: pointer;
}

.controls button:nth-child(2),
.controls button:nth-child(4) {
  border-left: 4px solid #000;
}

/* ================= END SCREEN ================= */

#end-screen .start-wrap {
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 14px;
}

#end-screen h2 {
  margin: 0;
  font-size: 28px;
  text-align: center;
  color: #000;
}

#final-score {
  font-size: 18px;
  line-height: 1.5;
  color: #000;
}

.session-note {
  margin-top: 8px;
  font-weight: 700;
}

/* ================= CANVAS FEEDBACK ================= */

.canvas-inner.correct {
  background: #cfeecf;
}

.canvas-inner.partial {
  background: #f3ebc4;
}

.canvas-inner.wrong {
  background: #efc9c9;
}

/* ================= SESSION GRADE FEEDBACK ================= */

.grade-great .canvas-inner {
  background: #cfeecf;
}

.grade-good .canvas-inner {
  background: #e8edd8;
}

.grade-okay .canvas-inner {
  background: #eee4c9;
}

.grade-bad .canvas-inner {
  background: #efd0d0;
}