:root {
  color-scheme: light;
  --bg: #e6ddd0;
  --paper: #fbf7f0;
  --ink: #1f1a14;
  --muted: #5e564c;
  --line: #e4d9c8;
  --line-strong: #d9cebf;
  --accent: #9a3412;
  --accent-ink: #fffaf6;
  --sage: #3f6b4e;
  --danger: #8f2d2d;
  --shadow: 0 8px 24px rgba(60, 40, 20, 0.06);
}

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

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", sans-serif;
  color: var(--ink);
  font-size: 18px;
  line-height: 1.45;
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
  touch-action: manipulation;
}

button {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app {
  width: min(480px, 100%);
  height: 100dvh;
  margin: 0 auto;
  background: var(--paper);
  display: flex;
  flex-direction: column;
}

.top {
  padding: 18px 16px 4px;
}

.brand {
  margin: 0;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

h1 {
  margin: 2px 0 0;
  font-size: 1.8rem;
  line-height: 1.2;
}

.mode {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 12px 16px 0;
}

.mode button {
  min-height: 52px;
  border-radius: 14px;
  border: 2px solid transparent;
  background: transparent;
  font-weight: 700;
}

.mode button.is-active {
  background: #fff;
  border-color: var(--line-strong);
}

.tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 12px 16px;
}

.tabs[hidden],
#idea-composer[hidden],
#idea-add-bar[hidden],
main[hidden] {
  display: none !important;
}

.tabs button {
  min-height: 52px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: 14px;
  border: 2px solid transparent;
  background: transparent;
  font-weight: 700;
  padding: 0 8px;
}

.tabs button.is-active {
  background: #fff;
  border-color: var(--line-strong);
}

.count {
  display: inline-grid;
  place-items: center;
  min-width: 1.5rem;
  height: 1.5rem;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 0.78rem;
  line-height: 1;
}

.count[hidden] {
  display: none;
}

main {
  flex: 1;
  overflow: auto;
  padding: 4px 16px 20px;
}

.day-kicker,
.hint,
.voice-note,
.status,
.empty {
  color: var(--muted);
}

.day-kicker {
  margin: 4px 0 12px;
}

.group h2,
.cal-head h2,
#sheet-title {
  font-size: 1.05rem;
  margin: 8px 0 10px;
}

.subhead {
  margin: 14px 0 8px;
  font-size: 0.95rem;
  color: var(--muted);
  font-weight: 700;
}

.empty {
  margin: 0;
  padding: 28px 8px;
  text-align: center;
}

.todo {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px;
  background: #fff;
  border-radius: 18px;
  margin: 0 0 10px;
  box-shadow: var(--shadow);
}

.cal-add {
  flex: 1 0 100%;
  margin: 0 12px 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  text-decoration: none;
  color: var(--ink);
}

.idea-link {
  display: block;
  width: 100%;
  min-height: 56px;
  margin: 0 0 8px;
  padding: 16px;
  text-align: left;
  font-weight: 700;
  background: #fff;
  border: 2px solid var(--line-strong);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.idea {
  background: #fff;
  border-radius: 18px;
  margin: 0 0 10px;
  padding: 14px 14px 12px;
  box-shadow: var(--shadow);
}

.idea-back {
  min-height: 44px;
  margin: 0 0 8px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--accent);
  font-weight: 700;
}

.idea h2 {
  margin: 0;
  font-size: 1.15rem;
}

.idea p {
  margin: 8px 0 12px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.idea .btn {
  width: 100%;
}

.idea .btn + .btn {
  margin-top: 8px;
}

#idea-add-bar .btn {
  margin: 0;
}

#idea-composer:not([hidden]) {
  flex: 1;
  overflow: auto;
}

.idea-form-title {
  margin: 4px 0 12px;
  font-size: 1.25rem;
}

.idea-actions {
  display: grid;
  grid-template-columns: 0.7fr 1.3fr;
  gap: 8px;
}

.todo-main {
  flex: 1;
  min-height: 72px;
  text-align: left;
  background: transparent;
  border: 0;
  padding: 14px 14px 14px 4px;
}

.todo-title {
  display: block;
  font-size: 1.15rem;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.todo.is-done .todo-title {
  color: var(--muted);
  font-weight: 500;
  text-decoration: line-through;
}

.todo-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin: 6px 0 0;
}

.pill {
  display: inline-block;
  background: #f3e6da;
  color: var(--accent);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 0.95rem;
  font-weight: 700;
}

.memo-preview {
  color: var(--muted);
  font-size: 0.95rem;
}

.check {
  width: 64px;
  height: 64px;
  flex: none;
  border: 0;
  background: transparent;
  padding: 0;
}

.check-box {
  width: 32px;
  height: 32px;
  margin: 0 auto;
  display: block;
  border: 2.5px solid var(--accent);
  border-radius: 10px;
  background: #fff;
}

.check[aria-pressed="true"] .check-box {
  border-color: var(--sage);
  background: var(--sage) center / 18px 18px no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5 9.5 17 19 7'/%3E%3C/svg%3E");
}

.cal-head {
  display: grid;
  grid-template-columns: 88px 1fr 88px;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

.cal-head h2 {
  margin: 0;
  text-align: center;
}

.weekdays,
.days {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.weekdays {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
}

.weekdays span:first-child {
  color: var(--accent);
}

.day,
.day-empty {
  min-height: 52px;
}

.day {
  border: 0;
  border-radius: 12px;
  background: transparent;
  font-weight: 700;
  padding: 6px 0 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.days .day:nth-child(7n + 1):not(.is-selected) {
  color: var(--accent);
}

.days .day:nth-child(7n):not(.is-selected) {
  color: #1d4e89;
}

.day.is-today:not(.is-selected) {
  box-shadow: inset 0 0 0 2px var(--accent);
}

.day.has-todos:not(.is-selected) {
  background: #f3e6da;
}

.day.is-selected {
  background: var(--accent);
  color: var(--accent-ink);
}

.dot {
  min-width: 18px;
  height: 18px;
  margin-top: 2px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
}

.day.is-selected .dot {
  background: #fff;
  color: var(--accent);
}

.calendar-layout {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.calendar-month .day,
.calendar-month .day-empty {
  min-height: 44px;
  padding: 2px 0;
}

.calendar-month .days,
.calendar-month .weekdays {
  gap: 2px;
}

.date-month {
  margin: 0 0 8px;
  text-align: center;
  font-weight: 700;
}

.date-nav {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin-bottom: 8px;
}

@media (min-width: 880px) {
  .app {
    width: min(980px, 100%);
  }

  .calendar-layout {
    display: grid;
    grid-template-columns: 380px minmax(0, 1fr);
    gap: 28px;
    align-items: start;
  }
}

.composer {
  flex: none;
  padding: 10px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--paper);
  border-top: 1px solid var(--line);
}

.composer input[type="text"],
.composer input:not([type]) {
  width: 100%;
}

#quick-title,
.field input,
.field textarea,
.time-open,
.btn {
  border-radius: 16px;
  border: 2px solid var(--line-strong);
  background: #fff;
}

#quick-title,
.field input,
.field textarea,
.time-open {
  width: 100%;
  min-height: 56px;
  padding: 14px 16px;
  font-size: 1.125rem;
}

.time-open {
  text-align: left;
  font-weight: 700;
}

.time-picker {
  margin: 0 0 12px;
  padding: 12px;
  border: 2px solid var(--line-strong);
  border-radius: 18px;
  background: #fff;
}

.ampm,
.time-actions,
.dials {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.dials {
  margin: 10px 0;
}

.dial {
  display: grid;
  justify-items: center;
  align-items: center;
  gap: 4px;
}

.dial strong {
  font-size: 2rem;
  line-height: 1;
}

.dial span {
  color: var(--muted);
  font-size: 0.95rem;
}

.ampm button,
.dial button,
.time-actions button {
  width: 100%;
}

.ampm button.is-on {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

#quick-title {
  margin: 0 0 8px;
}

.field textarea {
  min-height: 112px;
  resize: vertical;
}

.composer-actions,
.sheet-actions {
  display: grid;
  gap: 8px;
}

.composer-actions {
  grid-template-columns: 0.8fr 1.15fr 0.9fr;
}

.composer.no-voice .composer-actions {
  grid-template-columns: 1fr 1fr;
}

.btn {
  min-height: 56px;
  padding: 0 12px;
  font-weight: 700;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.btn-danger {
  width: 100%;
  margin-top: 8px;
  background: #fff;
  color: var(--danger);
  border-color: var(--danger);
}

.btn-block {
  width: 100%;
  margin: 0 0 12px;
}

.btn:active {
  transform: scale(0.98);
}

.mic.is-listening {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.voice-note,
.status,
.hint {
  margin: 0 0 8px;
  font-size: 0.95rem;
}

.status:empty {
  display: none;
}

.status[data-kind="error"],
.voice-note.is-error {
  color: var(--danger);
}

.sheet[hidden] {
  display: none !important;
}

.sheet {
  position: fixed;
  inset: 0;
  z-index: 20;
}

.backdrop {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  padding: 0;
  background: rgba(40, 28, 18, 0.45);
}

.sheet-panel {
  position: absolute;
  z-index: 1;
  left: 0;
  right: 0;
  bottom: 0;
  width: min(480px, 100%);
  margin-inline: auto;
  max-height: min(92dvh, 760px);
  overflow: auto;
  padding: 10px 16px calc(16px + env(safe-area-inset-bottom));
  background: var(--paper);
  border-radius: 24px 24px 0 0;
  box-shadow: 0 -12px 40px rgba(40, 28, 18, 0.18);
}

.sheet-grab {
  width: 48px;
  height: 5px;
  margin: 4px auto 8px;
  border-radius: 99px;
  background: var(--line-strong);
}

.title-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin-bottom: 12px;
}

.title-row .field {
  margin: 0;
}

.title-row .mic {
  flex: none;
  min-width: 84px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
  font-size: 0.95rem;
  font-weight: 700;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.field-row .field {
  margin-bottom: 8px;
}

.grow {
  flex: 1;
  min-width: 0;
}

.sheet-actions {
  grid-template-columns: 1fr 1.4fr;
}

body.sheet-open {
  overflow: hidden;
}

@media (max-width: 360px) {
  .field-row,
  .composer-actions {
    grid-template-columns: 1fr;
  }

  .cal-head {
    grid-template-columns: 72px 1fr 72px;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .mic.is-listening {
    animation: pulse 1.2s ease-in-out infinite;
  }
}

@keyframes pulse {
  50% {
    box-shadow: 0 0 0 6px rgba(154, 52, 18, 0.28);
  }
}

@media (prefers-reduced-motion: reduce) {
  .mic.is-listening,
  .btn:active {
    animation: none;
    transform: none;
  }
}
