/* =============================================
   TickDate - Styles
   ============================================= */

:root {
  --primary: #5B8DEF;
  --primary-dark: #3E6FD8;
  --primary-bg: #EAF1FF;
  --accent: #FF8A65;
  --success: #34C38F;
  --success-bg: #E3F8EF;
  --warn: #FF6B6B;
  --sun: #F0616D;
  --sat: #4C8DF6;
  --bg: #F5F7FF;
  --surface: #FFFFFF;
  --text: #253053;
  --text-2: #6B7593;
  --border: #E3E8F5;
  --hour: #2B3A67;
  --minute: #FF8A65;
  --radius: 20px;
  --radius-sm: 12px;
  --shadow: 0 2px 10px rgba(43, 58, 103, 0.08);
  --shadow-lg: 0 12px 40px rgba(43, 58, 103, 0.2);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

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

body {
  font-family: 'Nunito', -apple-system, BlinkMacSystemFont, 'Apple SD Gothic Neo', 'Malgun Gothic', 'Segoe UI', Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
button:disabled { cursor: default; }
[hidden] { display: none !important; }

/* ── 공통 컴포넌트 ── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 14px;
}
.card-label {
  font-size: 13px;
  font-weight: 800;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin: 4px 0 10px;
}

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 52px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 17px;
  transition: transform .1s, background .2s;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 6px 16px rgba(91, 141, 239, .35); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: var(--primary-bg); color: var(--primary-dark); }

.segmented {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--bg);
  border-radius: 999px;
}
.seg-item {
  flex: 1;
  min-height: 40px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 14px;
  color: var(--text-2);
  transition: background .15s, color .15s;
}
.seg-item.is-active { background: var(--surface); color: var(--primary-dark); box-shadow: var(--shadow); }

/* ── 시작 화면 ── */
.home {
  max-width: 480px;
  margin: 0 auto;
  padding: max(24px, env(safe-area-inset-top)) 16px 32px;
}
.home-hero { text-align: center; margin: 12px 0 20px; }
.home-logo { margin: 0 auto 6px; animation: bob 3s ease-in-out infinite; }
.home-title { font-size: 38px; font-weight: 900; letter-spacing: -.02em; color: var(--hour); }
.home-tagline { color: var(--text-2); font-weight: 600; }

.mode-list { display: grid; gap: 8px; margin-bottom: 16px; }
.mode-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border);
  text-align: left;
  transition: border-color .15s, background .15s;
}
.mode-item.is-active { border-color: var(--primary); background: var(--primary-bg); }
.mode-text { display: flex; flex-direction: column; }
.mode-text strong { font-size: 16px; }
.mode-text small { color: var(--text-2); font-size: 13px; }
.mode-icon {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-size: 20px;
}
.mode-icon--classic { background: #EAF1FF; }
.mode-icon--classic::before { content: '🕒'; }
.mode-icon--timeattack { background: #FFEDE6; }
.mode-icon--timeattack::before { content: '⚡'; }
.mode-icon--daily { background: #E3F8EF; }
.mode-icon--daily::before { content: '📅'; }

.diff-desc { text-align: center; color: var(--text-2); font-size: 13px; margin: 8px 0 4px; }

.best-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 4px;
  margin: 8px 0 14px;
  border-top: 1px dashed var(--border);
}
.best-label { font-weight: 800; color: var(--text-2); }
.best-value { font-weight: 800; }
.btn-play { font-size: 20px; min-height: 58px; }

.howto summary { font-weight: 800; cursor: pointer; }
.howto ol { margin: 10px 0 0 20px; color: var(--text-2); }
.howto li { margin: 4px 0; }

.toggle {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 46px;
  font-weight: 700;
  cursor: pointer;
}
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle i {
  position: relative;
  width: 48px;
  height: 28px;
  border-radius: 999px;
  background: var(--border);
  transition: background .2s;
}
.toggle i::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .2);
  transition: transform .2s;
}
.toggle input:checked + i { background: var(--success); }
.toggle input:checked + i::after { transform: translateX(20px); }
.toggle input:focus-visible + i { outline: 2px solid var(--primary); outline-offset: 2px; }
.lang-switch { display: flex; gap: 6px; }
.lang-switch a { padding: 6px 12px; border-radius: 999px; background: var(--bg); font-size: 14px; }
.lang-switch a.is-active { background: var(--primary); color: #fff; }

.home-footer { text-align: center; font-size: 13px; color: var(--text-2); margin-top: 8px; }
.home-footer a { text-decoration: underline; }

.doc h1 { font-size: 22px; margin: 8px 0; }
.doc h2 { font-size: 16px; margin: 16px 0 4px; }
.doc p { margin: 6px 0; color: var(--text-2); }
.doc hr { border: 0; border-top: 1px solid var(--border); margin: 24px 0; }

.error-card { text-align: center; margin-top: 20vh; }
.error-code { font-size: 56px; font-weight: 900; color: var(--primary); }
.error-card p { margin-bottom: 16px; color: var(--text-2); }

/* ── 게임 화면 ── */
body.is-game { overflow: hidden; overscroll-behavior: none; }

.game {
  --cell: clamp(30px, min(calc((100vw - 40px) / 7), 5.4dvh), 50px);
  --clock: clamp(160px, min(72vw, 36dvh), 340px);
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 520px;
  margin: 0 auto;
  padding: max(8px, env(safe-area-inset-top)) 12px max(8px, env(safe-area-inset-bottom));
  gap: 8px;
  user-select: none;
  -webkit-user-select: none;
}

.hud { display: flex; align-items: center; gap: 6px; }
.hud-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.1;
}
.hud-item small { font-size: 11px; font-weight: 700; color: var(--text-2); }
.hud-item strong { font-size: 18px; font-weight: 900; font-variant-numeric: tabular-nums; }
.hud-timer strong { font-size: 22px; }
.hud-timer.is-warn strong { color: var(--warn); animation: pulse 1s infinite; }
.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--surface);
  box-shadow: var(--shadow);
  fill: var(--text-2);
}
.pill-btn {
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 13px;
  font-weight: 800;
  color: var(--text-2);
}

.target {
  position: relative;
  background: var(--hour);
  color: #fff;
  border-radius: var(--radius);
  padding: 8px 12px 10px;
  text-align: center;
}
.target.is-new { animation: popIn .3s ease-out; }
.target-label { font-size: 11px; font-weight: 800; opacity: .7; text-transform: uppercase; letter-spacing: .08em; }
.target-parts { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin-top: 2px; }
.target-part {
  font-size: clamp(16px, 4.6vw, 21px);
  font-weight: 900;
  padding: 2px 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, .12);
  transition: background .2s, color .2s;
}
.target-part.is-match { background: var(--success); }
.target-part.is-match::after { content: ' ✓'; }
.combo-badge {
  position: absolute;
  top: -8px;
  right: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 900;
  font-size: 13px;
  padding: 2px 10px;
  border-radius: 999px;
}
.combo-badge.is-pop { animation: popIn .35s ease-out; }

.board {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-evenly;
  gap: 8px;
}
.is-locked .board { pointer-events: none; }

/* 달력 */
.cal {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 6px 8px 8px;
}
.cal-head { display: flex; align-items: center; justify-content: space-between; }
.cal-nav {
  width: 44px;
  height: 40px;
  font-size: 28px;
  line-height: 1;
  border-radius: 12px;
  color: var(--primary-dark);
}
.cal-nav:active { background: var(--primary-bg); }
.cal-nav:disabled { opacity: .2; }
.cal-title {
  flex: 1;
  height: 40px;
  font-weight: 900;
  font-size: 17px;
  border-radius: 12px;
}
.cal-title:active { background: var(--primary-bg); }
.cal-week, .cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); }
.cal-week span { text-align: center; font-size: 11px; font-weight: 800; color: var(--text-2); }
.cal-week [data-wd="0"] { color: var(--sun); }
.cal-week [data-wd="6"] { color: var(--sat); }
.cal-grid { grid-auto-rows: var(--cell); gap: 2px; }
.cal-day {
  border-radius: 50%;
  font-weight: 700;
  font-size: calc(var(--cell) * .38);
  width: var(--cell);
  height: var(--cell);
  justify-self: center;
  transition: background .1s, transform .1s;
}
.cal-day.is-sun { color: var(--sun); }
.cal-day.is-sat { color: var(--sat); }
.cal-day:not(:disabled):active { transform: scale(.9); background: var(--primary-bg); }
.cal-day.is-today { box-shadow: inset 0 0 0 2px var(--border); }
.cal-day.is-selected { background: var(--primary); color: #fff; box-shadow: 0 3px 8px rgba(91, 141, 239, .4); }

.cal-picker {
  position: absolute;
  inset: 46px 8px 8px;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 2;
}
.picker-years {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 2px 0 6px;
  scrollbar-width: thin;
}
.picker-years button { flex: none; padding: 8px 12px; border-radius: 999px; background: var(--bg); font-weight: 800; }
.picker-months { flex: 1; display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.picker-months button { border-radius: 12px; background: var(--bg); font-weight: 800; }
.picker-years .is-active, .picker-months .is-active { background: var(--primary); color: #fff; }

/* 시계 */
.clock-area { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.clock { width: var(--clock); height: var(--clock); touch-action: none; }
.clock-svg { width: 100%; height: 100%; display: block; overflow: visible; cursor: pointer; }
.clock-face { fill: var(--surface); stroke: var(--border); stroke-width: 3; filter: drop-shadow(0 4px 10px rgba(43, 58, 103, .12)); }
.tick { stroke: #C9D1E6; stroke-width: 1; }
.tick--major { stroke: var(--text-2); stroke-width: 2.5; stroke-linecap: round; }
.clock-nums text { font-size: 15px; font-weight: 800; fill: var(--text); }
.clock-readout { font-size: 13px; font-weight: 800; fill: var(--text-2); }
.hand { stroke-linecap: round; transition: stroke-width .1s; }
.hand--hour { stroke: var(--hour); stroke-width: 8; }
.hand--minute { stroke: var(--minute); stroke-width: 5; }
.is-drag-hour .hand--hour { stroke-width: 11; }
.is-drag-minute .hand--minute { stroke-width: 7.5; }
.clock-pin { fill: var(--hour); stroke: #fff; stroke-width: 2.5; }

.clock-controls { display: flex; align-items: center; gap: 10px; width: min(100%, 320px); }
.clock-controls .segmented { flex: 1; background: var(--surface); box-shadow: var(--shadow); }
.clock-controls .seg-item.is-active { background: var(--hour); color: #fff; }
.round-btn {
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 24px;
  font-weight: 800;
  color: var(--primary-dark);
}
.round-btn:active { transform: scale(.92); }

/* 오버레이 */
.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 10;
  padding: 16px;
}
.overlay--dim { background: rgba(37, 48, 83, .45); backdrop-filter: blur(3px); }
.countdown {
  font-size: 120px;
  font-weight: 900;
  color: var(--primary);
  text-shadow: 0 6px 24px rgba(91, 141, 239, .4);
}
.countdown.is-pop { animation: countPop .9s ease-out; }
#countdownOverlay { background: rgba(245, 247, 255, .75); }

.flash { position: fixed; inset: 0; display: grid; place-items: center; pointer-events: none; z-index: 9; }
.flash-badge {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--success);
  color: #fff;
  padding: 14px 30px;
  border-radius: 24px;
  font-size: 28px;
  font-weight: 900;
  box-shadow: var(--shadow-lg);
}
.flash-badge small { font-size: 16px; opacity: .9; }
.flash.is-anim .flash-badge { animation: correctPop .65s ease-out forwards; }
.is-correct .target { background: var(--success); transition: background .15s; }

.sheet {
  width: min(100%, 380px);
  background: var(--surface);
  border-radius: 28px;
  padding: 24px 20px;
  box-shadow: var(--shadow-lg);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 10px;
  animation: popIn .25s ease-out;
}
.sheet h2 { font-size: 22px; font-weight: 900; }
.result-mode { color: var(--text-2); font-weight: 700; margin-top: -8px; }
.result-score { font-size: 56px; font-weight: 900; color: var(--primary); line-height: 1.1; }
.new-best {
  align-self: center;
  background: var(--accent);
  color: #fff;
  font-weight: 900;
  padding: 2px 14px;
  border-radius: 999px;
  animation: pulse 1.2s infinite;
}
.result-stats { display: grid; gap: 2px; margin: 4px 0 6px; }
.result-stats div { display: flex; justify-content: space-between; padding: 6px 4px; border-bottom: 1px dashed var(--border); }
.result-stats dt { color: var(--text-2); font-weight: 700; }
.result-stats dd { font-weight: 900; font-variant-numeric: tabular-nums; }
.result-actions { display: grid; gap: 8px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translateX(-50%);
  background: var(--hour);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-weight: 700;
  z-index: 20;
}

/* 가로 화면/태블릿: 달력과 시계를 나란히 */
@media (min-aspect-ratio: 4/3) and (min-width: 600px) {
  .game {
    --cell: clamp(30px, min(calc((50vw - 60px) / 7), 7dvh), 56px);
    --clock: clamp(180px, min(42vw, 58dvh), 420px);
    max-width: 1000px;
  }
  .board { flex-direction: row; align-items: center; }
  .cal { flex: 1; }
  .clock-area { flex: 1; }
}

/* 아주 낮은 화면 */
@media (max-height: 640px) {
  .target { padding: 4px 10px 6px; }
  .cal-head { margin-bottom: -2px; }
  .cal-nav, .cal-title { height: 34px; }
}

@keyframes bob { 50% { transform: translateY(-6px) rotate(-3deg); } }
@keyframes pulse { 50% { opacity: .55; } }
@keyframes popIn { from { transform: scale(.92); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes countPop { 0% { transform: scale(1.6); opacity: 0; } 30% { transform: scale(1); opacity: 1; } 100% { transform: scale(.85); opacity: .6; } }
@keyframes correctPop {
  0% { transform: scale(.5); opacity: 0; }
  30% { transform: scale(1.1); opacity: 1; }
  70% { transform: scale(1); opacity: 1; }
  100% { transform: scale(1) translateY(-20px); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
