:root {
  --bg: #f5f6fa;
  --panel: #ffffff;
  --ink: #182033;
  --muted: #71798c;
  --line: #e6e8ef;
  --fairy: #3976ed;
  --fairy-soft: #edf3ff;
  --yomi: #ef5b66;
  --yomi-soft: #fff0f1;
  --today: #fff8e8;
  --radius: 22px;
  --shadow: 0 20px 70px rgba(33, 42, 67, .16);
  font-family: "Malgun Gothic", "Apple SD Gothic Neo", "Noto Sans KR", "Segoe UI", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  background:
    radial-gradient(circle at 12% -10%, rgba(57, 118, 237, .08), transparent 33%),
    radial-gradient(circle at 92% 0%, rgba(239, 91, 102, .07), transparent 30%),
    var(--bg);
  color: var(--ink);
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  word-break: keep-all;
}

button,
input,
textarea {
  font-family: inherit;
  font: inherit;
}

button {
  border: 0;
  color: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(57, 118, 237, .28);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

.app-shell {
  width: min(100%, 1040px);
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  margin: 0 auto;
  padding: max(10px, env(safe-area-inset-top)) 18px max(14px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 9px;
}

.eyebrow,
.sheet-kicker {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  letter-spacing: .03em;
}

.topbar h1,
.login-card h1 {
  margin: 0;
  font-size: clamp(23px, 4.2vw, 29px);
  font-weight: 800;
  letter-spacing: -.035em;
}

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

.profile-button,
.add-button {
  display: grid;
  place-items: center;
  width: 39px;
  height: 39px;
  border-radius: 13px;
  background: var(--panel);
  box-shadow: 0 5px 18px rgba(33, 42, 67, .09);
}

.profile-button {
  font-size: 12px;
  font-weight: 850;
}

.profile-button.fairy {
  background: var(--fairy-soft);
  color: #245bc5;
}

.profile-button.yomi {
  background: var(--yomi-soft);
  color: #c93c48;
}

.add-button {
  background: var(--ink);
  color: #fff;
  font-size: 26px;
  font-weight: 300;
}

.calendar-card {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid rgba(222, 225, 234, .92);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, .93);
  box-shadow: 0 18px 45px rgba(33, 42, 67, .08);
}

.calendar-controls {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
  padding: 6px 14px;
}

.calendar-toolbar {
  display: grid;
  grid-template-columns: 42px auto 42px;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 0;
}

.nav-button {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #fff;
  box-shadow: 0 2px 8px rgba(33, 42, 67, .06);
}

.nav-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.25;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.month-title {
  justify-self: center;
  min-width: 128px;
  padding: 5px 9px;
  border-radius: 12px;
  background: transparent;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -.025em;
}

.filter-row {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-self: start;
  padding: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.filter-row::-webkit-scrollbar {
  display: none;
}

.filter-chip,
.today-button {
  flex: 0 0 auto;
  min-height: 28px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.filter-chip::before {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 5px;
  border-radius: 50%;
  background: #9ba2b1;
  content: "";
}

.filter-chip.fairy::before {
  background: var(--fairy);
}

.filter-chip.yomi::before {
  background: var(--yomi);
}

.filter-chip.both::before {
  background: linear-gradient(90deg, var(--fairy) 50%, var(--yomi) 50%);
}

.filter-chip.is-active {
  border-color: var(--ink);
  background: var(--ink);
  color: #fff;
}

.today-button {
  justify-self: end;
  margin-left: 0;
  color: var(--ink);
}

.weekday-row,
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
}

.calendar-grid {
  flex: 1 1 auto;
  min-height: 0;
  grid-template-rows: repeat(6, minmax(0, 1fr));
  touch-action: pan-y;
  transition: transform .18s ease, opacity .18s ease;
  user-select: none;
  will-change: transform;
}

.calendar-grid.is-dragging {
  transition: none;
}

.weekday-row {
  flex: 0 0 auto;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: #fafbfc;
}

.weekday-row span {
  padding: 6px 0;
  color: var(--muted);
  text-align: center;
  font-size: 14px;
  font-weight: 700;
}

.weekday-row span:first-child {
  color: #db5360;
}

.weekday-row span:last-child {
  color: #3976ed;
}

.day-cell {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  min-width: 0;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  padding: 5px 5px 4px;
  appearance: none;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: #fff;
  text-align: left;
}

.day-cell:nth-child(7n) {
  border-right: 0;
}

.day-cell:nth-last-child(-n + 7) {
  border-bottom: 0;
}

.day-cell.is-outside {
  background: #fafafb;
}

.day-cell.is-today {
  background: var(--today);
}

.day-cell:active {
  background: #f0f3f9;
}

.day-number {
  position: static;
  flex: 0 0 auto;
  align-self: flex-start;
  display: grid;
  place-items: center;
  min-width: 24px;
  height: 24px;
  margin: 0 0 2px 3px;
  padding: 0 4px;
  border-radius: 50%;
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
}

.day-cell.is-outside .day-number {
  color: #b1b6c1;
}

.day-cell.is-today .day-number {
  background: var(--ink);
  color: #fff;
}

.day-cell:nth-child(7n + 1):not(.is-outside) .day-number {
  color: #d94b58;
}

.day-cell:nth-child(7n):not(.is-outside) .day-number {
  color: #2f6ad8;
}

.day-cell.is-today .day-number {
  color: #fff !important;
}

.month-event {
  position: relative;
  display: block;
  width: 100%;
  min-width: 0;
  flex: 0 0 auto;
  margin: 2px 0 0;
  padding: 4px 5px 4px 9px;
  overflow: hidden;
  border-radius: 6px;
  background: #f3f5f8;
  color: #30384c;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.2;
}

.month-event::before {
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  border-radius: 6px 0 0 6px;
  background: var(--fairy);
  content: "";
}

.month-event.yomi {
  background: var(--yomi-soft);
}

.month-event.yomi::before {
  background: var(--yomi);
}

.month-event.fairy {
  background: var(--fairy-soft);
}

.month-event.both {
  background: linear-gradient(90deg, var(--fairy-soft), var(--yomi-soft));
}

.month-event.both::before {
  background: linear-gradient(var(--fairy) 50%, var(--yomi) 50%);
}

.more-count {
  display: block;
  margin: 5px 0 0 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(20, 27, 43, .42);
  backdrop-filter: blur(3px);
}

.bottom-sheet {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 40;
  width: min(100%, 560px);
  max-height: calc(100dvh - 10px);
  margin: 0 auto;
  padding: 5px 14px max(10px, env(safe-area-inset-bottom));
  overflow-y: auto;
  border-radius: 26px 26px 0 0;
  background: #fff;
  box-shadow: var(--shadow);
  animation: sheet-in .22s ease-out;
}

@keyframes sheet-in {
  from { transform: translateY(24px); opacity: .6; }
  to { transform: translateY(0); opacity: 1; }
}

.sheet-handle {
  width: 42px;
  height: 5px;
  margin: 1px auto 8px;
  border-radius: 99px;
  background: #d9dce4;
}

.sheet-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 9px;
}

.sheet-header h2 {
  margin: 0;
  font-size: 20px;
  letter-spacing: -.035em;
}

.close-button {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border-radius: 11px;
  background: #f3f4f7;
  color: #555d6d;
  font-size: 24px;
  line-height: 1;
}

.day-event-list {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.day-event-card {
  position: relative;
  width: 100%;
  padding: 13px 14px 13px 18px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
  text-align: left;
}

.day-event-card::before {
  position: absolute;
  inset: 0 auto 0 0;
  width: 6px;
  background: var(--fairy);
  content: "";
}

.day-event-card.yomi::before {
  background: var(--yomi);
}

.day-event-card.both::before {
  background: linear-gradient(var(--fairy) 50%, var(--yomi) 50%);
}

.event-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.event-time {
  color: var(--ink);
  font-size: 14px;
  font-weight: 900;
}

.owner-label {
  flex: 0 0 auto;
  padding: 4px 7px;
  border-radius: 999px;
  background: var(--fairy-soft);
  color: #245bc5;
  font-size: 10px;
  font-weight: 850;
}

.day-event-card.yomi .owner-label {
  background: var(--yomi-soft);
  color: #c83e49;
}

.day-event-card.both .owner-label {
  background: linear-gradient(90deg, var(--fairy-soft), var(--yomi-soft));
  color: #5a4d75;
}

.event-card-title {
  margin: 6px 0 0;
  font-size: 16px;
  font-weight: 850;
  letter-spacing: -.02em;
}

.event-card-meta {
  display: flex;
  gap: 6px;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.event-card-memo {
  margin: 8px 0 0;
  color: #555e70;
  font-size: 13px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.sheet-action {
  width: 100%;
  margin-top: 14px;
}

.empty-day {
  display: grid;
  justify-items: center;
  gap: 5px;
  padding: 28px 12px;
  color: var(--muted);
  text-align: center;
}

.empty-day strong {
  color: var(--ink);
  font-size: 15px;
}

.empty-day span {
  font-size: 12px;
}

.empty-icon {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  margin-bottom: 4px;
  border-radius: 50%;
  background: #f3f4f7;
  font-size: 18px;
}

.event-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

fieldset {
  margin: 0;
  padding: 0;
  border: 0;
}

legend,
.field > span {
  display: block;
  margin-bottom: 4px;
  color: #4c5568;
  font-size: 12px;
  font-style: normal;
  font-weight: 800;
}

.field em {
  color: #9aa0ad;
  font-size: 10px;
  font-style: normal;
}

.owner-picker {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.owner-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.owner-option span {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: #fff;
  color: #5f6777;
  font-size: 13px;
  font-weight: 850;
}

.owner-option i {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--fairy);
}

.owner-option.yomi i {
  background: var(--yomi);
}

.owner-option.both i {
  background: linear-gradient(90deg, var(--fairy) 50%, var(--yomi) 50%);
}

.owner-option input:checked + span {
  border-color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--ink);
  color: var(--ink);
}

.field-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr;
  gap: 6px;
}

.field input,
.field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: #fafbfc;
  color: var(--ink);
  font-size: 14px;
}

.field input {
  height: 38px;
  padding: 0 10px;
}

.time-control {
  display: flex;
  align-items: center;
  width: 100%;
  height: 38px;
  min-width: 0;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: #fafbfc;
  transition: border-color .16s ease, box-shadow .16s ease;
}

.time-control:focus-within {
  border-color: rgba(57, 118, 237, .7);
  box-shadow: 0 0 0 3px rgba(57, 118, 237, .12);
}

.period-toggle {
  display: flex;
  flex: 0 0 auto;
  gap: 2px;
}

.period-button {
  display: grid;
  place-items: center;
  min-width: 32px;
  height: 30px;
  padding: 0 5px;
  border-radius: 9px;
  background: transparent;
  color: #858c9b;
  font-size: 10px;
  font-weight: 850;
  transition: background .14s ease, color .14s ease, box-shadow .14s ease;
}

.period-button.is-active {
  background: var(--ink);
  box-shadow: 0 3px 9px rgba(24, 32, 51, .18);
  color: #fff;
}

.field .time-control input {
  flex: 1 1 auto;
  width: 0;
  min-width: 64px;
  height: 30px;
  padding: 0 3px 0 6px;
  border: 0;
  border-radius: 0;
  outline: 0;
  background: transparent;
  font-size: 12px;
}

.field .time-control input:focus-visible {
  outline: 0;
}

.field .time-control input::-webkit-calendar-picker-indicator {
  margin: 0;
  padding: 1px;
}

.field textarea {
  min-height: 54px;
  max-height: 70px;
  padding: 8px 10px;
  line-height: 1.45;
  resize: vertical;
}

.form-actions {
  display: flex;
  gap: 7px;
  margin-top: 0;
}

.form-actions .primary-button {
  flex: 1;
}

.primary-button,
.secondary-button,
.danger-button {
  min-height: 40px;
  padding: 0 17px;
  border-radius: 14px;
  font-weight: 850;
}

.primary-button {
  background: var(--ink);
  color: #fff;
}

.secondary-button {
  border: 1px solid var(--line);
  background: #f7f8fa;
  color: var(--ink);
}

.danger-button {
  background: var(--yomi-soft);
  color: #c83844;
}

.form-error {
  min-height: 16px;
  margin: -5px 0 0;
  color: #cc3d49;
  font-size: 12px;
  font-weight: 700;
}

.compact-sheet {
  padding-bottom: max(22px, env(safe-area-inset-bottom));
}

.profile-copy {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 13px;
}

.compact-sheet .secondary-button {
  width: 100%;
}

.loading,
.toast {
  position: fixed;
  z-index: 80;
  right: 18px;
  bottom: max(18px, env(safe-area-inset-bottom));
  padding: 11px 14px;
  border-radius: 13px;
  background: #20283a;
  color: #fff;
  box-shadow: var(--shadow);
  font-size: 12px;
  font-weight: 800;
}

.loading {
  display: flex;
  align-items: center;
  gap: 7px;
}

.loading span {
  width: 13px;
  height: 13px;
  border: 2px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

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

.login-view {
  display: grid;
  min-height: 100vh;
  min-height: 100dvh;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(100%, 390px);
  padding: 34px 28px;
  border: 1px solid rgba(222, 225, 234, .9);
  border-radius: 28px;
  background: rgba(255,255,255,.94);
  box-shadow: 0 24px 70px rgba(33,42,67,.12);
}

.brand-mark {
  display: flex;
  width: 56px;
  height: 56px;
  margin-bottom: 20px;
  overflow: hidden;
  border-radius: 18px;
}

.brand-mark i {
  width: 50%;
  background: var(--fairy);
}

.brand-mark i:last-child {
  background: var(--yomi);
}

.login-copy {
  margin: 12px 0 24px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.login-form label {
  color: #4c5568;
  font-size: 12px;
  font-weight: 800;
}

.login-form input {
  width: 100%;
  height: 52px;
  padding: 0 15px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: #f8f9fb;
  color: var(--ink);
  font-size: 18px;
  letter-spacing: .12em;
}

.login-form .primary-button {
  margin-top: 2px;
}

@media (max-width: 680px) {
  .app-shell {
    padding: max(8px, env(safe-area-inset-top)) 7px max(10px, env(safe-area-inset-bottom));
  }

  .topbar {
    margin: 0 6px 7px;
  }

  .calendar-card {
    border-radius: 18px;
  }

  .calendar-controls {
    grid-template-columns: 1fr auto;
    gap: 4px 7px;
    padding: 5px 9px 6px;
  }

  .calendar-toolbar {
    grid-column: 1 / -1;
    grid-row: 1;
    grid-template-columns: 34px auto 34px;
    gap: 7px;
    padding: 0;
  }

  .nav-button {
    width: 34px;
    height: 34px;
    border-radius: 10px;
  }

  .nav-button svg {
    width: 18px;
    height: 18px;
  }

  .month-title {
    min-width: 116px;
    font-size: 18px;
  }

  .filter-row {
    grid-column: 1;
    grid-row: 2;
    padding: 0;
  }

  .today-button {
    grid-column: 2;
    grid-row: 2;
  }

  .day-number {
    min-width: 21px;
    height: 21px;
    margin: 0 0 1px 1px;
    padding: 0 3px;
    font-size: 12px;
  }

  .month-event {
    margin-top: 2px;
    padding: 3px 2px 3px 6px;
    border-radius: 4px;
    font-size: 10px;
    line-height: 1.15;
  }

  .day-number + .month-event {
    margin-top: 1px;
  }

  .month-event::before {
    width: 3px;
  }

  .more-count {
    margin: 3px 0 0 5px;
    font-size: 9px;
  }

  .field-grid {
    grid-template-columns: 1fr 1fr;
  }

  .field-grid .field:first-child {
    grid-column: 1 / -1;
  }

  .period-button {
    min-width: 30px;
    padding: 0 4px;
  }

  .field .time-control input {
    min-width: 58px;
    padding-left: 4px;
    font-size: 11px;
  }
}

@media (max-width: 370px) {
  .filter-chip,
  .today-button {
    padding: 0 8px;
  }

  .month-event {
    font-size: 9px;
  }
}

@media (min-width: 760px) {
  .bottom-sheet {
    right: 10px;
    bottom: 10px;
    left: auto;
    max-height: calc(100dvh - 20px);
    border-radius: 26px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
  }
}
