:root {
  --bg: #f2f3f8;
  --card: #ffffff;
  --text: #1d2130;
  --text-sub: #6b7186;
  --line: #e7e9f2;
  --primary: #5b5bd6;
  --primary-soft: #eceafd;
  --danger: #e5484d;
  --ok: #30a46c;
  --shadow: 0 1px 3px rgba(24, 28, 50, .07), 0 8px 24px rgba(24, 28, 50, .05);
  --radius: 16px;
  --tabbar-h: 62px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161f;
    --card: #1e2130;
    --text: #eceef6;
    --text-sub: #9aa0b5;
    --line: #2c3044;
    --primary: #7b7bec;
    --primary-soft: #2b2b4a;
    --shadow: 0 1px 3px rgba(0, 0, 0, .35);
  }
}

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

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

body {
  font-family: "Pretendard", -apple-system, BlinkMacSystemFont, "Segoe UI", "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 12px);
}

/* ───────── header ───────── */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 18px 10px;
  max-width: 1080px;
  margin: 0 auto;
}
.app-header h1 { font-size: 1.25rem; letter-spacing: -.02em; }
.app-header p { color: var(--text-sub); font-size: .8rem; }

/* ───────── layout ───────── */
main { max-width: 1080px; margin: 0 auto; padding: 0 14px; }
.view { display: none; flex-direction: column; gap: 14px; }
.view.active { display: flex; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.card h2 { font-size: 1rem; margin-bottom: 10px; letter-spacing: -.01em; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card-head h2 { margin-bottom: 10px; }

.badge {
  background: var(--primary-soft);
  color: var(--primary);
  font-size: .74rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 99px;
  white-space: nowrap;
}

.hint { color: var(--text-sub); font-size: .8rem; margin-bottom: 10px; }

/* ───────── buttons ───────── */
.btn {
  font: inherit;
  font-size: .88rem;
  font-weight: 600;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 12px;
  cursor: pointer;
  transition: transform .06s, filter .15s;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.btn-block { width: 100%; margin-top: 4px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.btn-sm { padding: 6px 12px; font-size: .78rem; border-radius: 9px; }

/* ───────── forms ───────── */
.form { display: flex; flex-direction: column; gap: 12px; }
.form label {
  display: flex; flex-direction: column; gap: 5px;
  font-size: .8rem; font-weight: 600; color: var(--text-sub); flex: 1;
}
.form input, .form select {
  font: inherit; font-size: .92rem;
  color: var(--text);
  background: var(--bg);
  border: 1.5px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  width: 100%;
}
.form input:focus, .form select:focus { outline: none; border-color: var(--primary); }
.form-row { display: flex; gap: 10px; }

.day-picker { display: flex; gap: 6px; }
.day-picker button {
  flex: 1; font: inherit; font-size: .85rem; font-weight: 700;
  padding: 9px 0; border-radius: 10px;
  border: 1.5px solid var(--line); background: var(--bg); color: var(--text-sub);
  cursor: pointer;
}
.day-picker button.on { background: var(--primary); border-color: var(--primary); color: #fff; }
.day-picker button.sat { color: #0090ff; }
.day-picker button.sun { color: var(--danger); }
.day-picker button.on.sat, .day-picker button.on.sun { color: #fff; }

.color-picker { display: flex; gap: 8px; flex-wrap: wrap; }
.color-picker button {
  width: 30px; height: 30px; border-radius: 50%;
  border: 3px solid transparent; cursor: pointer; padding: 0;
}
.color-picker button.on { border-color: var(--text); }

/* ───────── item lists (tasks / events) ───────── */
.item-list { list-style: none; display: flex; flex-direction: column; gap: 10px; }
.item-list .empty, .today-list .empty {
  color: var(--text-sub); font-size: .85rem; text-align: center; padding: 18px 0;
}
.item {
  display: flex; align-items: center; gap: 12px;
  border: 1px solid var(--line); border-radius: 12px; padding: 12px;
}
.item .color-bar { width: 5px; align-self: stretch; border-radius: 4px; flex-shrink: 0; }
.item .item-body { flex: 1; min-width: 0; }
.item .item-title { font-weight: 700; font-size: .92rem; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.item .item-sub { color: var(--text-sub); font-size: .78rem; margin-top: 2px; }
.item.done .item-title { text-decoration: line-through; color: var(--text-sub); }

.chip { font-size: .68rem; font-weight: 700; padding: 2px 8px; border-radius: 99px; }
.chip-hi  { background: #fdebec; color: #d13438; }
.chip-mid { background: #fff4e0; color: #b76e00; }
.chip-lo  { background: #e6f6ee; color: #18794e; }
.chip-over{ background: var(--danger); color: #fff; }
@media (prefers-color-scheme: dark) {
  .chip-hi  { background: #46262a; color: #ff9298; }
  .chip-mid { background: #42351d; color: #ffca6a; }
  .chip-lo  { background: #1d3a2c; color: #62d39c; }
}

.progress { height: 6px; border-radius: 99px; background: var(--line); margin-top: 8px; overflow: hidden; }
.progress i { display: block; height: 100%; border-radius: 99px; background: var(--ok); }

.icon-btn {
  border: none; background: none; cursor: pointer;
  font-size: 1rem; padding: 6px; border-radius: 8px; color: var(--text-sub);
}
.icon-btn:hover { background: var(--bg); }

/* ───────── today list ───────── */
.today-list { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.today-item {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg); border-radius: 12px; padding: 10px 12px;
}
.today-item .t-time { font-size: .78rem; font-weight: 700; color: var(--text-sub); white-space: nowrap; font-variant-numeric: tabular-nums; }
.today-item .t-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.today-item .t-title { flex: 1; font-size: .88rem; font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.today-item .t-dur { font-size: .74rem; color: var(--text-sub); white-space: nowrap; }
.today-item.done-blk .t-title { text-decoration: line-through; color: var(--text-sub); }
.today-item.fixed { opacity: .75; }

/* ───────── alerts ───────── */
.alert {
  border-radius: 12px; padding: 12px 14px; font-size: .84rem;
  background: #fdebec; color: #b3261e; border: 1px solid #f6c6c9;
}
.alert b { display: block; margin-bottom: 2px; }
@media (prefers-color-scheme: dark) {
  .alert { background: #401d20; color: #ffb3b8; border-color: #6b2a30; }
}

/* ───────── weekly grid ───────── */
.grid-card { padding-bottom: 8px; }
.legend { display: flex; gap: 10px; font-size: .72rem; color: var(--text-sub); }
.legend-item { display: flex; align-items: center; gap: 4px; }
.dot { width: 9px; height: 9px; border-radius: 3px; display: inline-block; }
.dot-event { background: #98a2c0; }
.dot-task { background: var(--primary); }

.grid-wrap { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
.grid {
  display: grid;
  grid-template-columns: 40px repeat(7, minmax(104px, 1fr));
  min-width: 780px;
}
.g-corner { position: sticky; top: 0; z-index: 3; background: var(--card); }
.g-day-head {
  position: sticky; top: 0; z-index: 3;
  background: var(--card);
  text-align: center; padding: 6px 0 8px;
  border-bottom: 2px solid var(--line);
}
.g-day-head .dow { font-weight: 800; font-size: .86rem; display: block; }
.g-day-head .date { font-size: .7rem; color: var(--text-sub); }
.g-day-head.sat .dow { color: #0090ff; }
.g-day-head.sun .dow { color: var(--danger); }
.g-day-head.today .dow, .g-day-head.today .date {
  color: var(--primary);
}
.g-day-head.today .dow::after { content: " ·오늘"; font-size: .68rem; }

.g-times { position: relative; }
.g-times span {
  position: absolute; right: 6px; transform: translateY(-7px);
  font-size: .66rem; color: var(--text-sub); font-variant-numeric: tabular-nums;
}

.g-col {
  position: relative;
  border-left: 1px solid var(--line);
  background-image: repeating-linear-gradient(
    to bottom, var(--line) 0 1px, transparent 1px var(--hh, 54px));
}
.g-col.today { background-color: color-mix(in srgb, var(--primary) 5%, transparent); }

.blk {
  position: absolute; left: 3px; right: 3px;
  border-radius: 8px; padding: 3px 7px;
  overflow: hidden; font-size: .7rem; line-height: 1.3;
  border-left: 3px solid var(--c, var(--primary));
  background: color-mix(in srgb, var(--c, var(--primary)) 16%, var(--card));
  color: var(--text);
}
.blk b { display: block; font-size: .72rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.blk span { color: var(--text-sub); font-size: .64rem; font-variant-numeric: tabular-nums; }
.blk.blk-task {
  background: var(--c, var(--primary));
  border-left: none; color: #fff;
}
.blk.blk-task span { color: rgba(255, 255, 255, .82); }
.blk.blk-done { opacity: .45; }
.blk.blk-done b { text-decoration: line-through; }

.now-line {
  position: absolute; left: 0; right: 0; height: 2px;
  background: var(--danger); z-index: 2; pointer-events: none;
}
.now-line::before {
  content: ""; position: absolute; left: -2px; top: -3px;
  width: 8px; height: 8px; border-radius: 50%; background: var(--danger);
}

/* ───────── tab bar ───────── */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
}
.tab {
  flex: 1; border: none; background: none; cursor: pointer;
  font: inherit; font-size: .72rem; font-weight: 600; color: var(--text-sub);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
.tab .tab-icon { font-size: 1.15rem; }
.tab.active { color: var(--primary); }

/* ───────── toast ───────── */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 18px);
  transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  font-size: .84rem; font-weight: 600;
  padding: 10px 18px; border-radius: 99px;
  box-shadow: var(--shadow); z-index: 20;
  opacity: 0; transition: opacity .25s;
  pointer-events: none; white-space: nowrap;
}
.toast.show { opacity: 1; }

@media (min-width: 720px) {
  .app-header h1 { font-size: 1.45rem; }
  .card { padding: 20px; }
  .grid-wrap { margin: 0 -20px; padding: 0 20px; }
}
