:root {
  --accent: #2FB67C; --accent-soft: #DFF5E9; --bg: #F6F7F9; --card: #FFFFFF; --text: #1D1D22;
  --muted: #6B7280; --line: #E5E7EB; --danger: #E5484D; --today: #2FB67C; --chip-text: #1D1D22;
  --radius: 14px; --shadow: 0 1px 3px rgba(0,0,0,.06), 0 8px 24px rgba(0,0,0,.04);
}
:root[data-mode="dark"] { --bg: #0F1012; --card: #1A1B1F; --text: #F3F4F6; --muted: #9CA3AF;
  --line: #2B2D33; --chip-text: #F3F4F6; --shadow: none; color-scheme: dark; }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.4 ui-rounded, -apple-system, "SF Pro Rounded", system-ui, sans-serif; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); min-height: 1.2em; margin: 4px 0; font-size: 13px; }
button { font: inherit; cursor: pointer; border: none; border-radius: 10px; padding: 8px 14px; background: transparent; color: var(--text); }
button.primary { background: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover { filter: brightness(1.05); }
button.ghost { background: transparent; border: 1px solid var(--line); }
button.danger { color: var(--danger); }
button.link { color: var(--accent); padding: 6px; }
button.icon { font-size: 22px; line-height: 1; padding: 4px 12px; border: 1px solid var(--line); }
input, select, textarea { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line);
  border-radius: 10px; padding: 9px 11px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
label { display: block; font-size: 13px; color: var(--muted); }
label input, label select, label textarea { margin-top: 4px; }
label.row { display: flex; gap: 8px; align-items: center; color: var(--text); font-size: 14px; }
label.row input { width: auto; }

/* Sign in */
.auth { min-height: 100%; display: grid; place-items: center; padding: 24px 16px;
  background: linear-gradient(180deg, var(--accent-soft), var(--bg)); }
.auth-card { background: var(--card); border-radius: 22px; padding: 28px 24px; width: 100%; max-width: 380px; text-align: center; box-shadow: var(--shadow); }
.auth-logo { width: 72px; height: 72px; }
.auth-card h1 { margin: 8px 0 4px; }
.auth-card form { display: grid; gap: 10px; margin-top: 18px; text-align: left; }
.auth-card button.primary { width: 100%; padding: 11px; }

/* Top bar */
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 16px; padding: 10px 16px;
  background: color-mix(in srgb, var(--card) 88%, transparent); backdrop-filter: blur(12px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 17px; }
.brand img { width: 30px; height: 30px; }
.tabs { display: flex; gap: 4px; margin: 0 auto; background: var(--bg); padding: 4px; border-radius: 12px; }
.tab { padding: 7px 14px; border-radius: 9px; color: var(--muted); font-weight: 600; position: relative; }
.tab.active { background: var(--card); color: var(--text); box-shadow: var(--shadow); }
.badge { background: var(--danger); color: #fff; border-radius: 999px; font-size: 11px; padding: 1px 6px; margin-left: 4px; }
.topuser { display: flex; align-items: center; gap: 10px; font-size: 13px; }
@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; }
  .topuser #user-email { display: none; }
  .tabs { order: 3; width: 100%; justify-content: center; }
  .tab { flex: 1; }
}

.tab-page { padding: 16px; max-width: 1280px; margin: 0 auto; }

/* Calendar */
.cal-toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.cal-toolbar .nav, .cal-toolbar .right { display: flex; gap: 8px; align-items: center; }
.cal-toolbar h2 { margin: 0 0 0 8px; font-size: 22px; }
.segmented { display: inline-flex; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.segmented button { padding: 6px 12px; border-radius: 8px; color: var(--muted); }
.segmented button.active { background: var(--accent); color: #fff; }
.segmented.small button { padding: 5px 12px; font-size: 14px; }
.cal-body { display: grid; grid-template-columns: 1fr 320px; gap: 16px; }
@media (max-width: 960px) { .cal-body { grid-template-columns: 1fr; } }
.cal-view { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.day-panel { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; align-self: start; }
.day-panel h3 { margin: 0 0 10px; }

.month { display: grid; grid-template-columns: repeat(7, 1fr); }
.month .wd { padding: 8px; font-size: 12px; font-weight: 700; color: var(--muted); text-align: center; border-bottom: 1px solid var(--line); }
.month .cell { min-height: 108px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 4px; cursor: pointer; overflow: hidden; }
.month .cell:nth-child(7n) { border-right: none; }
.month .cell.out { background: color-mix(in srgb, var(--bg) 60%, transparent); }
.month .cell.out .num { color: var(--muted); }
.month .cell.selected { background: var(--accent-soft); }
.month .num { font-size: 13px; font-weight: 600; width: 24px; height: 24px; display: grid; place-items: center; border-radius: 50%; margin-bottom: 2px; }
.month .cell.today .num { background: var(--today); color: #fff; }
@media (max-width: 720px) { .month .cell { min-height: 64px; } .chip .t { display: none; } }
.chip { display: flex; gap: 4px; align-items: center; font-size: 11.5px; padding: 1px 5px; border-radius: 5px; margin: 1px 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--chip-text); }
.chip.allday { color: #fff; }
.chip .t { color: var(--muted); }
.more { font-size: 11px; color: var(--muted); padding-left: 4px; }

.week { display: grid; grid-template-columns: 52px repeat(7, 1fr); position: relative; }
.week .head { position: sticky; top: 0; background: var(--card); padding: 8px 4px; text-align: center; font-size: 12px; font-weight: 700; color: var(--muted); border-bottom: 1px solid var(--line); z-index: 1; }
.week .head.today { color: var(--today); }
.week .head .d { display: block; font-size: 18px; color: var(--text); }
.week .head.today .d { color: var(--today); }
.week .alldayrow { grid-column: 1 / -1; display: grid; grid-template-columns: 52px repeat(7, 1fr); border-bottom: 1px solid var(--line); min-height: 6px; }
.week .hours { grid-column: 1 / -1; display: grid; grid-template-columns: 52px repeat(7, 1fr); height: 1088px; overflow: hidden; }
.week .times div { height: 64px; font-size: 11px; color: var(--muted); text-align: right; padding-right: 6px; transform: translateY(-7px); }
.week .col { position: relative; border-left: 1px solid var(--line);
  background-image: repeating-linear-gradient(to bottom, transparent 0 63px, var(--line) 63px 64px); }
.block { position: absolute; left: 3px; right: 3px; border-radius: 7px; padding: 3px 6px; font-size: 12px; overflow: hidden; cursor: pointer; color: var(--chip-text); }
.block b { display: block; font-weight: 600; }
.nowline { position: absolute; left: 0; right: 0; height: 2px; background: var(--danger); z-index: 2; }

.agenda { padding: 6px 14px; }
.agenda h4 { margin: 16px 0 6px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.item { display: flex; gap: 10px; align-items: center; padding: 8px; border-radius: 10px; cursor: pointer; }
.item:hover { background: var(--bg); }
.bar { width: 4px; align-self: stretch; border-radius: 2px; }
.item .meta { font-size: 12px; color: var(--muted); }
.empty { color: var(--muted); padding: 20px 8px; text-align: center; }

/* To-do */
.todo-wrap { max-width: 720px; margin: 0 auto; }
.todo-add { display: grid; grid-template-columns: 1fr 150px 110px auto; gap: 8px; background: var(--card); padding: 10px; border-radius: var(--radius); box-shadow: var(--shadow); }
@media (max-width: 620px) { .todo-add { grid-template-columns: 1fr 1fr; } .todo-add #todo-title { grid-column: 1 / -1; } }
.todo-group { margin-top: 18px; }
.todo-group h4 { margin: 0 0 6px 4px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.todo-group.overdue h4 { color: var(--danger); }
.todo { display: flex; align-items: center; gap: 12px; background: var(--card); padding: 11px 12px; border-radius: 12px; margin-bottom: 6px; box-shadow: var(--shadow); }
.todo .check { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--accent); flex: none; padding: 0; display: grid; place-items: center; color: #fff; }
.todo.done .check { background: var(--accent); }
.todo.done .title { text-decoration: line-through; color: var(--muted); }
.todo .body { flex: 1; cursor: pointer; }
.todo .due { font-size: 12px; color: var(--muted); }
.todo .due.late { color: var(--danger); }
.prio { width: 8px; height: 8px; border-radius: 50%; }

/* Chat */
.chat-wrap { max-width: 720px; margin: 0 auto; background: var(--card); border-radius: 20px; box-shadow: var(--shadow); display: flex; flex-direction: column; height: calc(100vh - 110px); min-height: 420px; }
.chat-head { display: flex; gap: 10px; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.chat-panda { width: 38px; height: 38px; }
.chat-log { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 78%; padding: 10px 14px; border-radius: 18px; white-space: pre-wrap; }
.msg.panda { background: var(--bg); align-self: flex-start; border-bottom-left-radius: 6px; }
.msg.user { background: var(--accent); color: #fff; align-self: flex-end; border-bottom-right-radius: 6px; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 6px 12px; }
.chips button { background: var(--accent-soft); color: var(--accent); font-size: 13px; white-space: nowrap; border-radius: 999px; padding: 6px 12px; }
.chat-form { display: flex; gap: 8px; padding: 10px 12px 12px; border-top: 1px solid var(--line); }

/* Dialogs */
dialog { border: none; border-radius: 18px; padding: 0; width: min(520px, calc(100vw - 24px)); background: var(--card); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(0,0,0,.35); }
dialog form, dialog .info { display: grid; gap: 12px; padding: 20px; }
dialog h3 { margin: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.dialog-actions { display: flex; gap: 8px; align-items: center; margin-top: 4px; }
.spacer { flex: 1; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.swatches button { display: flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 999px; border: 1px solid var(--line); font-size: 13px; }
.swatches button.active { border-color: var(--text); font-weight: 600; }
.swatches .dot { width: 12px; height: 12px; border-radius: 50%; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--text); color: var(--card); padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 20; }

/* Wallpaper behind everything */
#wallpaper { position: fixed; inset: 0; z-index: -1; pointer-events: none; }
body { background: var(--bg); }
#app .tab-page { position: relative; }
.center { text-align: center; }

/* Opening screen */
#splash { position: fixed; inset: 0; background: #000; display: grid; place-items: center; z-index: 50; transition: opacity .15s ease-out; }
#splash.gone { opacity: 0; pointer-events: none; }
.splash-card { position: relative; width: 112px; height: 104px; border-radius: 18px; overflow: visible; animation: splashIn .25s ease-out both; }
.splash-head { height: 24px; background: #2C2C34; border-radius: 18px 18px 0 0; }
.splash-page { position: relative; height: 80px; background: #fff; border-radius: 0 0 18px 18px; overflow: hidden; perspective: 300px; }
.splash-panda { position: absolute; left: 50%; top: 50%; width: 70px; height: 70px; transform: translate(-50%, -48%) scale(.85); opacity: 0; transition: all .35s cubic-bezier(.3,1.6,.6,1) .12s; }
.splash-flip { position: absolute; inset: 0; background: #fff; display: grid; place-items: center; align-content: center; transform-origin: top; }
.splash-flip small { color: #FF6B6B; font-weight: 800; font-size: 10px; letter-spacing: .05em; }
.splash-flip b { font-size: 40px; line-height: 1; color: #23232B; }
.splash-rings { position: absolute; top: -8px; left: 0; right: 0; display: flex; justify-content: center; gap: 54px; z-index: 2; }
.splash-rings span { width: 9px; height: 20px; border-radius: 5px; background: #8A8A96; }
#splash.flip .splash-flip { animation: pageFlip .22s ease-in forwards; }
#splash.flip .splash-panda { opacity: 1; transform: translate(-50%, -48%) scale(1); }
@keyframes splashIn { from { opacity: 0; transform: scale(.85); } to { opacity: 1; transform: none; } }
@keyframes pageFlip { to { transform: rotateX(-110deg); opacity: 0; } }

/* Floating Panda */
#float-panda { position: fixed; right: 22px; bottom: 22px; width: 64px; height: 64px; border-radius: 50%; padding: 0;
  background: var(--accent-soft); box-shadow: 0 6px 18px rgba(0,0,0,.2); display: grid; place-items: center; z-index: 8;
  transition: transform .2s cubic-bezier(.3,1.6,.6,1); }
#float-panda:hover { transform: scale(1.08) rotate(-4deg); }
#float-panda img { width: 52px; height: 52px; }

/* Insights */
.insights, .settings { max-width: 760px; margin: 0 auto; display: grid; gap: 14px; }
.week-nav { display: flex; align-items: center; justify-content: space-between; }
.motivation { display: flex; gap: 14px; align-items: center; background: var(--accent-soft); border-radius: 18px; padding: 16px; }
.motivation img { width: 64px; height: 64px; flex: none; }
.motivation .who { color: var(--accent); font-weight: 700; font-size: 12px; }
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.tile { background: var(--card); border-radius: 16px; padding: 14px; box-shadow: var(--shadow); text-align: left; cursor: pointer; }
.tile.active { outline: 2px solid var(--accent); }
.tile .v { font-size: 26px; font-weight: 800; }
.tile .l { font-size: 12px; color: var(--muted); }
.tile .i { color: var(--accent); font-size: 18px; }
.card { background: var(--card); border-radius: 18px; padding: 16px; box-shadow: var(--shadow); }
.card h3 { margin: 0 0 10px; font-size: 16px; }
.card h4 { margin: 16px 0 8px; font-size: 13px; color: var(--muted); }
#ins-graph { width: 100%; height: 240px; }

/* Settings */
.theme-row { display: flex; flex-wrap: wrap; gap: 12px; }
.theme-row button { display: grid; justify-items: center; gap: 4px; padding: 4px; font-size: 11px; color: var(--muted); }
.theme-row .sw { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 800; }
.theme-row button.active { color: var(--text); }
.theme-row button.active .sw { box-shadow: 0 0 0 3px var(--card), 0 0 0 5px currentColor; }
.wall-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 12px; }
.wall-grid button { display: grid; gap: 6px; padding: 0; font-size: 12px; color: var(--muted); }
.wall-grid canvas { width: 100%; aspect-ratio: 0.58; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); }
.wall-grid button.active canvas { border: 3px solid var(--accent); }
.wall-grid button.active { color: var(--text); font-weight: 600; }

/* Let the wallpaper show through the calendar, like the app */
.cal-view, .day-panel { background: color-mix(in srgb, var(--card) 82%, transparent); backdrop-filter: blur(3px); }
.week .head { background: color-mix(in srgb, var(--card) 92%, transparent); }
.week .hours { padding-top: 8px; }

/* Play with Panda: sticky notes like the app */
.play h3 { margin: 6px 4px 12px; font-size: 16px; }
.notes { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; padding: 8px 4px; }
.note { position: relative; text-align: left; display: grid; gap: 4px; padding: 26px 16px 18px; border-radius: 2px;
  font-family: "Noteworthy", "Chalkboard SE", "Marker Felt", "Comic Sans MS", cursive; color: #3A3A2E;
  box-shadow: 2px 6px 12px rgba(0,0,0,.18); transition: transform .15s; clip-path: polygon(0 0, 100% 0, 100% calc(100% - 22px), calc(100% - 22px) 100%, 0 100%); }
.note::after { content: ""; position: absolute; right: 0; bottom: 0; width: 22px; height: 22px;
  background: linear-gradient(135deg, rgba(0,0,0,.12), rgba(255,255,255,.4)); clip-path: polygon(0 0, 100% 0, 0 100%); }
.note.yellow { background: linear-gradient(#FFF4A8, #FFE98A); transform: rotate(-2.5deg); }
.note.mint { background: linear-gradient(#C9F2D6, #ADE8C2); transform: rotate(2deg); }
.note:hover { transform: rotate(0) scale(1.02); }
.note .tape { position: absolute; top: -8px; left: 50%; width: 60px; height: 18px; transform: translateX(-50%) rotate(3deg); background: rgba(255,255,255,.6); box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.note .art { display: flex; align-items: flex-end; justify-content: center; gap: 4px; height: 56px; position: relative; }
.note .art img { width: 40px; height: 40px; }
.note .knight { font-size: 38px; line-height: 1; color: #22222A; }
.note .ground { position: absolute; bottom: 0; left: 50%; width: 70px; height: 6px; border-radius: 3px; transform: translateX(-50%); background: #6FB36B; }
.note .ntitle { font-size: 20px; font-weight: 700; }
.note .nsub { font-size: 14px; opacity: .7; }

/* Game screens */
.game-overlay { position: fixed; inset: 0; z-index: 30; background: var(--bg); display: flex; flex-direction: column; }
.game-top { display: flex; align-items: center; gap: 12px; padding: 10px 14px; height: 56px; border-bottom: 1px solid var(--line); background: var(--card); }
.game-tools { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.runner { display: block; touch-action: none; cursor: pointer; }
.chess-wrap { flex: 1; overflow: auto; display: grid; justify-items: center; align-content: start; gap: 14px; padding: 16px;
  background: linear-gradient(var(--accent-soft), var(--bg) 40%); }
.chess-head { display: flex; align-items: center; gap: 12px; width: min(560px, 100%); }
.chess-head img { width: 52px; height: 52px; transition: transform .3s; }
.chess-head img.think { animation: wobble 1s ease-in-out infinite; }
.chess-head img.bounce { animation: pop .5s ease-out; }
.chess-head > div:nth-child(2) { flex: 1; }
.chess-score { display: flex; gap: 8px; }
.chess-score div { background: var(--card); border-radius: 10px; padding: 4px 10px; text-align: center; display: grid; min-width: 52px; }
.chess-score b { font-size: 17px; } .chess-score span { font-size: 11px; color: var(--muted); }
.chess-board { width: min(560px, 100%, calc(100vh - 200px)); aspect-ratio: 1; display: grid; grid-template-columns: repeat(8, 1fr);
  border-radius: 10px; overflow: hidden; box-shadow: 0 8px 24px rgba(0,0,0,.15); }
.sq { position: relative; padding: 0; border-radius: 0; display: grid; place-items: center; aspect-ratio: 1; }
.sq.light { background: #F1ECDD; } .sq.dark { background: color-mix(in srgb, var(--accent) 75%, #fff 0%); }
.sq.last::before { content: ""; position: absolute; inset: 0; background: rgba(255, 220, 0, .3); }
.sq.sel::before { content: ""; position: absolute; inset: 0; background: rgba(255, 220, 0, .5); }
.sq.check::before { content: ""; position: absolute; inset: 0; background: radial-gradient(rgba(229,72,77,.8), transparent 70%); }
.pc { position: relative; font-size: min(7.5vw, 52px); line-height: 1; }
.pc.w { color: #fff; text-shadow: 0 0 1px #000, 0 0 2px rgba(0,0,0,.7), 0 1px 2px rgba(0,0,0,.4); }
.pc.b { color: #22222A; text-shadow: 0 0 1px rgba(255,255,255,.35); }
.sq .dot { position: absolute; width: 30%; height: 30%; border-radius: 50%; background: rgba(0,0,0,.22); }
.sq .cap { position: absolute; inset: 5%; border-radius: 50%; border: 4px solid rgba(0,0,0,.28); }
.sq em { position: absolute; font-style: normal; font-size: 10px; font-weight: 700; color: rgba(0,0,0,.45); }
.sq .rank { top: 2px; left: 3px; } .sq .file { bottom: 1px; right: 3px; }
@keyframes wobble { 0%,100% { transform: rotate(-6deg); } 50% { transform: rotate(6deg); } }
@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.25); } 100% { transform: scale(1); } }

/* ---------- Tab icons ---------- */
.tab .ic { display: none; }
.tab .ic svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Phones: made like the iPhone app ---------- */
@media (max-width: 720px) {
  body { font-size: 16px; -webkit-tap-highlight-color: transparent; }
  .topbar { flex-wrap: nowrap; padding: calc(8px + env(safe-area-inset-top)) 14px 8px; gap: 8px; }
  .brand { font-size: 18px; }
  .topuser { display: none; }

  /* Bottom tab bar like iOS */
  .tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 9; margin: 0; width: auto; border-radius: 0; padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    background: color-mix(in srgb, var(--card) 92%, transparent); backdrop-filter: blur(16px); border-top: 1px solid var(--line); display: grid; grid-template-columns: repeat(5, 1fr); gap: 0; }
  .tab { display: grid; justify-items: center; gap: 2px; padding: 4px 0; border-radius: 10px; font-size: 10.5px; font-weight: 600; background: none !important; box-shadow: none !important; color: var(--muted); position: relative; }
  .tab .ic { display: block; height: 22px; }
  .tab.active { color: var(--accent); }
  .tab .badge { position: absolute; top: 0; left: 55%; margin: 0; font-size: 10px; padding: 0 5px; }
  .tab-page { padding: 12px 12px calc(84px + env(safe-area-inset-bottom)); }

  /* Calendar toolbar: title on top, buttons below */
  .cal-toolbar { gap: 8px; }
  .cal-toolbar .nav { width: 100%; }
  .cal-toolbar h2 { order: -1; flex: 1; margin: 0; font-size: 22px; }
  .cal-toolbar .nav button.icon { padding: 4px 10px; }
  .cal-toolbar .right { width: 100%; justify-content: space-between; }
  .segmented button { padding: 6px 10px; font-size: 14px; }
  .cal-body { gap: 12px; }

  .month .wd { padding: 6px 0; font-size: 11px; }
  .month .cell { min-height: 58px; padding: 2px; }
  .month .num { font-size: 13px; width: 24px; height: 24px; margin: 0 auto 2px; }
  .chip { font-size: 9.5px; padding: 0 3px; border-radius: 3px; }
  .more { font-size: 9px; text-align: center; padding: 0; }

  .week { grid-template-columns: 40px repeat(var(--days, 7), 1fr); }
  .week .alldayrow, .week .hours { grid-template-columns: 40px repeat(var(--days, 7), 1fr); }
  .week .times div { font-size: 10px; padding-right: 4px; }
  .block { font-size: 11px; padding: 2px 4px; }

  .day-panel { padding: 12px; }
  .todo-add { grid-template-columns: 1fr 1fr; }
  .tiles { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .tile { padding: 10px; } .tile .v { font-size: 22px; }
  #ins-graph { height: 200px; }
  .notes { gap: 14px; } .note { padding: 22px 12px 16px; } .note .ntitle { font-size: 17px; }

  .chat-wrap { height: calc(100dvh - 150px - env(safe-area-inset-bottom)); border-radius: 18px; }
  .msg { max-width: 85%; }

  #float-panda { right: 14px; bottom: calc(80px + env(safe-area-inset-bottom)); width: 54px; height: 54px; }
  #float-panda img { width: 44px; height: 44px; }

  /* Dialogs become bottom sheets */
  dialog { width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: 20px 20px 0 0; max-height: 92dvh; overflow-y: auto; }
  dialog form, dialog .info { padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); }
  .grid2 { grid-template-columns: 1fr; }
  input, select, textarea { font-size: 16px; min-width: 0; }   /* 16px stops iPhone zooming in */

  .settings .segmented { width: 100%; } .settings .segmented button { flex: 1; }
  .wall-grid { grid-template-columns: repeat(3, 1fr); }

  .game-top { padding-top: calc(10px + env(safe-area-inset-top)); height: auto; }
  .game-tools .segmented button { padding: 5px 8px; font-size: 13px; }
  .chess-head { flex-wrap: wrap; }
  .chess-board { width: min(100%, calc(100dvh - 230px)); }
  .pc { font-size: 9vw; }
}
input[type="datetime-local"], input[type="date"], input[type="time"] { min-width: 0; -webkit-appearance: none; appearance: none; }
dialog * { max-width: 100%; }
@media (max-width: 720px) {
  /* (a blurred top bar would trap the bottom tab bar inside it) */
  .topbar { backdrop-filter: none; -webkit-backdrop-filter: none; background: var(--card); }
  .cal-toolbar h2 { font-size: 20px; }
}

#ins-graph { height: auto !important; aspect-ratio: 700 / 240; }

/* Chat: your messages always visible */
.msg.user { background: var(--accent, #2FB67C); color: #fff; }
.msg { flex: none; }
@media (max-width: 720px) {
  /* On phones the chat grows with the page; the box to type in stays above the tab bar */
  .chat-wrap { height: auto; min-height: calc(100vh - 170px); }
  .chat-log { overflow: visible; flex: 1; }
  .chips { position: sticky; bottom: calc(130px + env(safe-area-inset-bottom)); background: var(--card); z-index: 2; }
  .chat-form { position: sticky; bottom: calc(68px + env(safe-area-inset-bottom)); background: var(--card); z-index: 2; border-radius: 0 0 18px 18px; }
}
