:root {
  --cocoa: #3b2a2e;
  --cream: #fdf0ee;
  --paper: #fffaf8;
  --rose: #e0849a;
  --rose-deep: #c96d84;
  --soft: #8a6a70;
  --line: rgba(59, 42, 46, .12);
  --dur: 320ms;
  /* fallback first; browsers without linear() keep the cubic */
  --ease: cubic-bezier(.2, .7, .2, 1);
  --ease: linear(0, .015, .06 2.5%, .134 5.2%, .234 8.2%, .354 11.6%, .488 15.4%, .627 19.8%, .76 25%, .867 31.4%, .938 38.6%, .978 47.4%, .995 58.6%, 1 100%);
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--paper); color: var(--cocoa); }
body {
  font: 16px/1.35 -apple-system, "SF Pro Text", "Helvetica Neue", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}
button, input, textarea, label { font: inherit; color: inherit; }
button { touch-action: manipulation; background: none; border: 0; padding: 0; cursor: pointer; }
img { display: block; user-select: none; -webkit-user-drag: none; }
.sr-only { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; pointer-events: none; }
[hidden] { display: none !important; }
.ico { display: inline-flex; width: 24px; height: 24px; flex: none; }
.ico svg { width: 100%; height: 100%; }
.ico.big { width: 40px; height: 40px; }

/* surfaces: squircle over a radius fallback */
.sq { border-radius: 20px; }
@supports (corner-shape: squircle) {
  .sq { corner-shape: squircle; border-radius: 24px; }
}

/* header + tabs */
.top {
  position: sticky; top: 0; z-index: 4; background: var(--paper);
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 8px) 16px 8px;
  min-height: 56px;
}
.brand { font-weight: 650; font-size: 18px; letter-spacing: .01em; }
.status { display: inline-flex; width: 44px; height: 44px; align-items: center; justify-content: center; color: var(--soft); }
.status.err { color: var(--rose-deep); }
.status.busy .ico { animation: spin 1s linear infinite; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 4;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--paper); border-top: 1px solid var(--line);
  padding: 4px 8px calc(env(safe-area-inset-bottom) + 4px);
}
.tab {
  min-height: 56px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 12px; color: var(--soft); border-radius: 16px;
}
.tab[aria-current="page"] { color: var(--cocoa); font-weight: 650; }
.tab[aria-current="page"] .ico { color: var(--rose-deep); }

main.content { padding: 8px 12px calc(96px + env(safe-area-inset-bottom)); }

/* grids and tiles */
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 720px) { .grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 1000px) { .grid { grid-template-columns: repeat(4, 1fr); } }

.tile {
  position: relative; overflow: hidden; aspect-ratio: 3 / 4;
  background: var(--cream);
  transition: transform var(--dur) var(--ease);
}
.tile img { width: 100%; height: 100%; object-fit: cover; }
.tile.add {
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--line); background: transparent; color: var(--cocoa);
}
.tile.add .ico { width: 36px; height: 36px; }
.tile.lifted { z-index: 3; transition: none; outline: 2px solid var(--cocoa); outline-offset: -2px; }
.tile.busy img { opacity: .45; }
.tile .state { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--cocoa); }
.tile .state .ico { width: 36px; height: 36px; }
.tile .state.spin .ico { animation: spin 1s linear infinite; }
.tile.fail .state { background: rgba(255, 250, 248, .6); }

.chip {
  position: absolute; width: 48px; height: 48px; z-index: 2;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255, 250, 248, .94); color: var(--cocoa);
  border: 1px solid var(--line); border-radius: 16px;
}
@supports (corner-shape: squircle) { .chip { corner-shape: squircle; } }
.chip.handle { top: 6px; left: 6px; touch-action: none; cursor: grab; }
.chip.del, .chip.br { bottom: 6px; right: 6px; }
.chip.top-r { top: 6px; right: 6px; }

.btn {
  min-height: 52px; padding: 0 20px; border-radius: 16px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-weight: 600; white-space: nowrap;
}
.btn.primary { background: var(--cocoa); color: var(--paper); }
.btn.ghost { border: 1px solid var(--line); color: var(--cocoa); }
.btn:disabled { opacity: .4; }

/* toast */
.toast {
  position: fixed; left: 12px; right: 12px; z-index: 5;
  bottom: calc(env(safe-area-inset-bottom) + 76px);
  max-width: 480px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 8px 8px 16px; min-height: 56px;
  background: var(--cocoa); color: var(--paper); border-radius: 18px;
}
.toast .act {
  min-height: 44px; padding: 0 14px; display: inline-flex; align-items: center; gap: 6px;
  border-radius: 14px; color: var(--paper); border: 1px solid rgba(255, 250, 248, .35); font-weight: 600;
}

/* menus and notice */
.menus .tile img { object-fit: contain; background: var(--cream); }
.notice { display: grid; gap: 14px; }
.notice textarea, .notice input[type="date"] {
  width: 100%; font-size: 16px; padding: 14px; border-radius: 18px;
  border: 1px solid var(--line); background: #fff; color: var(--cocoa);
}
.notice textarea { resize: vertical; min-height: 96px; }
.notice input[type="date"] { min-height: 52px; }
.field { display: flex; align-items: center; gap: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip-txt {
  min-height: 44px; padding: 0 16px; border-radius: 14px; border: 1px solid var(--line);
  font-weight: 600; background: #fff;
}
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row .btn.primary { flex: 1 1 200px; }
.thumb { position: relative; width: 100%; max-width: 260px; aspect-ratio: 4 / 3; border-radius: 18px; overflow: hidden; background: var(--cream); }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.live { display: flex; align-items: center; gap: 8px; color: var(--soft); min-height: 32px; }
.live[data-state="on"] { color: var(--cocoa); }
.live .ico { color: var(--rose-deep); }

/* live preview (approximate 16:9 TV) */
.tv {
  position: relative; width: 100%; aspect-ratio: 16 / 9; overflow: hidden;
  background: var(--cream); border-radius: 20px;
}
@supports (corner-shape: squircle) { .tv { corner-shape: squircle; } }
.tv-grid {
  position: absolute; inset: 8px; display: grid; gap: 8px;
  grid-template-columns: 2fr 1fr 1fr; grid-template-rows: 1fr 1fr;
}
.tv-grid img { width: 100%; height: 100%; object-fit: cover; border-radius: 14px; min-height: 0; }
.tv-grid img.big { grid-row: span 2; }
.tv-grid img.menu { object-fit: contain; background: #fff; }
.tv-notice {
  position: absolute; left: 16px; right: 16px; bottom: 16px;
  display: flex; align-items: center; gap: 8px;
  background: var(--cocoa); color: var(--paper); border-radius: 16px; padding: 10px 14px; font-size: 15px;
}
.tv-notice .ico { color: var(--rose); }

/* login */
.login-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login { width: min(100%, 340px); display: grid; gap: 14px; justify-items: center; }
.login .ico { color: var(--rose-deep); }
.login input {
  width: 100%; min-height: 56px; font-size: 18px; padding: 0 16px; border-radius: 18px;
  border: 1px solid var(--line); background: #fff;
}
.login .btn { width: 100%; }
.err { display: flex; align-items: center; gap: 8px; margin: 0; color: var(--rose-deep); font-weight: 600; min-height: 24px; }

@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
