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

:root {
  --bg: #f2f2f7;
  --surface: #ffffff;
  --border: #d1d1d6;
  --text: #1c1c1e;
  --text-muted: #8e8e93;
  --radius: 10px;
  --shadow: 0 2px 12px rgba(0, 0, 0, .1);
}

html {
  height: 100%;
}

body {
  min-height: 100%;
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

.hidden { display: none !important; }

/* ── Buttons ──────────────────────────────────────────────── */
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 18px;
  border: none;
  border-radius: var(--radius);
  font-size: .95rem;
  font-family: inherit;
  cursor: pointer;
  background: var(--border);
  color: var(--text);
  transition: opacity .1s;
  -webkit-appearance: none;
}

button:active { opacity: .75; }

.btn-primary  { background: #1c1c1e; color: #fff; }
.btn-danger   { background: #ff3b30; color: #fff; }

/* ── Login ────────────────────────────────────────────────── */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100svh;
  padding: 32px 20px;
}

.login-inner {
  width: 100%;
  max-width: 340px;
  text-align: center;
}

h1 {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -.02em;
  margin-bottom: 6px;
}

.login-sub {
  color: var(--text-muted);
  margin-bottom: 28px;
  font-size: .95rem;
}

#user-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 24px;
}

.user-btn {
  width: 100%;
  padding: 18px;
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: .01em;
  border-radius: var(--radius);
  background: var(--user-color, #666);
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,.25);
}

#pin-entry {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px 20px 20px;
  box-shadow: var(--shadow);
  text-align: left;
}

.pin-prompt {
  font-size: .95rem;
  color: var(--text-muted);
  margin-bottom: 12px;
  text-align: center;
}

#pin-input {
  display: block;
  width: 100%;
  font-size: 2rem;
  letter-spacing: .5em;
  text-align: center;
  padding: 12px 8px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  font-family: inherit;
  background: var(--bg);
  color: var(--text);
  margin-bottom: 8px;
  transition: border-color .15s;
}

#pin-input:focus { border-color: #555; }

.error {
  color: #ff3b30;
  font-size: .88rem;
  text-align: center;
  margin-bottom: 6px;
}

.pin-actions {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

.pin-actions button { flex: 1; padding: 12px; }

/* ── App header ───────────────────────────────────────────── */
#app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 14px 8px;
}

#user-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
}

#current-user-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

#current-user-label {
  font-weight: 700;
  font-size: .95rem;
  flex: 1;
}

#switch-user-btn {
  font-size: .78rem;
  padding: 4px 10px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 20px;
}

#month-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

#month-label {
  font-weight: 600;
  font-size: 1.05rem;
  letter-spacing: -.01em;
}

#prev-month,
#next-month {
  background: transparent;
  font-size: 1.8rem;
  padding: 0 10px;
  line-height: 1;
  color: var(--text-muted);
}

/* ── Calendar grid ────────────────────────────────────────── */
#calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px;
  background: var(--border);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.day-header {
  background: var(--bg);
  text-align: center;
  font-size: .65rem;
  font-weight: 600;
  color: var(--text-muted);
  padding: 5px 0 4px;
  text-transform: uppercase;
  letter-spacing: .06em;
}

.day-cell {
  position: relative;
  background: var(--surface);
  min-height: 56px;
  cursor: pointer;
}

.day-cell.empty {
  background: var(--bg);
  cursor: default;
}

.day-num {
  position: absolute;
  top: 5px;
  left: 6px;
  font-size: .72rem;
  font-weight: 500;
  line-height: 1;
  color: var(--text);
  z-index: 1;
}

/* Today ring */
.day-cell.today .day-num {
  background: var(--text);
  color: var(--surface);
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .62rem;
  top: 4px;
  left: 4px;
}

/* Drag selection outline */
.day-cell.selecting::after {
  content: '';
  position: absolute;
  inset: 0;
  border: 2px solid rgba(0, 0, 0, .45);
  pointer-events: none;
  z-index: 2;
}

/* Note indicator */
.day-cell.has-note::before {
  content: '';
  position: absolute;
  bottom: 5px;
  right: 5px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: rgba(0, 0, 0, .35);
  z-index: 1;
}

/* ── Hint text ────────────────────────────────────────────── */
#hint {
  text-align: center;
  font-size: .78rem;
  color: var(--text-muted);
  padding: 12px 16px 20px;
}

/* ── Modal ────────────────────────────────────────────────── */
#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  padding: 0;
}

#modal {
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%;
  max-width: 500px;
  padding: 24px 20px;
  padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
}

#modal-title {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 14px;
}

#modal-body {
  margin-bottom: 18px;
  font-size: .95rem;
  line-height: 1.55;
}

.period-card {
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 10px;
  background: var(--bg);
  border-left: 4px solid #ccc;
}

.period-card strong { display: block; margin-bottom: 2px; }
.period-card small  { color: var(--text-muted); font-size: .85rem; }
.period-card em     { display: block; margin-top: 4px; font-size: .88rem; color: var(--text-muted); }

#modal-body label {
  display: block;
  font-size: .88rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}

#note-input {
  display: block;
  width: 100%;
  padding: 11px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: .95rem;
  font-family: inherit;
  outline: none;
  background: var(--bg);
  color: var(--text);
  transition: border-color .15s;
}

#note-input:focus { border-color: #555; }

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-top: 14px;
  cursor: pointer;
  font-size: .95rem;
  color: var(--text);
}

.checkbox-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  cursor: pointer;
  accent-color: #1c1c1e;
}

.special-badge {
  display: inline-block;
  font-size: .7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  background: rgba(0,0,0,.12);
  color: inherit;
  border-radius: 4px;
  padding: 1px 5px;
  margin-left: 4px;
  vertical-align: middle;
}

#modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

#modal-actions button {
  min-width: 90px;
  padding: 11px 16px;
}

/* ── Desktop adjustments ──────────────────────────────────── */
@media (min-width: 520px) {
  #modal-overlay {
    align-items: center;
    padding: 20px;
  }
  #modal {
    border-radius: var(--radius);
    max-height: 85vh;
    overflow-y: auto;
    padding-bottom: 24px;
  }
  .day-cell { min-height: 72px; }
}

@media (hover: hover) {
  .day-cell:not(.empty):hover { filter: brightness(.95); }
  .user-btn:hover              { opacity: .88; }
}
