/* ============ Twogether ============ */
:root {
  --p1: #f97066;
  --p2: #14b8a6;
  --both: #8b5cf6;
  --bg: #faf7f2;
  --card: #ffffff;
  --ink: #33302b;
  --muted: #8a857c;
  --line: #eee9e0;
  --accent: #f97066;
  --radius: 16px;
  --shadow: 0 1px 3px rgba(60, 50, 30, .07), 0 4px 14px rgba(60, 50, 30, .05);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.45;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; -webkit-tap-highlight-color: transparent; }
input { font: inherit; color: inherit; }
.hidden { display: none !important; }

/* ---- PIN gate ---- */
#gate {
  position: fixed; inset: 0; z-index: 100; background: var(--bg);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.gate-card { text-align: center; width: 100%; max-width: 300px; }
.gate-icon { width: 76px; height: 76px; border-radius: 20px; box-shadow: var(--shadow); }
.gate-card h1 { font-size: 26px; letter-spacing: -.4px; margin: 12px 0 4px; }
#gate-msg { color: var(--muted); font-size: 14.5px; margin-bottom: 18px; }
#gate-msg.err { color: #dc2626; font-weight: 700; }
#gate-pin {
  width: 100%; text-align: center; font-size: 26px; letter-spacing: 10px;
  padding: 12px; border: 1.5px solid var(--line); border-radius: 14px;
  background: var(--card); margin-bottom: 12px;
}
#gate-pin:focus { outline: 2px solid var(--accent); border-color: transparent; }
#gate-form .mainbtn { width: 100%; }
.shake { animation: shake .4s; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-8px); }
  40%, 80% { transform: translateX(8px); }
}

/* ---- top bar ---- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px 8px;
  max-width: 1100px; margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 800; font-size: 21px; letter-spacing: -.3px; }
.brand-icon { width: 30px; height: 30px; border-radius: 8px; }
.iconbtn {
  font-size: 19px; width: 40px; height: 40px; border-radius: 12px;
  display: inline-flex; align-items: center; justify-content: center;
}
.iconbtn:active { background: var(--line); }

/* ---- layout ---- */
#main { max-width: 640px; margin: 0 auto; padding: 4px 14px 20px; }
body[data-view="week"] #main, body[data-view="month"] #main { max-width: 1100px; }
.view { display: none; }
body[data-view="today"] #view-today,
body[data-view="week"] #view-week,
body[data-view="month"] #view-month,
body[data-view="manage"] #view-manage { display: block; }

/* ---- bottom tabs ---- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: flex; justify-content: space-around;
  background: rgba(255,255,255,.92); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
}
.tab {
  flex: 1; max-width: 120px; display: flex; flex-direction: column; align-items: center; gap: 1px;
  font-size: 11.5px; font-weight: 600; color: var(--muted);
  padding: 5px 0 3px; border-radius: 12px;
}
.tab-ico { font-size: 21px; }
.tab.active { color: var(--accent); }
.tab.active .tab-ico { transform: scale(1.12); }

/* ---- generic bits ---- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); }
.mainbtn {
  background: var(--accent); color: #fff; font-weight: 700;
  padding: 12px 22px; border-radius: 14px; font-size: 16px;
  box-shadow: 0 3px 10px rgba(249,112,102,.35);
}
.mainbtn:active { transform: scale(.97); }
.ghostbtn {
  border: 1.5px solid var(--line); background: var(--card);
  padding: 10px 16px; border-radius: 12px; font-weight: 600;
}
.dangerbtn { color: #dc2626; font-weight: 700; padding: 12px 16px; border-radius: 12px; }
.dangerbtn.arm { background: #dc2626; color: #fff; }
.linkbtn { color: var(--accent); font-weight: 600; text-decoration: underline; font-size: 14px; }
.hint { font-size: 12.5px; color: var(--muted); margin-top: 6px; }
.hint-inline { font-weight: 400; color: var(--muted); font-size: 12.5px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; }
.dot-p1 { background: var(--p1); }
.dot-p2 { background: var(--p2); }

/* ---- check circles ---- */
.chk {
  --c: var(--both);
  width: 30px; height: 30px; min-width: 30px; border-radius: 50%;
  border: 2.5px solid var(--c);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 15px; color: transparent; background: #fff;
  transition: background .15s, transform .1s;
  position: relative;
}
.chk::after { content: "✓"; font-weight: 900; }
.chk.done { background: var(--c); color: #fff; }
.chk:active { transform: scale(.85); }
.chk.small { width: 22px; height: 22px; min-width: 22px; border-width: 2px; font-size: 11px; }
.chk .chk-ini {
  position: absolute; top: -7px; right: -7px;
  font-size: 9.5px; font-weight: 800; color: #fff; background: var(--c);
  width: 15px; height: 15px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
}

/* ---- Today ---- */
.today-head { padding: 8px 4px 14px; }
.today-date { font-size: 24px; font-weight: 800; letter-spacing: -.4px; }
.today-sub { color: var(--muted); font-size: 14px; margin-top: 2px; }
.progress-wrap { margin-top: 12px; }
.progress-bar { height: 10px; border-radius: 6px; background: var(--line); overflow: hidden; }
.progress-fill {
  height: 100%; border-radius: 6px;
  background: linear-gradient(90deg, var(--p1), var(--p2));
  transition: width .4s ease;
}
.progress-label { font-size: 12.5px; color: var(--muted); margin-top: 5px; font-weight: 600; }
.section-head {
  display: flex; align-items: center; gap: 8px;
  font-size: 15px; font-weight: 800; margin: 18px 4px 8px;
}
.section-head .who-emoji { font-size: 19px; }
.item-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 12px 14px; margin-bottom: 8px;
  border-left: 4px solid var(--c, var(--line));
}
.item-row.alldone { opacity: .55; }
.item-row.alldone .item-title { text-decoration: line-through; }
.item-emoji { font-size: 22px; }
.item-main { flex: 1; min-width: 0; }
.item-title { font-weight: 700; font-size: 15.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-meta { font-size: 12.5px; color: var(--muted); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.time-chip { background: var(--bg); border-radius: 8px; padding: 1px 7px; font-weight: 600; }
.turn-chip { font-weight: 700; }
.checks { display: flex; gap: 8px; }
.empty-state { text-align: center; padding: 46px 20px; }
.empty-state .big { font-size: 46px; }
.empty-state h3 { font-size: 19px; margin: 10px 0 6px; }
.empty-state p { color: var(--muted); font-size: 14.5px; margin-bottom: 18px; }
.empty-state .mainbtn { margin: 4px; }
.allclear {
  text-align: center; padding: 26px 16px; background: var(--card);
  border-radius: var(--radius); box-shadow: var(--shadow); margin-top: 16px;
  font-weight: 700; font-size: 16px;
}

/* ---- view controls (week/month) ---- */
.viewbar {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 2px 14px; flex-wrap: wrap;
}
.viewbar h2 { font-size: 19px; font-weight: 800; letter-spacing: -.3px; flex: 1; min-width: 140px; }
.navbtns { display: flex; gap: 4px; align-items: center; }
.navbtn {
  width: 36px; height: 36px; border-radius: 10px; border: 1.5px solid var(--line);
  background: var(--card); font-size: 16px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
}
.todaybtn { border: 1.5px solid var(--line); background: var(--card); border-radius: 10px; padding: 7px 12px; font-weight: 700; font-size: 13.5px; }
.printbtn {
  border: 1.5px solid var(--line); background: var(--card); border-radius: 10px;
  padding: 7px 12px; font-weight: 700; font-size: 13.5px; display: inline-flex; gap: 6px; align-items: center;
}

/* ---- Week (screen) ---- */
.week-screen {
  display: flex; gap: 10px; overflow-x: auto; scroll-snap-type: x mandatory;
  padding-bottom: 10px; -webkit-overflow-scrolling: touch;
}
.day-col {
  min-width: 240px; flex: 1; scroll-snap-align: start;
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 12px; align-self: flex-start;
}
.day-col.is-today { outline: 2.5px solid var(--accent); }
.day-col-head { font-weight: 800; font-size: 14px; margin-bottom: 10px; display: flex; justify-content: space-between; align-items: baseline; }
.day-col-head .dnum { color: var(--muted); font-weight: 700; }
.day-col.is-today .day-col-head { color: var(--accent); }
.wk-item { display: flex; align-items: center; gap: 8px; padding: 6px 2px; border-bottom: 1px solid var(--line); }
.wk-item:last-child { border-bottom: none; }
.wk-item .wk-title { flex: 1; font-size: 13.5px; font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wk-item .wk-title.alldone { text-decoration: line-through; opacity: .5; }
.wk-none { color: var(--muted); font-size: 13px; padding: 6px 2px; }

/* ---- Month (screen) ---- */
.month-grid {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px;
  background: transparent;
}
.mg-head { text-align: center; font-size: 11.5px; font-weight: 800; color: var(--muted); padding: 4px 0; text-transform: uppercase; }
.mg-cell {
  background: var(--card); border-radius: 10px; box-shadow: var(--shadow);
  min-height: 64px; padding: 4px 5px; cursor: pointer;
  display: flex; flex-direction: column; gap: 2px; overflow: hidden;
}
.mg-cell.out { background: transparent; box-shadow: none; cursor: default; }
.mg-cell .dnum {
  font-size: 12px; font-weight: 800; color: var(--muted);
  width: 22px; height: 22px; display: flex; align-items: center; justify-content: center; border-radius: 50%;
}
.mg-cell.is-today .dnum { background: var(--accent); color: #fff; }
.mg-chips { display: flex; flex-wrap: wrap; gap: 2px; align-content: flex-start; }
.mchip {
  --pc: var(--both);
  display: inline-flex; align-items: center; gap: 3px;
  font-size: 11px; border-radius: 6px; padding: 1px 3px;
  background: color-mix(in srgb, var(--pc) 12%, white);
  max-width: 100%; overflow: hidden;
}
.mchip .mbox {
  width: 11px; height: 11px; min-width: 11px; border: 1.5px solid var(--pc); border-radius: 3px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 8px; font-weight: 900; color: var(--pc);
}
.mchip .mbox.done { background: var(--pc); color: #fff; }
.mchip .mtitle { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 700px) {
  .mg-cell { min-height: 52px; }
  .mchip .mtitle, .mchip .mbox { display: none; }  /* emoji-only chips on small screens */
  .mchip { background: transparent; padding: 0; font-size: 12px; }
}
.month-legend { display: flex; gap: 14px; margin-top: 12px; font-size: 13px; color: var(--muted); font-weight: 600; flex-wrap: wrap; }
.month-legend .dot { margin-right: 5px; }

/* ---- Manage ---- */
.seg { display: flex; background: var(--line); border-radius: 12px; padding: 3px; margin-bottom: 14px; }
.seg button { flex: 1; padding: 9px 0; border-radius: 10px; font-weight: 700; font-size: 14px; color: var(--muted); }
.seg button.active { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
.mg-item {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 13px 14px; margin-bottom: 8px; cursor: pointer;
  border-left: 4px solid var(--c, var(--line));
}
.mg-item.inactive { opacity: .5; }
.mg-item .item-main { pointer-events: none; }
.switch { position: relative; width: 44px; height: 26px; min-width: 44px; }
.switch input { opacity: 0; width: 100%; height: 100%; position: absolute; cursor: pointer; z-index: 2; margin: 0; }
.switch .track { position: absolute; inset: 0; background: var(--line); border-radius: 13px; transition: background .15s; }
.switch .track::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px;
  background: #fff; border-radius: 50%; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: left .15s;
}
.switch input:checked + .track { background: var(--p2); }
.switch input:checked + .track::after { left: 21px; }
.mg-del {
  font-size: 16px; min-width: 38px; height: 38px; border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center;
}
.mg-del.arm { background: #dc2626; color: #fff; font-weight: 800; font-size: 12.5px; }
.addrow { display: flex; gap: 8px; margin: 14px 0 6px; }
.addrow .mainbtn { flex: 1; font-size: 15px; padding: 12px 8px; }

/* ---- modals ---- */
.modal {
  position: fixed; inset: 0; z-index: 60; display: none;
  background: rgba(40, 35, 25, .45);
  align-items: flex-end; justify-content: center;
}
.modal.open { display: flex; }
.modal-card {
  background: var(--bg); width: 100%; max-width: 560px;
  border-radius: 22px 22px 0 0; max-height: 92vh; overflow-y: auto;
  padding-bottom: env(safe-area-inset-bottom);
  animation: slideup .22s ease;
}
@media (min-width: 600px) {
  .modal { align-items: center; padding: 20px; }
  .modal-card { border-radius: 22px; }
}
@keyframes slideup { from { transform: translateY(40px); opacity: .6; } to { transform: none; opacity: 1; } }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px 6px; position: sticky; top: 0; background: var(--bg); z-index: 2;
}
.modal-head h2 { font-size: 19px; letter-spacing: -.3px; }
.modal-body { padding: 6px 18px 10px; }
.modal-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 18px 18px; }
.modal-foot .mainbtn { margin-left: auto; }
.welcome { text-align: center; font-size: 17px; padding: 8px 0 16px; line-height: 1.5; }

.field { margin-bottom: 18px; }
.field > label { display: block; font-weight: 700; font-size: 13.5px; margin-bottom: 7px; }
.field input[type="text"] {
  width: 100%; padding: 12px 14px; border: 1.5px solid var(--line);
  border-radius: 12px; background: var(--card); font-size: 16px;
}
.field input[type="text"]:focus { outline: 2px solid var(--accent); border-color: transparent; }
.title-row { display: flex; gap: 8px; }
.title-row input { flex: 1; min-width: 0; }
.emoji-btn {
  width: 48px; height: 48px; min-width: 48px; font-size: 24px;
  border: 1.5px solid var(--line); border-radius: 12px; background: var(--card);
  display: inline-flex; align-items: center; justify-content: center;
}
.emoji-grid {
  display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px;
  background: var(--card); border: 1.5px solid var(--line); border-radius: 12px;
  padding: 8px; margin-top: 8px;
}
.emoji-grid button { font-size: 21px; padding: 5px 0; border-radius: 8px; }
.emoji-grid button:active, .emoji-grid button.sel { background: var(--line); }
.emoji-grid.people { grid-template-columns: repeat(6, 1fr); max-height: 235px; overflow-y: auto; }
.pills.sub { margin-top: 10px; }
.phase-label { font-size: 13px; font-weight: 700; color: var(--muted); align-self: center; margin-right: 2px; }
.pills { display: flex; gap: 7px; flex-wrap: wrap; }
.pill {
  border: 1.5px solid var(--line); background: var(--card);
  padding: 9px 14px; border-radius: 999px; font-weight: 700; font-size: 14px;
}
.pill.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.pill.active[data-val="p1"] { background: var(--p1); border-color: var(--p1); }
.pill.active[data-val="p2"] { background: var(--p2); border-color: var(--p2); }
.pill.active[data-val="both"] { background: var(--both); border-color: var(--both); }
.day-pills { display: flex; gap: 5px; margin-top: 10px; }
.day-pill {
  flex: 1; padding: 9px 0; border-radius: 10px; border: 1.5px solid var(--line);
  background: var(--card); font-weight: 700; font-size: 12.5px; text-align: center;
}
.day-pill.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.mday-row { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-size: 14px; font-weight: 600; }
.mday-row input {
  width: 64px; padding: 9px; border: 1.5px solid var(--line); border-radius: 10px;
  background: var(--card); font-size: 16px; text-align: center;
}
.time-row { display: flex; align-items: center; gap: 10px; }
.time-row input[type="time"] {
  padding: 10px 12px; border: 1.5px solid var(--line); border-radius: 12px;
  background: var(--card); font-size: 16px;
}
.check-row { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-size: 14.5px; font-weight: 600; }
.check-row input { width: 19px; height: 19px; accent-color: var(--accent); }

/* ---- toast / confetti / boot error ---- */
#toast {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 12px;
  font-size: 14px; font-weight: 600; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s; z-index: 80; max-width: 90vw; text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 90; overflow: hidden; }
.confetto { position: absolute; top: -30px; font-size: 22px; animation: fall 2.4s ease-in forwards; }
@keyframes fall {
  to { transform: translateY(110vh) rotate(360deg); opacity: .7; }
}
#boot-error { text-align: center; padding: 40px 20px; font-size: 15px; }

/* ---- week print table (hidden on screen) ---- */
.week-print { display: none; }
.print-header { display: none; }

/* ============ PRINT (landscape) ============ */
@page { size: A4 landscape; margin: 9mm; }

@media print {
  body { background: #fff; padding: 0; }
  .no-print, .topbar, .tabbar, .viewbar, .month-legend { display: none !important; }
  #main { max-width: none; padding: 0; }
  .print-header {
    display: flex; align-items: baseline; justify-content: space-between;
    border-bottom: 2px solid #33302b; padding-bottom: 6px; margin-bottom: 10px;
  }
  .print-header h1 { font-size: 20px; letter-spacing: -.3px; }
  .print-header .ph-legend { font-size: 12px; font-weight: 700; display: flex; gap: 16px; }
  .print-header .ph-brand { font-size: 11px; color: #8a857c; font-weight: 600; }

  /* Week: table of items x days */
  .week-screen { display: none; }
  .week-print { display: block; }
  .week-print table { width: 100%; border-collapse: collapse; table-layout: fixed; }
  .week-print th, .week-print td { border: 1px solid #b9b2a5; padding: 5px 7px; font-size: 12px; vertical-align: middle; }
  .week-print th { background: #f1ece3; font-weight: 800; text-align: center; }
  .week-print th.colitem { width: 21%; text-align: left; }
  .week-print td.colitem { font-weight: 700; }
  .week-print td.colitem .pw { font-weight: 600; color: #6b665d; font-size: 10.5px; display: block; }
  .week-print td.occ { text-align: center; }
  .week-print td.noocc { background: #f4f1ea; }
  .week-print .kindrow td { background: #e8e2d6; font-weight: 800; font-size: 11.5px; text-transform: uppercase; letter-spacing: .5px; }
  .pbox {
    display: inline-flex; align-items: center; justify-content: center;
    width: 15px; height: 15px; border: 1.6px solid var(--pc, #33302b); border-radius: 4px;
    font-size: 10px; font-weight: 900; color: var(--pc, #33302b); margin: 0 2px; vertical-align: middle;
  }
  .pbox.done { background: var(--pc, #33302b); color: #fff; }
  .pbox-ini { font-size: 9.5px; font-weight: 800; color: var(--pc, #33302b); margin-right: 4px; }

  /* Month: full-page calendar grid */
  .month-grid { gap: 0; border: 1.5px solid #33302b; }
  .mg-head { border: .5px solid #b9b2a5; background: #f1ece3; color: #33302b; padding: 5px 0; font-size: 11px; }
  .mg-cell {
    border: .5px solid #b9b2a5; border-radius: 0; box-shadow: none;
    min-height: 88px; padding: 3px 4px; break-inside: avoid;
  }
  .mg-cell.out { background: #f4f1ea; }
  .mg-cell.is-today .dnum { background: none; color: #33302b; text-decoration: underline; }
  .mg-cell .dnum { font-size: 11px; height: auto; width: auto; }
  .mg-chips { gap: 1px 6px; }
  .mchip { background: none; padding: 0; font-size: 10px; max-width: 100%; }
  .mchip .mtitle, .mchip .mbox { display: inline-flex; }
  .mchip .mtitle { font-weight: 600; }
  .mchip .mbox { width: 10px; height: 10px; min-width: 10px; font-size: 7px; }
}
