/* ============================================================
   공통 디자인 시스템 — "친근한 아케이드"
   허브: 인터랙티브 학습·두뇌 게임·퀴즈·미니도구
   전 연령 대상이되 유아틱하지 않은 일반 사용자용 톤.
   모든 앱은 이 파일 하나를 링크해 동일한 룩을 공유한다.
   경로 예: <link rel="stylesheet" href="../../_shared/design-system.css">
   ============================================================ */

/* ---------- 토큰 (라이트 기본) ---------- */
:root {
  /* 중립색 — 살짝 쿨(브랜드 쪽) 편향, 무채색 아님 */
  --bg:        #f6f7fb;
  --surface:   #ffffff;
  --surface-2: #eef1f7;
  --border:    #e2e6f0;
  --border-2:  #d3d9e8;
  --text:      #171a22;
  --text-soft: #4a5266;
  --text-faint:#7a8399;

  /* 브랜드 — 코발트 인디고 + 앰버(보색, 에너지) */
  --brand:     #3b54e6;
  --brand-ink: #2b3fc0;
  --brand-soft:#e5e9fd;
  --accent:    #ffc233;
  --accent-ink:#c8880a;
  --accent-soft:#fff2cf;

  /* 의미색 */
  --good: #16a34a; --good-soft: #dcf5e6;
  --warn: #d98a0b; --warn-soft: #fbeccb;
  --bad:  #e23d3d; --bad-soft:  #fbdede;

  /* 카테고리 색상 (허브의 "아케이드" 다채로움) */
  --cat-time:   #f5a623;
  --cat-math:   #3d9bff;
  --cat-memory: #8b5cf6;
  --cat-react:  #ff5a5f;
  --cat-games:  #22b07d;
  --cat-music:  #ec4899;
  --cat-geo:    #14b8c4;
  --cat-gen:    #64748b;
  --cat-print:  #fb7a3c;
  --cat-money:  #16a34a;

  /* 타이포 — display=둥근 지오메트릭, body=휴머니스트 산세리프.
     실제 배포 시 Outfit/Manrope를 self-host 권장. fallback으로도 준수. */
  --font-display: "Outfit", "Manrope", ui-rounded, "Segoe UI", system-ui, -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  --font-body:    "Manrope", system-ui, -apple-system, "Segoe UI", Roboto, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  --font-mono:    ui-monospace, "SFMono-Regular", "Cascadia Code", Consolas, monospace;

  /* 타입 스케일 */
  --fs-xs: .75rem; --fs-sm: .875rem; --fs-base: 1rem; --fs-lg: 1.125rem;
  --fs-xl: 1.375rem; --fs-2xl: 1.75rem; --fs-3xl: 2.25rem; --fs-4xl: 3rem;

  /* 간격 (4px 베이스) */
  --sp-1: .25rem; --sp-2: .5rem; --sp-3: .75rem; --sp-4: 1rem; --sp-5: 1.5rem;
  --sp-6: 2rem; --sp-7: 3rem; --sp-8: 4rem;

  /* 라운드 */
  --r-sm: 8px; --r-md: 12px; --r-lg: 18px; --r-xl: 26px; --r-full: 999px;

  /* 그림자 */
  --shadow-sm: 0 1px 2px rgba(23,26,34,.06), 0 1px 1px rgba(23,26,34,.04);
  --shadow-md: 0 2px 6px rgba(23,26,34,.06), 0 10px 24px -12px rgba(23,26,34,.18);
  --shadow-lg: 0 8px 40px -12px rgba(59,84,230,.28);

  --wrap: 72rem;
  --header-h: 4rem;
}

/* ---------- 다크 ---------- */
@media (prefers-color-scheme: dark) {
  :root {
    --bg:        #0f1218;
    --surface:   #171b24;
    --surface-2: #1e232e;
    --border:    #2a303d;
    --border-2:  #353c4b;
    --text:      #e9ecf3;
    --text-soft: #aeb6c6;
    --text-faint:#7c8598;
    --brand:     #7b8cff;
    --brand-ink: #9aa7ff;
    --brand-soft:#1c2340;
    --accent:    #ffce5c;
    --accent-ink:#ffd982;
    --accent-soft:#33280f;
    --good:#4ade80; --good-soft:#123021;
    --warn:#f2b23e; --warn-soft:#332711;
    --bad:#f26a6a;  --bad-soft:#331717;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
    --shadow-md: 0 2px 6px rgba(0,0,0,.35), 0 12px 30px -14px rgba(0,0,0,.7);
    --shadow-lg: 0 10px 44px -12px rgba(123,140,255,.35);
  }
}
:root[data-theme="light"] {
  --bg:#f6f7fb; --surface:#fff; --surface-2:#eef1f7; --border:#e2e6f0; --border-2:#d3d9e8;
  --text:#171a22; --text-soft:#4a5266; --text-faint:#7a8399;
  --brand:#3b54e6; --brand-ink:#2b3fc0; --brand-soft:#e5e9fd; --accent:#ffc233; --accent-ink:#c8880a; --accent-soft:#fff2cf;
  --good:#16a34a; --good-soft:#dcf5e6; --warn:#d98a0b; --warn-soft:#fbeccb; --bad:#e23d3d; --bad-soft:#fbdede;
  --shadow-sm:0 1px 2px rgba(23,26,34,.06),0 1px 1px rgba(23,26,34,.04);
  --shadow-md:0 2px 6px rgba(23,26,34,.06),0 10px 24px -12px rgba(23,26,34,.18);
  --shadow-lg:0 8px 40px -12px rgba(59,84,230,.28);
}
:root[data-theme="dark"] {
  --bg:#0f1218; --surface:#171b24; --surface-2:#1e232e; --border:#2a303d; --border-2:#353c4b;
  --text:#e9ecf3; --text-soft:#aeb6c6; --text-faint:#7c8598;
  --brand:#7b8cff; --brand-ink:#9aa7ff; --brand-soft:#1c2340; --accent:#ffce5c; --accent-ink:#ffd982; --accent-soft:#33280f;
  --good:#4ade80; --good-soft:#123021; --warn:#f2b23e; --warn-soft:#332711; --bad:#f26a6a; --bad-soft:#331717;
  --shadow-sm:0 1px 2px rgba(0,0,0,.4);
  --shadow-md:0 2px 6px rgba(0,0,0,.35),0 12px 30px -14px rgba(0,0,0,.7);
  --shadow-lg:0 10px 44px -12px rgba(123,140,255,.35);
}

/* ---------- 리셋/베이스 ---------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg); color: var(--text);
  font-family: var(--font-body); font-size: var(--fs-base); line-height: 1.6;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
  min-height: 100dvh;
}
h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 700; line-height: 1.15; letter-spacing: -.01em; text-wrap: balance; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
img, svg, canvas { display: block; max-width: 100%; }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; border-radius: 4px; }
.container { max-width: var(--wrap); margin-inline: auto; padding-inline: var(--sp-4); }
.tnum { font-variant-numeric: tabular-nums; }
.sr-only { position:absolute; width:1px; height:1px; padding:0; margin:-1px; overflow:hidden; clip:rect(0 0 0 0); white-space:nowrap; border:0; }

/* ---------- 헤더 ---------- */
.app-header {
  position: sticky; top: 0; z-index: 50;
  height: var(--header-h);
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.app-header .inner { max-width: var(--wrap); margin-inline: auto; height: 100%; padding-inline: var(--sp-4);
  display: flex; align-items: center; gap: var(--sp-4); }
.brand { display: inline-flex; align-items: center; gap: .55rem; font-family: var(--font-display);
  font-weight: 800; font-size: 1.2rem; letter-spacing: -.02em; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand .mark { width: 1.9rem; height: 1.9rem; border-radius: 9px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--brand), color-mix(in srgb, var(--brand) 55%, var(--accent)));
  color: #fff; font-size: 1.05rem; box-shadow: var(--shadow-sm); }
.app-header nav { display: flex; gap: var(--sp-1); margin-left: auto; align-items: center; }
.app-header nav a { color: var(--text-soft); font-size: var(--fs-sm); font-weight: 600; padding: .4rem .7rem; border-radius: var(--r-sm); }
.app-header nav a:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
.theme-toggle { display: grid; place-items: center; width: 2.3rem; height: 2.3rem; border-radius: var(--r-sm);
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-soft); }
.theme-toggle:hover { color: var(--text); border-color: var(--border-2); }

/* 언어 토글(🌐) + 드롭다운 */
.lang-wrap { position: relative; display: inline-flex; }
.lang-toggle { display: inline-flex; align-items: center; gap: .3rem; height: 2.3rem; padding: 0 .6rem;
  border-radius: var(--r-sm); background: var(--surface-2); border: 1px solid var(--border); color: var(--text-soft);
  font-size: var(--fs-sm); font-weight: 700; }
.lang-toggle:hover { color: var(--text); border-color: var(--border-2); }
.lang-toggle .lang-code { font-variant: tabular-nums; letter-spacing: .02em; }
.lang-menu { position: absolute; top: calc(100% + .4rem); right: 0; min-width: 8rem; z-index: 60;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); box-shadow: var(--shadow-md);
  padding: .3rem; display: none; flex-direction: column; }
.lang-wrap.open .lang-menu { display: flex; }
.lang-menu button { text-align: left; padding: .5rem .7rem; border-radius: var(--r-sm); border: none; background: none;
  color: var(--text-soft); font-size: var(--fs-sm); font-weight: 600; }
.lang-menu button:hover { background: var(--surface-2); color: var(--text); }
.lang-menu button[aria-current="true"] { color: var(--brand); background: var(--brand-soft); }

/* ---------- 버튼 ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  font-family: var(--font-display); font-weight: 700; font-size: var(--fs-base);
  padding: .7rem 1.2rem; border-radius: var(--r-md); border: 1px solid transparent;
  min-height: 2.75rem; transition: transform .08s ease, box-shadow .15s ease, background .15s ease; }
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--brand-ink); box-shadow: var(--shadow-md); }
.btn-accent { background: var(--accent); color: #1c1400; }
.btn-accent:hover { filter: brightness(.96); }
.btn-ghost { background: var(--surface); border-color: var(--border-2); color: var(--text); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-lg { font-size: var(--fs-lg); padding: .85rem 1.6rem; min-height: 3.25rem; border-radius: var(--r-lg); }
.btn-block { width: 100%; }

/* ---------- 카드/패널 ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm); padding: var(--sp-5); }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-xl);
  box-shadow: var(--shadow-md); padding: var(--sp-6); }

/* 도구/카테고리 카드 */
.tool-card { display: flex; flex-direction: column; gap: var(--sp-2); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--sp-4) var(--sp-5);
  box-shadow: var(--shadow-sm); transition: transform .12s ease, box-shadow .18s ease, border-color .18s ease; }
.tool-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); border-color: var(--border-2); text-decoration: none; }
.tool-card .ico { width: 2.6rem; height: 2.6rem; border-radius: var(--r-md); display: grid; place-items: center;
  font-size: 1.3rem; background: var(--cat, var(--brand-soft)); color: #fff; }
.tool-card h3 { font-size: var(--fs-lg); color: var(--text); }
.tool-card p { font-size: var(--fs-sm); color: var(--text-soft); }

/* 카테고리 색을 카드에 주입: class="cat-games" 등 */
.cat-time   { --cat: var(--cat-time); }
.cat-math   { --cat: var(--cat-math); }
.cat-memory { --cat: var(--cat-memory); }
.cat-react  { --cat: var(--cat-react); }
.cat-games  { --cat: var(--cat-games); }
.cat-music  { --cat: var(--cat-music); }
.cat-geo    { --cat: var(--cat-geo); }
.cat-gen    { --cat: var(--cat-gen); }
.cat-print  { --cat: var(--cat-print); }
.cat-money  { --cat: var(--cat-money); }
.cat-accent-bar { border-top: 3px solid var(--cat, var(--brand)); }

/* ---------- 태그/뱃지/필 ---------- */
.tag { display: inline-flex; align-items: center; gap: .3rem; font-size: var(--fs-xs); font-weight: 700;
  padding: .12rem .5rem; border-radius: var(--r-full); background: var(--surface-2); color: var(--text-soft); }
.tag.soon { background: var(--warn-soft); color: var(--warn); }
.tag.new  { background: var(--good-soft); color: var(--good); }
.badge-cat { display:inline-flex; align-items:center; gap:.35rem; font-size:var(--fs-xs); font-weight:700; color:var(--cat,var(--brand)); }
.badge-cat::before { content:""; width:.55rem; height:.55rem; border-radius:2px; background:var(--cat,var(--brand)); }

/* ---------- 스탯 타일 / 스코어바 (게임 공용) ---------- */
.scorebar { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.stat { flex: 1 1 6rem; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-md);
  padding: .7rem .9rem; text-align: center; }
.stat .val { font-family: var(--font-display); font-weight: 800; font-size: var(--fs-2xl); line-height: 1;
  font-variant-numeric: tabular-nums; color: var(--text); }
.stat .lbl { font-size: var(--fs-xs); color: var(--text-faint); text-transform: uppercase; letter-spacing: .06em; margin-top: .3rem; }

/* 컨트롤 행 / 폼 */
.controls { display: flex; flex-wrap: wrap; gap: var(--sp-2); align-items: center; }
.field { display: inline-flex; flex-direction: column; gap: .25rem; font-size: var(--fs-sm); color: var(--text-soft); }
.select, .input { font: inherit; padding: .55rem .7rem; border-radius: var(--r-sm); border: 1px solid var(--border-2);
  background: var(--surface); color: var(--text); min-height: 2.6rem; }

/* ---------- 광고 슬롯 (AdSense 자리) ---------- */
.ad-slot { position: relative; display: grid; place-items: center; width: 100%;
  min-height: 90px; border: 1px dashed var(--border-2); border-radius: var(--r-md);
  background: repeating-linear-gradient(45deg, var(--surface-2), var(--surface-2) 10px, transparent 10px, transparent 20px);
  color: var(--text-faint); font-size: var(--fs-xs); letter-spacing: .1em; text-transform: uppercase; }
.ad-slot::before { content: "Advertisement"; }
.ad-slot[data-ad] { min-height: var(--ad-h, 90px); }
/* 실제 AdSense <ins> 삽입 시 이 자리표시 스타일은 자동으로 가려짐 */
.ad-slot.live { border: none; background: none; }
.ad-slot.live::before { content: none; }

/* ---------- 게임/앱 레이아웃 헬퍼 ---------- */
.app-main { max-width: 56rem; margin-inline: auto; padding: var(--sp-6) var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-5); }
.app-title { font-size: var(--fs-2xl); }
.app-intro { color: var(--text-soft); max-width: 42rem; }

/* 콘텐츠(정책·소개) 프로즈 */
.prose { max-width: 44rem; }
.prose h2 { font-size: var(--fs-xl); margin: var(--sp-5) 0 var(--sp-2); }
.prose p { margin-bottom: var(--sp-3); color: var(--text-soft); }
.prose ul { margin: 0 0 var(--sp-3) 1.2rem; color: var(--text-soft); }
.prose li { margin-bottom: var(--sp-1); }
.prose a { text-underline-offset: 3px; }
.board-wrap { display: grid; place-items: center; padding: var(--sp-4); background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-xl); box-shadow: var(--shadow-sm); }

/* 결과 모달 (게임 공용) */
.overlay { position: fixed; inset: 0; z-index: 100; display: none; place-items: center; padding: var(--sp-4);
  background: rgba(8,10,15,.55); }
.overlay.open { display: grid; }
.result-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-xl);
  box-shadow: var(--shadow-md); padding: var(--sp-6) var(--sp-5); text-align: center; width: 100%; max-width: 22rem;
  display: grid; gap: var(--sp-4); animation: result-pop .18s ease; }
.result-card .r-emoji { font-size: 3.2rem; line-height: 1; }
.result-card h2 { font-size: var(--fs-2xl); }
.result-card .r-score { color: var(--text-soft); font-variant-numeric: tabular-nums; font-size: var(--fs-lg); }
@keyframes result-pop { from { transform: scale(.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.result-card { max-height: 88dvh; overflow-y: auto; }

/* 순위표 (결과 모달 안) */
.lb { text-align: left; border-top: 1px solid var(--border); padding-top: var(--sp-4); }
.lb-title { font-family: var(--font-display); font-weight: 700; font-size: var(--fs-sm); color: var(--text-faint); text-transform: uppercase; letter-spacing: .06em; margin-bottom: var(--sp-2); }
.lb-list { list-style: none; padding: 0; margin: 0 0 var(--sp-3); display: grid; gap: 2px; }
.lb-list li { display: grid; grid-template-columns: 1.6rem 1fr auto; gap: .5rem; align-items: center; padding: .35rem .5rem; border-radius: var(--r-sm); font-size: var(--fs-sm); }
.lb-list li:nth-child(odd) { background: var(--surface-2); }
.lb-list .lb-rk { color: var(--text-faint); font-variant-numeric: tabular-nums; text-align: center; }
.lb-list .lb-nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-list .lb-sc { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--brand); }
.lb-list .lb-empty, .lb-list .lb-loading { grid-column: 1 / -1; color: var(--text-faint); text-align: center; }
.lb-form { display: flex; gap: var(--sp-2); }
.lb-form .lb-name { flex: 1; min-width: 0; }
.lb-msg { margin-top: var(--sp-2); font-weight: 700; color: var(--good); font-size: var(--fs-sm); min-height: 1.2rem; text-align: center; }

/* ---------- 푸터 ---------- */
.app-footer { border-top: 1px solid var(--border); margin-top: var(--sp-8); background: var(--surface); }
.app-footer .inner { max-width: var(--wrap); margin-inline: auto; padding: var(--sp-6) var(--sp-4);
  display: flex; flex-wrap: wrap; gap: var(--sp-5); justify-content: space-between; }
.app-footer .col h4 { font-size: var(--fs-sm); color: var(--text); margin-bottom: var(--sp-2); }
.app-footer .col a { display: block; font-size: var(--fs-sm); color: var(--text-soft); padding: .2rem 0; }
.app-footer .col a:hover { color: var(--brand); }
.app-footer .copy { width: 100%; border-top: 1px solid var(--border); padding-top: var(--sp-4); margin-top: var(--sp-2);
  font-size: var(--fs-xs); color: var(--text-faint); }

/* ---------- 모션 접근성 ---------- */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
