:root {
  --bg: #0d1624;
  --fg: #eaf4ff;
  --sub: #a9c2dc;
  --muted: #7d93ab;
  --accent: #00e5ff;
  --accent-rgb: 0, 229, 255;
  --accent-2: color-mix(in srgb, var(--accent) 60%, #fff);
  --on-accent: #06121c;
  --glass-a: .08;
  --danger: #f29a9a;
  --glass: rgba(255, 255, 255, var(--glass-a));
  --glass-2: rgba(255, 255, 255, calc(var(--glass-a) + .06));
  --line: rgba(255, 255, 255, .16);
  --radius: 18px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --font: "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", system-ui, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); color: var(--fg); background: var(--bg); overflow: hidden; font-size: 15px; }
#bg { position: fixed; inset: 0; z-index: -1; overflow: hidden; background: linear-gradient(160deg, #060a16 0%, #130f2b 55%, #07182a 100%); }
#bg::before, #bg::after { content: ''; position: absolute; inset: 0; pointer-events: none; }
#bg::before {
  background:
    radial-gradient(circle at 10% 10%, rgba(var(--accent-rgb), .38) 0, transparent 70%),
    radial-gradient(circle at 95% 88%, rgba(124, 77, 255, .40) 0, transparent 70%);
}
#bg-img { position: absolute; inset: 0; background-size: cover; background-repeat: no-repeat; opacity: var(--bg-opacity, .75); will-change: transform; }
#bg.has-img::after { background: linear-gradient(180deg, rgba(0, 0, 0, .25) 0%, rgba(0, 0, 0, .06) 45%, rgba(0, 0, 0, .44) 100%); }
[hidden] { display: none !important; }
a { color: var(--accent-2); }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.glass {
  background: var(--glass);
  border: 1px solid var(--line);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
}

/* ---- buttons ---- */
.btn {
  font: inherit; color: var(--fg); background: var(--glass-2); border: 1px solid var(--line);
  border-radius: 12px; padding: 9px 16px; cursor: pointer; text-decoration: none; display: inline-flex;
  align-items: center; justify-content: center; gap: 6px; transition: background .15s, transform .1s;
}
.btn:hover { background: rgba(255, 255, 255, .2); }
.btn:active { transform: scale(.97); }
.btn.primary { background: rgba(var(--accent-rgb), .92); color: var(--on-accent); border-color: rgba(255, 255, 255, .35); font-weight: 500; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 12px; font-size: 13px; border-radius: 10px; }
.btn.big { padding: 14px 26px; font-size: 16px; border-radius: 14px; }
.btn.full { width: 100%; }
.btn.danger { color: var(--danger); }
.btn.danger-bg { background: linear-gradient(135deg, #c96b6b, #a24f7a); }
.btn:disabled { opacity: .5; pointer-events: none; }
.icon-btn {
  background: none; border: none; color: var(--fg); width: 40px; height: 40px; border-radius: 12px;
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer; flex: none;
}
.icon-btn:hover { background: var(--glass-2); }
.icon-btn.active { color: var(--accent); }
.icon-btn.active svg { fill: rgba(var(--accent-rgb), .35); }
.icon-btn.danger:hover { color: var(--danger); }

/* ---- welcome ---- */
.screen { position: fixed; inset: 0; }
#welcome { display: flex; align-items: center; justify-content: center; padding: 24px; }
.welcome-card { max-width: 440px; width: 100%; border-radius: 26px; padding: 40px 30px; text-align: center; box-shadow: 0 20px 60px rgba(0, 0, 0, .35); }
.welcome-icon { width: 84px; height: 84px; border-radius: 22px; }
.welcome-card h1 { font-weight: 300; letter-spacing: .12em; margin: 14px 0 8px; }
.welcome-card p { color: var(--sub); line-height: 1.8; font-size: 14px; }
.fine { font-size: 12px; color: var(--muted); line-height: 1.7; }
.error { color: var(--danger); font-size: 13px; }

/* ---- main layout ---- */
#main { display: flex; flex-direction: column; padding: calc(var(--safe-t) + 10px) 10px calc(var(--safe-b) + 10px); gap: 10px; }
#topbar { display: flex; align-items: center; gap: 6px; border-radius: var(--radius); padding: 4px 8px; flex: none; }
.brand { font-weight: 300; letter-spacing: .14em; font-size: 17px; flex: 1; padding-left: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.pill {
  display: inline-flex; align-items: center; gap: 7px; font: inherit; font-size: 12px; color: var(--sub);
  background: var(--glass); border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px; cursor: pointer;
}
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.pill[data-state="ok"] .dot { background: #8fe0b0; }
.pill[data-state="syncing"] .dot { background: var(--accent); animation: pulse 1s infinite alternate; }
.pill[data-state="error"] .dot, .pill[data-state="auth"] .dot { background: var(--danger); }
.pill[data-state="offline"] .dot { background: #f2c97d; }
.pill[data-pending="1"] { color: #ffd98a; border-color: rgba(255, 196, 92, .6); background: rgba(255, 179, 0, .14); }
.pill[data-pending="1"] .dot { background: #ffb300; }
@keyframes pulse { to { opacity: .3; } }
.banner {
  display: flex; align-items: center; justify-content: center; gap: 12px; flex: none;
  background: rgba(242, 154, 154, .14); border: 1px solid rgba(242, 154, 154, .35); border-radius: 14px; padding: 8px 12px; font-size: 13px;
}

#layout { flex: 1; display: grid; grid-template-columns: 230px 320px 1fr; gap: 10px; min-height: 0; }
#sidebar, #list-pane, #editor-pane { border-radius: var(--radius); min-height: 0; }

#sidebar { padding: 12px 10px; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; }
#group-nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 12px; cursor: pointer;
  color: var(--sub); border: 1px solid transparent; user-select: none;
}
.nav-item:hover { background: var(--glass); }
.nav-item.active { background: var(--glass-2); color: var(--fg); border-color: rgba(var(--accent-rgb), .45); }
.nav-item .gdot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.nav-item .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item .count { font-size: 12px; color: var(--muted); }
.nav-item .edit { opacity: 0; width: 26px; height: 26px; }
.nav-item:hover .edit, .nav-item.active .edit { opacity: .8; }
.nav-item .edit svg { width: 16px; height: 16px; }
.nav-sep { height: 1px; background: var(--line); margin: 6px 4px; }
.nav-label { font-size: 11px; color: var(--muted); letter-spacing: .1em; padding: 6px 10px 2px; }

#list-pane { display: flex; flex-direction: column; overflow: hidden; }
.list-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 6px; }
.list-head h2 { margin: 0; font-size: 16px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search { padding: 4px 14px 10px; }
.search input, select, .dlg input {
  width: 100%; font: inherit; color: var(--fg); background: rgba(0, 0, 0, .18); border: 1px solid var(--line);
  border-radius: 12px; padding: 9px 12px; outline: none;
}
.search input:focus, .dlg input:focus { border-color: var(--accent); }
select { width: auto; padding: 6px 10px; font-size: 13px; }
select option { background: #1b2638; }
#note-list { list-style: none; margin: 0; padding: 0 8px 10px; overflow-y: auto; flex: 1; }
.note-item { padding: 11px 12px; border-radius: 14px; cursor: pointer; border: 1px solid transparent; margin-bottom: 4px; }
.note-item:hover { background: var(--glass); }
.note-item.active { background: var(--glass-2); border-color: rgba(var(--accent-rgb), .45); }
.note-item .t { font-weight: 500; display: flex; align-items: center; gap: 6px; }
.note-item .t span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note-item .p { font-size: 13px; color: var(--sub); margin-top: 3px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; line-height: 1.5; }
.note-item .m { font-size: 11px; color: var(--muted); margin-top: 5px; display: flex; gap: 8px; align-items: center; }
.note-item .gdot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.note-item .pin { color: var(--accent); font-size: 12px; }
.note-item .unsynced { color: #f2c97d; }
.empty { color: var(--muted); font-size: 14px; text-align: center; padding: 30px 10px; }
.empty.center { margin: auto; }

#editor-pane { display: flex; flex-direction: column; overflow: hidden; }
#editor { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.editor-bar { display: flex; align-items: center; gap: 4px; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.spacer { flex: 1; }
.title-input { font: inherit; font-size: 22px; font-weight: 500; background: none; border: none; color: var(--fg); padding: 16px 20px 2px; outline: none; }
.title-input::placeholder, textarea::placeholder { color: var(--muted); }
.meta-line { font-size: 11px; color: var(--muted); padding: 0 20px 6px; }
textarea {
  flex: 1; min-height: 120px; font: inherit; font-size: 15px; line-height: 1.85; color: var(--fg);
  background: none; border: none; outline: none; resize: none; padding: 6px 20px 16px;
}
#attachments { display: flex; flex-direction: column; gap: 8px; padding: 0 16px; max-height: 45%; overflow-y: auto; flex: none; }
.att {
  display: flex; flex-direction: column; gap: 8px; background: rgba(0, 0, 0, .18); border: 1px solid var(--line);
  border-radius: 14px; padding: 10px 12px;
}
.att-head { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.att-head .n { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-head .s { color: var(--muted); font-size: 12px; flex: none; }
.att-head .icon-btn { width: 30px; height: 30px; }
.att-head .icon-btn svg { width: 17px; height: 17px; }
.att img, .att video { max-width: 100%; max-height: 320px; border-radius: 10px; display: block; background: #000; }
.att audio { width: 100%; }
.att .progress { height: 4px; background: rgba(255, 255, 255, .1); border-radius: 4px; overflow: hidden; }
.att .progress span { display: block; height: 100%; background: var(--accent); width: 0; transition: width .2s; }
.att .note { font-size: 12px; color: var(--muted); }
.att .err { font-size: 12px; color: var(--danger); }
.attach-bar { display: flex; gap: 8px; padding: 10px 16px 14px; border-top: 1px solid var(--line); margin-top: 10px; flex: none; }

/* ---- dialogs ---- */
dialog.dlg { color: var(--fg); border-radius: 22px; padding: 22px; width: min(420px, 92vw); background: rgba(24, 34, 52, .88); }
dialog::backdrop { background: rgba(0, 0, 0, .45); backdrop-filter: blur(3px); }
.dlg h3 { margin: 0 0 14px; font-weight: 500; }
.dlg label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--sub); }
.dlg-actions { display: flex; gap: 8px; margin-top: 18px; align-items: center; }
.dlg-col { display: flex; flex-direction: column; gap: 8px; }
.colors { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.colors button { width: 30px; height: 30px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; }
.colors button.sel { border-color: #fff; box-shadow: 0 0 0 3px rgba(255, 255, 255, .2); }
.rec-time { font-size: 44px; font-weight: 200; text-align: center; letter-spacing: .08em; font-variant-numeric: tabular-nums; }
.rec-level { height: 6px; background: rgba(255, 255, 255, .1); border-radius: 6px; overflow: hidden; margin: 14px 0 4px; }
.rec-level span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #8fe0b0, #f2c97d, #f29a9a); transition: width .08s; }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-b) + 24px); transform: translateX(-50%); z-index: 50;
  background: rgba(24, 34, 52, .95); border: 1px solid var(--line); border-radius: 14px; padding: 10px 18px; font-size: 13px;
  max-width: 90vw; box-shadow: 0 8px 30px rgba(0, 0, 0, .4);
}

.only-mobile { display: none; }
#scrim { display: none; }

/* ---- tablet ---- */
@media (max-width: 1080px) {
  #layout { grid-template-columns: 290px 1fr; }
  #sidebar {
    position: fixed; z-index: 30; top: calc(var(--safe-t) + 10px); bottom: calc(var(--safe-b) + 10px); left: 10px; width: 260px;
    transform: translateX(-120%); transition: transform .22s ease; background: rgba(20, 30, 48, .92);
  }
  body.drawer #sidebar { transform: none; }
  body.drawer #scrim { display: block; position: fixed; inset: 0; z-index: 25; background: rgba(0, 0, 0, .35); }
}
/* ---- phone ---- */
@media (max-width: 720px) {
  #main { padding: calc(var(--safe-t) + 6px) 6px calc(var(--safe-b) + 6px); gap: 6px; }
  #layout { grid-template-columns: 1fr; }
  body.editing #list-pane { display: none; }
  body:not(.editing) #editor-pane { display: none; }
  .only-mobile { display: inline-flex; }
  .brand { font-size: 15px; letter-spacing: .08em; }
  .pill { padding: 5px 10px; }
  .title-input { font-size: 20px; padding: 12px 14px 2px; }
  textarea { padding: 6px 14px 12px; }
  .meta-line { padding: 0 14px 6px; }
  #attachments { padding: 0 10px; }
  .attach-bar { padding: 8px 10px 10px; }
}

/* ---- 他の端末で使う ---- */
.hint { margin: 0 14px 10px; padding: 10px 12px; border-radius: 14px; background: rgba(var(--accent-rgb), .12); border: 1px solid rgba(var(--accent-rgb), .35); }
.hint-text { font-size: 13px; line-height: 1.6; }
.hint-actions { display: flex; gap: 8px; margin-top: 8px; }
.url-box { display: flex; align-items: center; gap: 8px; background: rgba(0, 0, 0, .25); border: 1px solid var(--line); border-radius: 12px; padding: 8px 8px 8px 12px; margin: 10px 0 14px; }
.url-box span { flex: 1; font-size: 15px; word-break: break-all; user-select: all; }
.qr-wrap { text-align: center; margin-bottom: 12px; }
#qr { display: inline-block; background: #fff; padding: 10px; border-radius: 14px; line-height: 0; }
#qr svg { width: 168px; height: 168px; }

/* ---- 見た目の設定 ---- */
.dlg.wide { width: min(520px, 94vw); max-height: 92vh; overflow-y: auto; }
.set-sec { margin-top: 16px; }
.set-sec h4 { margin: 0 0 8px; font-size: 13px; font-weight: 500; color: var(--accent); letter-spacing: .05em; }
.accents { display: flex; gap: 12px; flex-wrap: wrap; }
.accents button { width: 34px; height: 34px; border-radius: 50%; border: 3px solid transparent; cursor: pointer; }
.accents button.sel { border-color: #fff; }
.range-row { display: flex; flex-direction: column; gap: 4px; margin-top: 12px; font-size: 13px; color: var(--sub); }
.range-row .lbl { display: flex; justify-content: space-between; }
.range-row small { color: var(--muted); font-size: 11px; }
input[type=range] { width: 100%; accent-color: var(--accent); }
.bg-preview {
  position: relative; width: 100%; aspect-ratio: var(--preview-ar, 16 / 10); max-height: 300px; margin: 6px auto 0; border-radius: 14px; overflow: hidden;
  border: 1px solid var(--line); background: linear-gradient(160deg, #060a16 0%, #130f2b 55%, #07182a 100%); touch-action: none; cursor: grab;
}
.bg-preview.dragging { cursor: grabbing; }
.bg-preview .pv-img { position: absolute; inset: 0; background-size: cover; background-repeat: no-repeat; }
.bg-preview .pv-panel { position: absolute; left: 8%; top: 12%; width: 38%; height: 70%; border-radius: 10px; background: var(--glass); border: 1px solid var(--line); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.bg-preview .pv-hint { position: absolute; right: 8px; bottom: 8px; font-size: 11px; background: rgba(0, 0, 0, .55); padding: 3px 8px; border-radius: 8px; }
.bg-preview .pv-empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 13px; }
.row-btns { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
