:root {
  --navy: #081222;
  --navy-deep: #040a14;
  --navy-mid: #102034;
  --amber: #f0ac38;
  --cyan: #56c4d6;
  --paper: #e2e8ee;
  --surface: #f4f7fa;
  --ink: #0e1c2a;
  --muted: #4e6478;
  --line: #c4d2de;
  --weekend: #c4684e;
  --outside: #a8b6c4;
  --selected: #dceef6;
  --hover: #eef4f8;
  --subtitle: #e8c884;
  --header-h: 72px;
  --status-h: 44px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --font: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei UI",
    "Microsoft YaHei", "Heiti SC", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--navy-deep);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  overscroll-behavior: none;
  min-height: 100dvh;
  min-height: -webkit-fill-available;
}

button, input, select, textarea {
  font: inherit;
  font-size: 16px; /* avoid iOS zoom */
}

button {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  min-height: -webkit-fill-available;
  background: var(--paper);
  padding-top: var(--safe-top);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

.app-header {
  flex: 0 0 auto;
  height: var(--header-h);
  background: var(--navy);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px 8px;
  position: relative;
  user-select: none;
}

.app-header::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 5px;
  background: linear-gradient(#56c4d6 0 2px, #f0ac38 2px 5px);
}

.header-ticks {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 10px;
  height: 6px;
  background-image: repeating-linear-gradient(
    to right,
    rgba(86, 196, 214, 0.28) 0 1px,
    transparent 1px 18px
  );
  pointer-events: none;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1 1 auto;
}

.plane-badge {
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
  border-radius: 50%;
  border: 1.5px solid rgba(86, 196, 214, 0.8);
  background: var(--navy-deep);
  display: grid;
  place-items: center;
}

.plane-badge svg {
  width: 34px;
  height: 34px;
  display: block;
}

.app-title {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.month-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.nav-btn, .today-btn, .icon-btn {
  min-height: 44px;
  min-width: 44px;
  border-radius: 8px;
  border: 1px solid rgba(60, 140, 160, 0.9);
  background: var(--navy-mid);
  color: #fff;
  padding: 0 10px;
  font-weight: 700;
}

.today-btn {
  background: var(--amber);
  color: var(--navy-deep);
  border-color: var(--amber);
  min-width: 72px;
  font-weight: 700;
}

.month-label {
  min-width: 7.5em;
  text-align: center;
  font-size: 1.1rem;
  font-weight: 700;
}

.layout {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(320px, 0.9fr);
  grid-template-rows: minmax(0, 1fr);
  gap: 12px;
  padding: 12px 12px 8px;
  min-height: 0;
  background: var(--paper);
}

.cal-card, .side {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.calendar {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.cal-week {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  background: var(--navy);
  color: #fff;
  height: 36px;
  flex: 0 0 auto;
}

.cal-week span {
  display: grid;
  place-items: center;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.cal-week span.wkend { color: var(--amber); }

.cal-grid {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  grid-template-rows: repeat(6, minmax(0, 1fr));
  min-height: 0;
  border-top: 1px solid var(--cyan);
}

.cell {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 5px 5px 4px;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  cursor: pointer;
  overflow: hidden;
  background: var(--surface);
}

.cell:nth-child(7n) { border-right: none; }
.cell:hover { background: var(--hover); }
.cell.selected {
  background: var(--selected);
  box-shadow: inset 3px 0 0 var(--cyan);
}

.cell-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 2px;
  flex: 0 0 auto;
}

.day-num {
  min-width: 2.25ch;
  padding: 1px 5px;
  font-size: 1.05rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.25;
  color: var(--ink);
  text-align: center;
}

.cell.outside .day-num,
.cell.outside .holiday,
.cell.outside .work-badge {
  color: var(--outside);
}

.day-num.today {
  background: var(--amber);
  color: var(--navy-deep);
  border-radius: 999px;
  box-shadow: 0 0 0 2px var(--surface), 0 0 0 3.5px var(--cyan);
}

.work-badge {
  flex: 0 0 auto;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--weekend);
  line-height: 1.4;
  padding-top: 3px;
}

.holiday {
  flex: 0 0 auto;
  font-size: 0.7rem;
  line-height: 1.2;
  padding: 1px 4px;
  border-radius: 3px;
  align-self: flex-start;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.holiday.rest {
  background: var(--amber);
  color: var(--navy-deep);
  font-weight: 700;
}

.cell.outside .holiday.rest {
  background: #e8d6b0;
  color: var(--navy-deep);
}

.holiday.work { color: var(--weekend); }
.holiday.quiet { color: var(--muted); }
.cell.outside .holiday.work,
.cell.outside .holiday.quiet { color: var(--outside); }

.chips {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow: hidden;
}

.chip {
  display: flex;
  align-items: center;
  min-height: 16px;
  border-radius: 3px;
  overflow: hidden;
  font-size: 0.68rem;
  line-height: 1.2;
  padding: 1px 4px 1px 0;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.chip-more {
  font-size: 0.68rem;
  color: var(--muted);
  padding: 0 4px;
}

.legend {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  padding: 6px 10px 8px;
  color: var(--muted);
  font-size: 0.75rem;
  border-top: 1px solid var(--line);
}

.legend i {
  display: inline-block;
  width: 3px;
  height: 12px;
  margin-right: 6px;
  vertical-align: -1px;
  border-radius: 1px;
}

.side {
  padding: 10px 12px 0;
}

.day-head { flex: 0 0 auto; padding: 2px 2px 8px; }
.day-title { font-size: 1.15rem; font-weight: 700; color: var(--ink); }
.day-count { font-size: 0.8rem; color: var(--muted); margin-top: 2px; }

.quick-add {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  padding-bottom: 8px;
}

.quick-add button {
  min-height: 44px;
  border-radius: 8px;
  border: 1px solid;
  font-weight: 700;
  padding: 0 6px;
  white-space: nowrap;
}

.day-list, .agenda-list {
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.day-list {
  flex: 1 1 40%;
  min-height: 80px;
  padding-bottom: 8px;
}

.empty-day {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  text-align: center;
  color: var(--muted);
  padding: 16px 12px 8px;
  gap: 12px;
}

.empty-day .plane-badge { width: 64px; height: 64px; }
.empty-day .plane-badge svg { width: 44px; height: 44px; }

.event-card {
  display: grid;
  grid-template-columns: 6px 1fr auto;
  gap: 0 10px;
  border-radius: 8px;
  padding: 10px 10px 10px 0;
  margin-bottom: 8px;
  min-height: 72px;
}

.event-card .bar { border-radius: 8px 0 0 8px; }
.event-card .when { font-weight: 700; color: var(--ink); }
.event-card .ttl { color: var(--ink); margin-top: 2px; }
.event-card .meta { font-size: 0.8rem; color: var(--muted); margin-top: 4px; }
.event-card .acts { display: flex; flex-direction: column; gap: 6px; }
.event-card .acts button {
  min-height: 36px;
  min-width: 56px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 6px;
  padding: 0 8px;
}

.agenda {
  flex: 1 1 48%;
  min-height: 200px;
  display: flex;
  flex-direction: column;
  margin: 0 -12px 0;
  background: var(--navy-deep);
  color: #fff;
  padding: 8px 12px calc(10px + var(--safe-bottom));
  border-top: 1px solid rgba(86, 196, 214, 0.35);
}

.agenda-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 0 10px;
  flex: 0 0 auto;
}

.agenda-head h2 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
}

.agenda-count { color: var(--amber); font-size: 0.9rem; }

.agenda-list { flex: 1 1 auto; min-height: 0; }

.agenda-empty {
  color: var(--subtitle);
  padding: 8px 0 0;
  font-size: 0.95rem;
}

.agenda-row {
  display: grid;
  grid-template-columns: 5px 1fr auto;
  gap: 0 10px;
  background: var(--navy-mid);
  border-radius: 8px;
  padding: 8px 10px 8px 0;
  margin-bottom: 8px;
  min-height: 58px;
  cursor: pointer;
}

.agenda-row .when { color: #baccdc; font-size: 0.9rem; }
.agenda-row .clock { color: var(--amber); font-weight: 700; }
.agenda-row .cat { font-size: 0.75rem; margin-top: 6px; }
.agenda-row .ttl { color: #fff; margin-top: 4px; }
.agenda-row .tag { font-size: 0.8rem; margin-top: 6px; }

.status {
  flex: 0 0 auto;
  min-height: var(--status-h);
  background: var(--navy-deep);
  color: #d6e4ec;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px calc(6px + var(--safe-bottom));
  border-top: 2px solid var(--amber);
  box-shadow: 0 -1px 0 var(--cyan);
  font-size: 0.85rem;
}

.status-text {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status button {
  flex: 0 0 auto;
  min-height: 40px;
  min-width: 64px;
  border: 0;
  background: transparent;
  color: var(--amber);
  font-weight: 700;
  padding: 0 10px;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 10, 20, 0.55);
  display: none;
  align-items: stretch;
  justify-content: center;
  padding: calc(12px + var(--safe-top)) calc(12px + var(--safe-right)) calc(12px + var(--safe-bottom)) calc(12px + var(--safe-left));
  z-index: 40;
}

.overlay.open { display: flex; }

.sheet {
  background: var(--surface);
  width: min(560px, 100%);
  max-height: 100%;
  border-radius: 14px;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.35);
}

.sheet-head {
  background: var(--navy);
  color: #fff;
  padding: 14px 18px 12px;
  position: relative;
  flex: 0 0 auto;
}

.sheet-head h2 { margin: 0; font-size: 1.15rem; }
.sheet-head .accent {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 3px;
}

.sheet-body { padding: 14px 18px 18px; display: flex; flex-direction: column; gap: 12px; }

.cats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.cats button {
  min-height: 44px;
  border-radius: 8px;
  border: 1px solid;
  background: var(--surface);
  font-weight: 700;
}

.cats button.on { color: #fff; border-color: transparent; }

label.field { display: flex; flex-direction: column; gap: 6px; font-size: 0.8rem; color: var(--muted); font-weight: 600; letter-spacing: 0.04em; }
label.field input, label.field select, label.field textarea {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 10px;
  background: #fff;
  color: var(--ink);
  min-height: 44px;
}

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

.row-2, .row-3 { display: grid; gap: 10px; }
.row-2 { grid-template-columns: 1fr 1fr; }
.row-3 { grid-template-columns: 1.1fr 0.9fr auto 0.9fr; align-items: end; }

.end-check {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  color: var(--ink);
  font-weight: 600;
  font-size: 0.9rem;
  letter-spacing: 0;
}

.quick-when {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.quick-when button, .ghost {
  min-height: 44px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 8px;
  padding: 0 8px;
}

.hint { font-size: 0.8rem; color: var(--muted); font-weight: 400; letter-spacing: 0; }

.sheet-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  padding-top: 4px;
}

.primary, .danger {
  min-height: 44px;
  min-width: 96px;
  border: 0;
  border-radius: 8px;
  padding: 0 16px;
  font-weight: 700;
  color: #fff;
}

.primary { background: var(--navy); }
.danger { background: var(--weekend); }
.sheet-actions .ghost { min-width: 96px; }

.about p { margin: 0 0 10px; color: var(--ink); }
.about .quiet { color: var(--muted); font-size: 0.9rem; }
.settings-row { display: flex; flex-wrap: wrap; gap: 8px; }

@media (max-width: 980px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(380px, 48vh) minmax(0, 1fr);
  }
  .agenda { min-height: 220px; }
}

@media (max-width: 700px) {
  .app-title { font-size: 1.15rem; }
  .plane-badge { width: 42px; height: 42px; }
  .month-label { min-width: 6.2em; font-size: 1rem; }
  .row-3 { grid-template-columns: 1fr 1fr; }
  .row-3 .end-check { grid-column: 1 / -1; }
  .quick-when, .cats, .quick-add { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cal-week { height: 32px; }
  .day-num { font-size: 0.98rem; }
}

@media (pointer: coarse) {
  .cell { padding-top: 6px; }
}
