:root {
  --bg: #F3F7FC;
  --surface: #FFFFFF;
  --surface-2: #EEF3FA;
  --border: #E1E8F2;
  --text: #1E2A3A;
  --text-muted: #6B7A8D;
  --blue: #3B7DDE;
  --blue-soft: #E7F0FD;
  --orange: #FF7A45;
  --orange-soft: #FFE9DE;
  --good: #1FA971;
  --good-soft: #E1F6EC;
  --critical: #E5484D;
  --critical-soft: #FBE6E7;
  --shadow: 0 2px 10px rgba(30, 60, 110, 0.07);
  --shadow-lift: 0 18px 44px rgba(30, 60, 110, 0.20);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0F1620;
    --surface: #161F2C;
    --surface-2: #1D2734;
    --border: #2B3544;
    --text: #E7EDF6;
    --text-muted: #8D9AAC;
    --blue: #6FA3F2;
    --blue-soft: rgba(111, 163, 242, 0.16);
    --orange: #FF9466;
    --orange-soft: rgba(255, 148, 102, 0.16);
    --good: #3FCB92;
    --good-soft: rgba(63, 203, 146, 0.16);
    --critical: #F1696D;
    --critical-soft: rgba(241, 105, 109, 0.16);
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    --shadow-lift: 0 22px 50px rgba(0, 0, 0, 0.55);
  }
}

:root[data-theme="dark"] {
  --bg: #0F1620;
  --surface: #161F2C;
  --surface-2: #1D2734;
  --border: #2B3544;
  --text: #E7EDF6;
  --text-muted: #8D9AAC;
  --blue: #6FA3F2;
  --blue-soft: rgba(111, 163, 242, 0.16);
  --orange: #FF9466;
  --orange-soft: rgba(255, 148, 102, 0.16);
  --good: #3FCB92;
  --good-soft: rgba(63, 203, 146, 0.16);
  --critical: #F1696D;
  --critical-soft: rgba(241, 105, 109, 0.16);
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
  --shadow-lift: 0 22px 50px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: "M PLUS Rounded 1c", "Hiragino Maru Gothic ProN", "Yu Gothic", sans-serif;
  margin: 0;
  display: flex;
  min-height: 100vh;
}

.mono { font-variant-numeric: tabular-nums; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: 216px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 4px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 11px;
  background: linear-gradient(135deg, var(--blue), #6FA3F2);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: var(--shadow);
}

.brand-mark svg { width: 19px; height: 19px; }

.brand-name {
  font-weight: 800;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
}

.brand-name .e { color: var(--blue); }

nav { display: flex; flex-direction: column; gap: 4px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--text-muted);
}

.nav-item.active {
  background: var(--blue-soft);
  color: var(--blue);
}

.nav-item .ic { width: 17px; text-align: center; }

.punch-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.punch-status {
  font-size: 0.68rem;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.5;
}

.sidebar-foot {
  margin-top: auto;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 12px;
  background: var(--surface-2);
  border-radius: 12px;
  font-size: 0.72rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.sidebar-foot .user-name { font-weight: 700; color: var(--text); font-size: 0.82rem; }

.sidebar-foot a {
  color: var(--blue);
  font-weight: 700;
  text-decoration: none;
}

.sidebar-foot a:hover { text-decoration: underline; }

/* ---------- Main ---------- */
main {
  flex: 1;
  padding: 32px clamp(20px, 4vw, 44px) 60px;
  max-width: 760px;
}

.greeting h1 {
  font-size: 1.4rem;
  font-weight: 800;
  margin: 0 0 4px;
  text-wrap: balance;
}

.greeting p {
  margin: 0 0 22px;
  color: var(--text-muted);
  font-size: 0.86rem;
}

/* Clock card */
.clock-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 26px 30px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 14px;
}

.clock-time {
  font-size: clamp(2.6rem, 7vw, 3.6rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1;
  color: var(--text);
}

.clock-date {
  margin-top: 8px;
  color: var(--text-muted);
  font-size: 0.86rem;
  font-weight: 500;
}

.clock-badge {
  width: 68px;
  height: 68px;
  border-radius: 20px;
  background: var(--blue-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.clock-badge svg { width: 32px; height: 32px; }

/* Next alarm strip */
.next-strip {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
  font-size: 0.86rem;
}

.next-strip .tag {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--good);
  background: var(--good-soft);
  padding: 3px 10px;
  border-radius: 999px;
  flex-shrink: 0;
}

.next-strip strong { font-weight: 800; }
.next-strip .dim { color: var(--text-muted); }

/* Sound card */
.sound-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 16px 20px;
  margin-bottom: 24px;
}

.sound-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.sound-title { font-size: 0.72rem; font-weight: 700; color: var(--text-muted); margin-bottom: 2px; }
.sound-current { font-size: 0.92rem; font-weight: 700; }
.sound-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.sound-note { margin: 10px 0 0; font-size: 0.7rem; color: var(--text-muted); line-height: 1.5; }

/* Alarm list card */
.list-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 22px 14px;
  flex-wrap: wrap;
  gap: 10px;
}

.list-head h2 {
  font-size: 1rem;
  font-weight: 800;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.list-head .count {
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--text-muted);
  background: var(--surface-2);
  padding: 2px 9px;
  border-radius: 999px;
}

.head-actions { display: flex; gap: 8px; }

.btn {
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  border: none;
  border-radius: 999px;
  padding: 9px 16px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: transform 0.1s, box-shadow 0.15s, background 0.15s;
  text-decoration: none;
}

.btn:active { transform: scale(0.97); }
.btn:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

.btn-primary { background: var(--orange); color: #fff; box-shadow: 0 6px 16px rgba(255, 122, 69, 0.32); }
.btn-primary:hover { box-shadow: 0 8px 20px rgba(255, 122, 69, 0.4); }

.btn-ghost { background: var(--surface-2); color: var(--text-muted); }
.btn-ghost:hover { color: var(--text); }

.btn-block { background: var(--blue); color: #fff; width: 100%; justify-content: center; padding: 11px; }

.sample-note {
  padding: 0 22px 12px;
  margin: 0;
  font-size: 0.74rem;
  color: var(--text-muted);
}

/* Add-alarm form */
.add-form {
  padding: 4px 22px 20px;
  border-bottom: 1px solid var(--border);
  display: none;
}

.add-form.open { display: block; }

.field-row { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 12px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 0.72rem; font-weight: 700; color: var(--text-muted); }

.field input[type="time"],
.field input[type="text"],
.field input[type="password"] {
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  width: 100%;
}

.field input:focus-visible { outline: 2px solid var(--blue); outline-offset: 1px; }
.field input[type="text"] { font-weight: 500; min-width: 220px; }

.day-picker { display: flex; gap: 6px; margin-bottom: 16px; }

.day-chip {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 0.76rem;
  font-weight: 700;
  cursor: pointer;
}

.day-chip.active { background: var(--blue); border-color: var(--blue); color: #fff; }

.form-actions { display: flex; gap: 10px; }

/* Alarm rows */
.alarm-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 22px;
  border-top: 1px solid var(--border);
}

.alarm-row.disabled .alarm-time,
.alarm-row.disabled .alarm-label { opacity: 0.42; }

.alarm-time { font-size: 1.7rem; font-weight: 800; min-width: 92px; }

.alarm-mid { flex: 1; min-width: 0; }

.alarm-label { font-size: 0.86rem; font-weight: 700; margin-bottom: 4px; }

.day-row { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }

.day-dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.62rem;
  font-weight: 700;
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.day-dot.on { background: var(--blue-soft); color: var(--blue); border-color: transparent; }

.every-day { font-size: 0.74rem; color: var(--text-muted); font-weight: 500; }

.alarm-actions { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }

.switch {
  width: 44px;
  height: 26px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  position: relative;
  cursor: pointer;
  flex-shrink: 0;
}

.switch.on { background: var(--blue); border-color: var(--blue); }

.switch .knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: left 0.15s;
}

.switch.on .knob { left: 20px; }

.icon-btn {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:hover { background: var(--surface-2); color: var(--critical); }

.empty-state {
  padding: 36px 22px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.86rem;
}

/* Ringing overlay */
.ring-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 22, 32, 0.55);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}

.ring-overlay.show { display: flex; }

.ring-card {
  background: var(--surface);
  border-radius: 24px;
  padding: 36px 34px;
  max-width: 340px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow-lift);
}

.ring-bell {
  width: 64px;
  height: 64px;
  margin: 0 auto 14px;
  border-radius: 50%;
  background: var(--orange-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: ring-pulse 1s ease-in-out infinite;
}

.ring-bell svg { width: 30px; height: 30px; }

@keyframes ring-pulse {
  0%, 100% { transform: rotate(0deg) scale(1); }
  20% { transform: rotate(-12deg) scale(1.04); }
  40% { transform: rotate(10deg) scale(1.04); }
  60% { transform: rotate(-8deg) scale(1.02); }
  80% { transform: rotate(6deg) scale(1.02); }
}

.ring-time { font-size: 2.2rem; font-weight: 800; margin-bottom: 4px; }
.ring-label { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 22px; }

.ring-actions { display: flex; gap: 10px; }
.ring-actions .btn { flex: 1; padding: 12px; font-size: 0.86rem; }

/* ---------- Login / setup pages ---------- */
.login-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  width: 100%;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 32px 30px;
  max-width: 360px;
  width: 100%;
}

.login-card .brand { margin-bottom: 18px; }

.login-card h1 {
  font-size: 1.2rem;
  font-weight: 800;
  margin: 0 0 6px;
}

.login-card .setup-note {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: 0 0 18px;
  line-height: 1.6;
}

.login-card form .field { margin-bottom: 14px; }

.login-error {
  background: var(--critical-soft);
  color: var(--critical);
  font-size: 0.8rem;
  font-weight: 700;
  padding: 10px 12px;
  border-radius: 10px;
  margin: 0 0 16px;
}

.login-card code {
  background: var(--surface-2);
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 0.85em;
}

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  body { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; align-items: center; padding: 14px 18px; }
  .sidebar-foot { display: none; }
  nav { flex-direction: row; }
  main { padding: 24px 18px 48px; }
  .clock-card { flex-direction: column; align-items: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
  .ring-bell { animation: none; }
  .btn, .switch .knob { transition: none; }
}
