/*
VOICE: dụng cụ làm việc, gọn như app Camera/Ảnh mặc định của iPhone.
IDEA: một cuốn album công việc tách riêng, mở ra là thấy ảnh, chạm tab là chụp.
PICTURE: lưới ảnh vuông sát nhau; màn hình chụp đen toàn khung với nút chụp tròn.
COLOUR and TYPE: đen tuyền, chữ trắng, vàng camera #ffd60a cho chế độ đang chọn, xanh iOS #0a84ff cho hành động; font hệ thống.
LAYOUT: hai tab dưới cùng; camera chiếm trọn màn hình phía trên thanh tab.
*/
:root {
  color-scheme: dark;
  --bg: #000; --panel: #1c1c1e; --panel2: #2c2c2e; --line: #38383a;
  --text: #fff; --muted: #8e8e93; --accent: #0a84ff; --yellow: #ffd60a; --danger: #ff453a;
  --st: env(safe-area-inset-top); --sb: env(safe-area-inset-bottom);
  --tab: calc(54px + var(--sb));
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; min-width: 0; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font-size: 16px; line-height: 1.4; min-height: 100dvh; overscroll-behavior: none; -webkit-user-select: none; user-select: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:focus-visible, label:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
input, select, textarea { font-size: 16px; background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%; -webkit-user-select: text; user-select: text; }
select { width: auto; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

[hidden] { display: none !important; }
.screen { display: none; }
body[data-tab="photos"] .photos { display: block; }
body[data-tab="camera"] .camera { display: flex; }

/* ---------- tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; height: var(--tab);
  display: grid; grid-template-columns: 1fr 1fr; padding-bottom: var(--sb);
  background: rgba(22,22,24,.92); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border-top: .5px solid var(--line);
}
.tabbar button { background: none; border: 0; display: grid; justify-items: center; align-content: center; gap: 2px; color: var(--muted); font-size: 11px; font-weight: 600; }
.tabbar button.on { color: var(--accent); }
body[data-tab="camera"] .tabbar { background: #000; }
body[data-tab="camera"] .tabbar button.on { color: var(--yellow); }

/* ---------- Work Photos ---------- */
.photos { padding: calc(var(--st) + 8px) 0 calc(var(--tab) + 70px); }
.lib-head { display: flex; align-items: flex-end; justify-content: space-between; padding: 6px 16px 10px; position: sticky; top: 0; z-index: 5;
  background: linear-gradient(#000 70%, rgba(0,0,0,0)); }
.lib-head h1 { margin: 0; font-size: 34px; line-height: 1.1; font-weight: 800; letter-spacing: -.02em; }
.lib-head p { margin: 2px 0 0; color: var(--muted); font-size: 13px; min-height: 18px; }
.pill { background: var(--panel2); border: 0; border-radius: 999px; padding: 7px 16px; font-weight: 600; font-size: 15px; min-height: 34px; }
.day { margin: 18px 16px 8px; font-size: 17px; font-weight: 700; }
.day::first-letter { text-transform: uppercase; }
.tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 2px; }
@media (min-width: 600px) { .tiles { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); } }
.tile { position: relative; aspect-ratio: 1; padding: 0; border: 0; background: var(--panel); overflow: hidden; display: block; }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile .dur { position: absolute; right: 5px; bottom: 4px; font-size: 12px; font-weight: 600; text-shadow: 0 1px 3px rgba(0,0,0,.8); }
.tile .mark { position: absolute; left: 5px; bottom: 5px; display: grid; place-items: center; width: 20px; height: 20px; border-radius: 6px; background: rgba(0,0,0,.55); font-size: 12px; font-weight: 800; }
.tile .mark.note { left: auto; right: 5px; top: 5px; bottom: auto; }
.tile .check { display: none; position: absolute; right: 6px; bottom: 6px; width: 24px; height: 24px; border-radius: 50%; border: 2px solid #fff; background: rgba(0,0,0,.25); }
.selecting .tile .check { display: block; }
.selecting .tile .mark, .selecting .tile .dur { display: none; }
.tile.sel::after { content: ""; position: absolute; inset: 0; background: rgba(255,255,255,.25); }
.tile.sel .check { background: var(--accent); border-color: #fff; }
.tile.sel .check::after { content: ""; position: absolute; left: 7px; top: 3px; width: 6px; height: 11px; border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg); }
.empty { display: grid; justify-items: center; gap: 10px; text-align: center; padding: 18vh 32px 0; color: var(--muted); }
.empty b { color: var(--text); font-size: 20px; }
.empty span { max-width: 34ch; }

.selbar { position: fixed; left: 0; right: 0; bottom: var(--tab); z-index: 21; display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px; background: rgba(22,22,24,.96); border-top: .5px solid var(--line); font-weight: 600; }
.icon-btn { background: none; border: 0; width: 48px; height: 44px; display: grid; place-items: center; color: var(--accent); border-radius: 10px; }
.icon-btn.danger { color: var(--danger); }
.icon-btn:disabled { opacity: .35; }

/* ---------- Camera ---------- */
.camera { position: fixed; left: 0; right: 0; top: 0; bottom: var(--tab); flex-direction: column; background: #000; }
.cam-top { height: calc(var(--st) + 48px); padding: var(--st) 12px 0; display: flex; align-items: center; justify-content: space-between; }
.cam-top .spacer { width: 40px; }
.round { width: 40px; height: 40px; border-radius: 50%; border: 0; background: rgba(255,255,255,.12); display: grid; place-items: center; }
.round.on { color: var(--yellow); }
.round.big { width: 48px; height: 48px; }
.rec { display: none; align-items: center; gap: 6px; background: var(--danger); padding: 3px 10px; border-radius: 6px; font-variant-numeric: tabular-nums; font-weight: 600; }
.rec i { width: 8px; height: 8px; border-radius: 50%; background: #fff; }
.recording .rec { display: inline-flex; }
.cam-view { position: relative; flex: 1; min-height: 0; overflow: hidden; background: #0b0b0b; touch-action: none; }
.cam-view video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.cam-view video.mirror { transform: scaleX(-1); }
#flash { position: absolute; inset: 0; background: #000; opacity: 0; pointer-events: none; }
#flash.go { animation: shot .22s ease-out; }
@keyframes shot { 0% { opacity: .9; } 100% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { #flash.go { animation: none; } }
.zoom { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); display: flex; gap: 6px; padding: 4px; border-radius: 999px; background: rgba(0,0,0,.35); }
.zoom:empty { display: none; }
.zoom button { width: 36px; height: 36px; border-radius: 50%; border: 0; background: rgba(0,0,0,.5); font-size: 12px; font-weight: 700; }
.zoom button.on { color: var(--yellow); width: 42px; height: 42px; margin: -3px 0; font-size: 13px; }
.fallback { position: absolute; inset: 0; display: grid; align-content: center; justify-items: center; gap: 12px; padding: 24px; text-align: center; color: var(--muted); background: #111; }
.fallback p { max-width: 34ch; margin: 0 0 6px; }
.fallback .btn { width: min(100%, 320px); }
.modes { display: flex; justify-content: center; gap: 22px; padding: 12px 0 4px; }
.modes button { background: none; border: 0; font-size: 13px; font-weight: 600; letter-spacing: .06em; color: #fff; padding: 6px 4px; min-height: 32px; }
.modes button.on { color: var(--yellow); }
.recording .modes, .recording .tabbar, .recording #lastThumb, .recording #flipBtn { opacity: .25; pointer-events: none; }
.cam-bottom { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 10px 28px 16px; }
.last { justify-self: start; width: 48px; height: 48px; border-radius: 8px; border: 1.5px solid rgba(255,255,255,.7); background: #1c1c1e; padding: 0; overflow: hidden; }
.last img { width: 100%; height: 100%; object-fit: cover; display: block; }
.last:disabled { opacity: .5; }
#flipBtn { justify-self: end; }
.shutter { width: 76px; height: 76px; border-radius: 50%; border: 4px solid #fff; background: transparent; display: grid; place-items: center; padding: 0; }
.shutter span { width: 62px; height: 62px; border-radius: 50%; background: #fff; transition: all .2s; }
.shutter:active span { transform: scale(.9); }
body[data-mode="video"] .shutter span { background: var(--danger); }
.recording .shutter span { width: 30px; height: 30px; border-radius: 7px; }

/* ---------- xem ảnh ---------- */
.viewer { position: fixed; inset: 0; z-index: 30; background: #000; display: flex; flex-direction: column; }
.viewer[hidden] { display: none; }
.v-top { display: flex; align-items: center; gap: 8px; padding: calc(var(--st) + 6px) 8px 6px; }
.v-top span { flex: 1; text-align: right; font-size: 14px; font-weight: 600; padding-right: 8px; }
.v-back { background: none; border: 0; color: var(--accent); display: flex; align-items: center; gap: 2px; font-size: 17px; min-height: 44px; }
.v-stage { flex: 1; min-height: 0; display: grid; place-items: center; overflow: hidden; touch-action: none; }
.v-stage .media { max-width: 100%; max-height: 100%; display: block; transition: transform .12s; transform-origin: center; }
.v-stage video { max-width: 100%; max-height: 100%; width: 100%; touch-action: auto; }
.v-note { margin: 0 12px 6px; padding: 8px 12px; border-radius: 10px; background: var(--panel); font-size: 15px; max-height: 6.5em; overflow: auto; -webkit-user-select: text; user-select: text; white-space: pre-wrap; }
.v-bottom { display: flex; justify-content: space-around; padding: 6px 8px calc(var(--sb) + 8px); }

/* ---------- hộp thoại & thông báo ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 0 16px; border-radius: 12px;
  border: 0; background: var(--panel2); font-weight: 600; white-space: nowrap; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.row { display: flex; gap: 8px; align-items: center; margin-top: 12px; }
.row.end { justify-content: flex-end; }
dialog#modal { border: 0; border-radius: 16px; background: var(--panel); color: var(--text); width: min(92vw, 420px); padding: 0; }
dialog::backdrop { background: rgba(0,0,0,.6); }
.modal-body { padding: 18px; max-height: 82vh; overflow: auto; }
.modal-body h3 { margin: 0 0 10px; font-size: 17px; }
.modal-body p { margin: 0 0 8px; }
.sheet { display: grid; gap: 6px; }
.previews { display: grid; gap: 8px; max-height: 50vh; overflow: auto; }
.previews img, .previews video { width: 100%; border-radius: 10px; display: block; -webkit-user-select: auto; user-select: auto; -webkit-touch-callout: default; }
#toast { position: fixed; left: 50%; bottom: calc(var(--tab) + 120px); transform: translate(-50%, 16px); opacity: 0; z-index: 60;
  background: rgba(240,240,245,.96); color: #000; padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 500;
  pointer-events: none; transition: .25s; max-width: 88vw; text-align: center; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- trình chỉnh sửa (dùng lại từ editor.js) ---------- */
#editorRoot[hidden] { display: none; }
.ed { position: fixed; inset: 0; display: flex; flex-direction: column; background: #000; z-index: 40; }
.ed-top { display: flex; align-items: center; gap: 8px; padding: calc(var(--st) + 6px) 8px 6px; background: var(--panel); }
.ed-top .btn { min-height: 38px; padding: 0 14px; border: 0; }
.ed-status { flex: 1; font-size: 12px; color: var(--muted); text-align: center; line-height: 1.3; }
.ed-stage { flex: 1; position: relative; overflow: hidden; touch-action: none; }
.ed-stage canvas { position: absolute; inset: 0; touch-action: none; }
.ed-sub { display: flex; justify-content: space-between; align-items: center; padding: 6px 8px; background: var(--panel); border-top: .5px solid var(--line); }
.ed-colors { display: flex; gap: 6px; }
.sw { width: 24px; height: 24px; flex: none; border-radius: 50%; border: 2px solid var(--line); padding: 0; }
.sw.on { outline: 3px solid var(--accent); outline-offset: 1px; }
.ed-actions { display: flex; }
.icon { background: none; border: 0; border-radius: 10px; min-width: 34px; height: 40px; font-size: 18px; }
.icon:disabled { opacity: .3; }
.ed-tools { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); background: var(--panel); padding: 4px 4px calc(var(--sb) + 6px); }
.tool { background: none; border: 0; border-radius: 10px; display: grid; justify-items: center; gap: 1px; padding: 6px 0; color: var(--muted); }
.tool span { font-size: 20px; line-height: 1.2; }
.tool small { font-size: 10px; }
.tool.on { color: var(--text); background: var(--panel2); }
