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

:root {
  --korean-color: #FF8DA1;
  --korean-bg: #FFE4EA;
  --math-color: #6BA3FF;
  --math-bg: #DCEEFF;
  --social-color: #52C96E;
  --social-bg: #D6F5DE;
  --science-color: #FF9A40;
  --science-bg: #FFE8D0;
  --grade-color: #9B6FFF;
  --grade-bg: #EDE0FF;
  --primary-start: #9B6FFF;
  --primary-end: #FF7BAC;
  --text-dark: #2D2D2D;
  --text-mid: #666;
  --bg-page: #FFF5F8;
  --bg-card: #FFFFFF;
  --radius: 20px;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  --font: 'Noto Sans KR', -apple-system, BlinkMacSystemFont, sans-serif;
}

html {
  font-size: 18px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg-page);
  color: var(--text-dark);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
}

/* ============ HEADER ============ */
.app-header {
  background: linear-gradient(135deg, #FF8DA1 0%, #FFB347 55%, #FFD700 100%);
  padding: 14px 20px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 16px rgba(0, 0, 0, 0.14);
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 600px;
  margin: 0 auto;
}

.header-title {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-emoji {
  font-size: 2.4rem;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.15));
}

.header-title h1 {
  font-size: 1.55rem;
  font-weight: 900;
  color: white;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
  line-height: 1.15;
}

.header-title p {
  font-size: 0.82rem;
  color: rgba(255, 255, 255, 0.92);
  font-weight: 500;
}

.btn-settings {
  background: rgba(255, 255, 255, 0.28);
  border: none;
  border-radius: 50%;
  width: 44px;
  height: 44px;
  font-size: 1.3rem;
  cursor: pointer;
  transition: background 0.2s;
  flex-shrink: 0;
  line-height: 1;
}

.btn-settings:hover {
  background: rgba(255, 255, 255, 0.5);
}

/* ============ SCREENS ============ */
#app {
  max-width: 600px;
  margin: 0 auto;
}

.screen {
  padding: 16px 16px 100px;
  animation: fadeIn 0.3s ease;
}

.screen.hidden {
  display: none;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============ CARDS ============ */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.card-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-dark);
  margin-bottom: 14px;
}

/* ============ SUBJECT BUTTONS ============ */
.btn-grid-2x2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.subject-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 18px 12px;
  border: 3px solid transparent;
  border-radius: 16px;
  font-family: var(--font);
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-emoji {
  font-size: 2rem;
  line-height: 1;
}

.subject-btn.korean        { background: var(--korean-bg);  color: #C0405A; }
.subject-btn.math          { background: var(--math-bg);    color: #2455B8; }
.subject-btn.social        { background: var(--social-bg);  color: #1E7C38; }
.subject-btn.science       { background: var(--science-bg); color: #B85A00; }

.subject-btn.korean:hover,  .subject-btn.korean.selected  { background: var(--korean-color);  color: white; border-color: #C0405A;  transform: scale(1.04); box-shadow: 0 4px 16px rgba(255,141,161,0.5); }
.subject-btn.math:hover,    .subject-btn.math.selected    { background: var(--math-color);    color: white; border-color: #2455B8;  transform: scale(1.04); box-shadow: 0 4px 16px rgba(107,163,255,0.5); }
.subject-btn.social:hover,  .subject-btn.social.selected  { background: var(--social-color);  color: white; border-color: #1E7C38;  transform: scale(1.04); box-shadow: 0 4px 16px rgba(82,201,110,0.5);  }
.subject-btn.science:hover, .subject-btn.science.selected { background: var(--science-color); color: white; border-color: #B85A00;  transform: scale(1.04); box-shadow: 0 4px 16px rgba(255,154,64,0.5);   }

/* ============ GRADE BUTTONS ============ */
.btn-grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.grade-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 14px 4px;
  border: 3px solid transparent;
  border-radius: 14px;
  background: var(--grade-bg);
  color: #5B3DB5;
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
}

.grade-btn .btn-emoji { font-size: 1.6rem; }

.grade-btn:hover, .grade-btn.selected {
  background: var(--grade-color);
  color: white;
  border-color: #5B3DB5;
  transform: scale(1.04);
  box-shadow: 0 4px 16px rgba(155, 111, 255, 0.5);
}

/* ============ TEXTAREA ============ */
textarea {
  width: 100%;
  padding: 14px 16px;
  border: 2px solid #E8E0FF;
  border-radius: 14px;
  font-family: var(--font);
  font-size: 1rem;
  color: var(--text-dark);
  background: #FAFAFE;
  resize: none;
  transition: border-color 0.2s;
  outline: none;
  margin-bottom: 14px;
  line-height: 1.6;
}

textarea:focus {
  border-color: var(--grade-color);
  background: white;
}

textarea::placeholder {
  color: #B0A8CC;
}

/* ============ PRIMARY BUTTON ============ */
.btn-primary {
  width: 100%;
  padding: 18px;
  background: linear-gradient(135deg, var(--primary-start) 0%, var(--primary-end) 100%);
  color: white;
  border: none;
  border-radius: 16px;
  font-family: var(--font);
  font-size: 1.2rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 4px 16px rgba(155, 111, 255, 0.4);
  display: block;
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(155, 111, 255, 0.55);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* ============ EXPLAIN SCREEN ============ */
.explain-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  gap: 10px;
}

.btn-back {
  background: white;
  border: 2px solid #E8E0FF;
  border-radius: 12px;
  padding: 10px 16px;
  font-family: var(--font);
  font-size: 1rem;
  font-weight: 600;
  color: #5B3DB5;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s;
}

.btn-back:hover { background: var(--grade-bg); }

.badges {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.badge {
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.88rem;
  font-weight: 700;
  white-space: nowrap;
}

.badge-subject { background: #FFE4EA; color: #C0405A; }
.badge-grade   { background: #EDE0FF; color: #5B3DB5; }

.explain-box {
  background: white;
  border-radius: 20px;
  padding: 24px;
  min-height: 180px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
  border: 2px solid #F0EBFF;
}

/* ============ LOADING ============ */
.loading-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 36px 20px;
  gap: 16px;
}

.loading-area.hidden { display: none; }

.spinner {
  width: 48px;
  height: 48px;
  border: 5px solid #F0EBFF;
  border-top-color: var(--grade-color);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-area p {
  font-size: 1.05rem;
  color: var(--text-mid);
  font-weight: 500;
}

/* ============ EXPLAIN CONTENT ============ */
.explain-content {
  font-size: 1.08rem;
  line-height: 1.95;
  color: var(--text-dark);
  white-space: pre-wrap;
  word-break: keep-all;
}

.explain-content:empty { display: none; }

.success-banner {
  background: linear-gradient(135deg, #D4F5DD, #B8F5C8);
  border: 2px solid #52C96E;
  border-radius: 14px;
  padding: 18px;
  text-align: center;
  margin-bottom: 16px;
  animation: fadeIn 0.4s ease;
}

.success-banner .success-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: #1E7C38;
}

.success-banner .success-sub {
  font-size: 0.95rem;
  font-weight: 500;
  color: #2E7D32;
  margin-top: 6px;
}

/* ============ FAILURE DOTS ============ */
.failure-dots {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-bottom: 14px;
  min-height: 22px;
}

.failure-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #FFB347;
  animation: dotPop 0.3s ease;
}

.failure-dot.danger { background: #FF6B6B; }

@keyframes dotPop {
  0%   { transform: scale(0); }
  60%  { transform: scale(1.3); }
  100% { transform: scale(1); }
}

/* ============ ACTION BUTTONS ============ */
.action-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.btn-good {
  padding: 18px 10px;
  background: linear-gradient(135deg, #52C96E, #2EAF4D);
  color: white;
  border: none;
  border-radius: 16px;
  font-family: var(--font);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 4px 12px rgba(82, 201, 110, 0.4);
}

.btn-good:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(82, 201, 110, 0.55);
}

.btn-notgood {
  padding: 18px 10px;
  background: linear-gradient(135deg, #FFB347, #FF8C00);
  color: white;
  border: none;
  border-radius: 16px;
  font-family: var(--font);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 4px 12px rgba(255, 179, 71, 0.4);
}

.btn-notgood:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(255, 179, 71, 0.55);
}

.btn-good:disabled, .btn-notgood:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

/* ============ MEDITATION SCREEN ============ */
#screen-meditation {
  background: linear-gradient(160deg, #A8EDEA, #FED6E3, #C8B8FF);
  background-size: 300% 300%;
  animation: gradientFlow 8s ease infinite;
  min-height: calc(100vh - 80px);
  min-height: calc(100dvh - 80px);
  padding: 30px 20px 80px;
}

@keyframes gradientFlow {
  0%   { background-position: 0% 50%; }
  50%  { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

.meditation-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 26px;
  max-width: 420px;
  margin: 0 auto;
  text-align: center;
}

.med-title {
  font-size: 1.75rem;
  font-weight: 900;
  color: #3D3060;
  text-shadow: 0 2px 10px rgba(255, 255, 255, 0.7);
}

.med-desc {
  font-size: 1.1rem;
  color: #4A4060;
  line-height: 1.85;
  font-weight: 500;
}

/* ============ BREATHING CIRCLE ============ */
.breath-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.breath-circle {
  width: 160px;
  height: 160px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, rgba(255, 255, 255, 0.95), rgba(168, 237, 234, 0.6));
  border: 4px solid rgba(255, 255, 255, 0.85);
  box-shadow: 0 0 40px rgba(168, 237, 234, 0.55), 0 8px 32px rgba(0, 0, 0, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 4s ease-in-out, box-shadow 4s ease-in-out;
  will-change: transform;
}

.breath-circle.inhale {
  transform: scale(1.5);
  box-shadow: 0 0 70px rgba(168, 237, 234, 0.85), 0 12px 48px rgba(0, 0, 0, 0.1);
}

.breath-circle.exhale {
  transform: scale(1.0);
  box-shadow: 0 0 28px rgba(168, 237, 234, 0.4), 0 6px 20px rgba(0, 0, 0, 0.08);
}

.breath-emoji {
  font-size: 3rem;
  transition: all 0.6s ease;
  user-select: none;
}

.breath-text {
  font-size: 1.3rem;
  font-weight: 700;
  color: #3D3060;
  min-height: 2rem;
  text-shadow: 0 1px 4px rgba(255, 255, 255, 0.8);
}

/* ============ TIMER ============ */
.timer-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.timer-ring {
  position: relative;
  width: 120px;
  height: 120px;
}

.timer-svg {
  width: 120px;
  height: 120px;
  transform: rotate(-90deg);
}

.timer-track {
  fill: none;
  stroke: rgba(255, 255, 255, 0.5);
  stroke-width: 9;
}

.timer-fill {
  fill: none;
  stroke: rgba(155, 111, 255, 0.85);
  stroke-width: 9;
  stroke-linecap: round;
  stroke-dasharray: 326.73;
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 1s linear;
}

.timer-number {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 2.1rem;
  font-weight: 900;
  color: #5B3DB5;
}

.timer-label {
  font-size: 1rem;
  color: #4A4060;
  font-weight: 600;
}

/* ============ MODAL ============ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.42);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  backdrop-filter: blur(4px);
}

.modal-overlay.hidden { display: none; }

.modal-box {
  background: white;
  border-radius: 24px;
  padding: 32px 24px;
  max-width: 400px;
  width: 100%;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.22);
  animation: modalPop 0.28s ease;
  text-align: center;
}

@keyframes modalPop {
  from { transform: scale(0.88); opacity: 0; }
  to   { transform: scale(1);    opacity: 1; }
}

.modal-emoji { font-size: 3rem; margin-bottom: 12px; }

.modal-box h2 {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--text-dark);
}

.modal-box p {
  color: var(--text-mid);
  margin-bottom: 18px;
  font-size: 0.95rem;
}

input[type="password"] {
  width: 100%;
  padding: 14px 16px;
  border: 2px solid #E8E0FF;
  border-radius: 14px;
  font-family: var(--font);
  font-size: 1rem;
  color: var(--text-dark);
  background: #FAFAFE;
  outline: none;
  margin-bottom: 18px;
  transition: border-color 0.2s;
}

input[type="password"]:focus {
  border-color: var(--grade-color);
  background: white;
}

.modal-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.btn-save {
  padding: 14px;
  background: linear-gradient(135deg, var(--primary-start), var(--primary-end));
  color: white;
  border: none;
  border-radius: 12px;
  font-family: var(--font);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-save:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(155, 111, 255, 0.4);
}

.btn-cancel {
  padding: 14px;
  background: #F0EEFC;
  color: var(--text-mid);
  border: none;
  border-radius: 12px;
  font-family: var(--font);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-cancel:hover { background: #E4E0F5; }

/* ============ TOAST ============ */
#toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(45, 28, 78, 0.93);
  color: white;
  padding: 13px 26px;
  border-radius: 28px;
  font-family: var(--font);
  font-size: 1rem;
  font-weight: 600;
  z-index: 9999;
  pointer-events: none;
  max-width: 90vw;
  text-align: center;
  white-space: nowrap;
  transition: opacity 0.35s ease;
}

/* ============ RESPONSIVE ============ */
@media (max-width: 380px) {
  html { font-size: 16px; }
  .grade-btn { padding: 12px 3px; font-size: 0.82rem; }
  .grade-btn .btn-emoji { font-size: 1.35rem; }
  .action-buttons { grid-template-columns: 1fr; }
}
