/* ===== Reset & base ===== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  overscroll-behavior-y: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN",
               "Noto Sans JP", "Yu Gothic", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  touch-action: manipulation;
  transition: background .35s ease, color .35s ease;
}

button {
  font-family: inherit;
  border: none;
  background: none;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

/* ===== Theme tokens =====
   Each theme defines: --bg, --surface, --surface-2, --text, --text-dim,
   --accent, --accent-text, --border
   Sat / Sun-holiday colors stay fixed per spec (blue / red) but each theme
   supplies its own shade so it still harmonizes.
*/

body[data-theme="graphite"] {
  --bg: #0b0b0d;
  --surface: #17171a;
  --surface-2: #1f1f23;
  --text: #f2f2f0;
  --text-dim: #8b8b93;
  --accent: #3ddc97;
  --accent-text: #06140e;
  --border: #2a2a2f;
  --sat: #4a9eff;
  --sun: #ff5c5c;
}

body[data-theme="ember"] {
  --bg: #0e0b0a;
  --surface: #1a1512;
  --surface-2: #241d18;
  --text: #f5efe9;
  --text-dim: #9a8b80;
  --accent: #ff6b4a;
  --accent-text: #200a04;
  --border: #2e241d;
  --sat: #5b9fe6;
  --sun: #ff5c5c;
}

body[data-theme="ultraviolet"] {
  --bg: #0b0a0f;
  --surface: #16141c;
  --surface-2: #1e1b26;
  --text: #f1eefb;
  --text-dim: #948da8;
  --accent: #a78bfa;
  --accent-text: #150c2e;
  --border: #292437;
  --sat: #6ea8ff;
  --sun: #ff6188;
}

body[data-theme="citrus"] {
  --bg: #0b0c08;
  --surface: #171911;
  --surface-2: #1f2216;
  --text: #f3f5e9;
  --text-dim: #94997f;
  --accent: #d4e157;
  --accent-text: #191d05;
  --border: #282c1b;
  --sat: #55b6d6;
  --sun: #ff6b5c;
}

body[data-theme="rose"] {
  --bg: #0e0a0c;
  --surface: #1a1216;
  --surface-2: #24191e;
  --text: #f6eef1;
  --text-dim: #a38993;
  --accent: #ff6fa5;
  --accent-text: #250811;
  --border: #2e1e25;
  --sat: #5aa4ff;
  --sun: #ff5c5c;
}

body[data-theme="ice"] {
  --bg: #08090c;
  --surface: #131720;
  --surface-2: #1a2029;
  --text: #eef3f8;
  --text-dim: #85919f;
  --accent: #5bc8ff;
  --accent-text: #041826;
  --border: #202834;
  --sat: #5bc8ff;
  --sun: #ff6a6a;
}

/* ===== Layout ===== */
.app {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100vh;
  padding: env(safe-area-inset-top, 0) 16px calc(env(safe-area-inset-bottom, 0) + 24px);
  display: flex;
  flex-direction: column;
}

/* ===== Top bar ===== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 2px 8px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
}

.brand-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 12px 1px color-mix(in srgb, var(--accent) 70%, transparent);
}

.brand h1 {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.icon-btn {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  color: var(--text-dim);
  transition: background .2s ease, color .2s ease;
}
.icon-btn:active {
  background: var(--surface-2);
  color: var(--text);
}

/* ===== Theme panel ===== */
.theme-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px;
  margin: 4px 2px 4px;
  animation: dropIn .18s ease;
}

.theme-panel-title {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 10px;
  letter-spacing: 0.02em;
}

.theme-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
}

.theme-swatch {
  aspect-ratio: 1;
  border-radius: 12px;
  border: 2px solid transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  min-height: 44px;
}

.theme-swatch.active {
  border-color: var(--text);
}

.theme-swatch .dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
}

@keyframes dropIn {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== Month nav ===== */
.month-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 14px;
  padding: 0 2px;
}

.nav-btn {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  transition: background .15s ease, color .15s ease, transform .1s ease;
}
.nav-btn:active {
  background: var(--surface-2);
  color: var(--text);
  transform: scale(0.94);
}

.month-label {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.01em;
  padding: 8px 16px;
  border-radius: 12px;
}
.month-label:active {
  background: var(--surface-2);
}
.month-label span#yearText {
  color: var(--text-dim);
  font-weight: 500;
  font-size: 16px;
  margin-right: 2px;
}

/* ===== Month picker ===== */
.month-picker {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px;
  margin-top: 10px;
  animation: dropIn .18s ease;
}

.picker-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 22px;
  margin-bottom: 12px;
}

.picker-year {
  font-size: 17px;
  font-weight: 700;
  min-width: 64px;
  text-align: center;
}

.picker-year-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  font-size: 20px;
  color: var(--text-dim);
}
.picker-year-btn:active {
  background: var(--surface-2);
  color: var(--text);
}

.picker-months {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.picker-month-btn {
  padding: 12px 0;
  border-radius: 10px;
  background: var(--surface-2);
  font-size: 14px;
  color: var(--text-dim);
  font-weight: 600;
}
.picker-month-btn.active {
  background: var(--accent);
  color: var(--accent-text);
}
.picker-month-btn:active {
  transform: scale(0.96);
}

.picker-today {
  width: 100%;
  margin-top: 10px;
  padding: 10px 0;
  text-align: center;
  border-radius: 10px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  background: var(--surface-2);
}

/* ===== Calendar ===== */
.calendar-wrap {
  margin-top: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 14px 8px 6px;
}

.weekday-row {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  margin-bottom: 6px;
}

.wd {
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  padding-bottom: 6px;
}
.wd.sun { color: var(--sun); }
.wd.sat { color: var(--sat); }

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-auto-rows: minmax(46px, auto);
}

.day-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.day-btn {
  width: 100%;
  height: 100%;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  position: relative;
  font-size: 14.5px;
  font-weight: 500;
  color: var(--text);
  transition: background .12s ease, transform .1s ease;
}

.day-btn:active {
  transform: scale(0.92);
}

.day-btn .num {
  position: relative;
  z-index: 2;
}

.day-btn .mark {
  position: absolute;
  inset: 5px;
  border-radius: 50%;
  z-index: 1;
  opacity: 0;
  transform: scale(0.7);
  transition: opacity .15s ease, transform .15s ease;
}

.day-btn.marked .mark {
  opacity: 0.28;
  transform: scale(1);
}
.day-btn.marked {
  font-weight: 700;
}

.day-btn.marked.type-normal .mark { background: var(--accent); }
.day-btn.marked.type-sat .mark { background: var(--sat); }
.day-btn.marked.type-sun .mark { background: var(--sun); }

.day-btn.type-sat .num { color: var(--sat); }
.day-btn.type-sun .num { color: var(--sun); }

.day-btn.today .num::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -7px;
  transform: translateX(-50%);
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--text-dim);
}
.day-btn.today { color: var(--text); }

.day-cell.empty { pointer-events: none; }

.holiday-name {
  position: absolute;
  bottom: 1px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 8px;
  color: var(--sun);
  opacity: 0.85;
  white-space: nowrap;
  z-index: 2;
  max-width: 95%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hint {
  text-align: center;
  font-size: 11.5px;
  color: var(--text-dim);
  padding: 10px 0 6px;
}

/* ===== Results ===== */
.results {
  margin-top: 18px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.result-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.result-info {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.result-label {
  font-size: 11.5px;
  color: var(--text-dim);
  font-weight: 600;
  line-height: 1.3;
}

.result-value {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.copy-btn {
  width: 38px;
  height: 38px;
  min-width: 38px;
  border-radius: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  background: var(--surface-2);
  transition: background .15s ease, color .15s ease, transform .1s ease;
}
.copy-btn:active {
  background: var(--accent);
  color: var(--accent-text);
  transform: scale(0.92);
}

/* ===== Reset button ===== */
.reset-btn {
  margin-top: 16px;
  width: 100%;
  padding: 14px 0;
  text-align: center;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 600;
}
.reset-btn:active {
  background: var(--surface-2);
  color: var(--text);
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 16px);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 11px 18px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 50;
  box-shadow: 0 8px 30px rgba(0,0,0,0.4);
}
.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ===== Small screens ===== */
@media (max-width: 360px) {
  .result-value { font-size: 22px; }
  .theme-grid { grid-template-columns: repeat(3, 1fr); }
}
