:root {
  color-scheme: dark light;
  --bg: #292A2D;
  --surface: #35363A;
  --chrome: #202124;
  --hover: #45474D;
  --text: #E8EAED;
  --muted: #B4B8BF;
  --line: #494B50;
  --accent: #A8C7FA;
  --accent-ink: #162C50;
  --focus: #A8C7FA;
  --scroll-thumb: #62656E;
  --danger: #F28B82;
  --danger-bg: rgba(242, 139, 130, 0.14);
  --match-fill: #FFDB74;
  --active-match-fill: #FFAC42;
  --match-ink: #292522;
  --scrim: rgba(0, 0, 0, 0.58);
  --viewer-scrim: rgba(0, 0, 0, 0.92);
  --grid-cols: 4;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #FFFFFF;
    --surface: #F1F3F7;
    --chrome: #DEE7F7;
    --hover: #DCE5F2;
    --text: #202124;
    --muted: #5F6368;
    --line: #DADCE0;
    --accent: #D3E3FD;
    --accent-ink: #162C50;
    --focus: #0B57D0;
    --scroll-thumb: #B5BAC3;
    --danger: #C5221F;
    --danger-bg: rgba(197, 34, 31, 0.10);
    --scrim: rgba(15, 23, 42, 0.45);
  }
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #FFFFFF;
  --surface: #F1F3F7;
  --chrome: #DEE7F7;
  --hover: #DCE5F2;
  --text: #202124;
  --muted: #5F6368;
  --line: #DADCE0;
  --accent: #D3E3FD;
  --accent-ink: #162C50;
  --focus: #0B57D0;
  --scroll-thumb: #B5BAC3;
  --danger: #C5221F;
  --danger-bg: rgba(197, 34, 31, 0.10);
  --scrim: rgba(15, 23, 42, 0.45);
}

:root[data-theme="dark"] {
  color-scheme: dark;
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

button, input, textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: 1px solid transparent;
  background: transparent;
  padding: 0;
  touch-action: manipulation;
}

button:disabled {
  opacity: 0.38;
  cursor: default;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* Top Bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: calc(8px + var(--safe-top)) calc(14px + var(--safe-right)) 8px calc(14px + var(--safe-left));
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.view-tabs {
  display: inline-flex;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
}

.view-tab {
  min-width: 40px;
  height: 32px;
  padding: 0 10px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  transition: background-color 140ms ease, color 140ms ease;
}

.view-tab[aria-selected="true"] {
  background: var(--accent);
  color: var(--accent-ink);
}

.count-label {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.grid-controls {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 4px;
}

.col-count {
  font-size: 12px;
  color: var(--muted);
  padding: 0 4px;
  white-space: nowrap;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  transition: background-color 140ms ease, opacity 140ms ease, border-color 140ms ease;
  flex-shrink: 0;
}

.icon-btn.sm {
  width: 34px;
  height: 34px;
}

.grid-controls .icon-btn {
  width: 32px;
  height: 32px;
}

.icon-btn:hover:not(:disabled) {
  background: var(--hover);
}

.icon-btn.active {
  background: var(--accent);
  color: var(--accent-ink);
}

.icon-btn.accent-btn {
  background: var(--accent);
  color: var(--accent-ink);
}

.icon-btn.accent-btn:hover:not(:disabled) {
  opacity: 0.86;
  background: var(--accent);
}

.icon-btn.danger:hover:not(:disabled) {
  background: var(--danger-bg);
  color: var(--danger);
}

.text-pill-btn {
  height: 38px;
  padding: 0 13px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.text-pill-btn.active {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
}

.primary-pill-btn,
.secondary-pill-btn,
.danger-pill-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 18px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 500;
  transition: opacity 140ms ease, background-color 140ms ease;
}

.primary-pill-btn.sm,
.secondary-pill-btn.sm {
  min-height: 36px;
  padding: 0 14px;
  font-size: 13px;
}

.primary-pill-btn {
  background: var(--accent);
  color: var(--accent-ink);
}

.secondary-pill-btn {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
}

.danger-pill-btn {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid transparent;
}

.full {
  width: 100%;
}

.danger-text {
  color: var(--danger);
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Search & Tag Filter Bar */
.find-bar {
  position: sticky;
  top: calc(55px + var(--safe-top));
  z-index: 25;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  padding: 8px calc(14px + var(--safe-right)) 10px calc(14px + var(--safe-left));
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.16);
}

.find-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.find-input-wrap {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 12px;
  height: 40px;
}

.find-input-wrap:focus-within {
  border-color: var(--focus);
}

.find-icon {
  color: var(--muted);
  display: inline-flex;
  flex-shrink: 0;
}

.find-input-wrap input {
  width: 100%;
  min-width: 0;
  border: none;
  background: transparent;
  outline: none;
  font-size: 14px;
}

.find-count {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  padding: 0 4px;
}

.find-nav {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

.quick-tag-strip {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}

.quick-tag-strip::-webkit-scrollbar {
  display: none;
}

.quick-tag-pill {
  flex-shrink: 0;
  min-height: 30px;
  padding: 4px 11px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.quick-tag-pill.active {
  border-color: transparent;
  box-shadow: 0 0 0 2px var(--focus);
}

.quick-tag-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* Main Collection */
.collection {
  flex: 1;
  padding: 12px calc(12px + var(--safe-right)) calc(84px + var(--safe-bottom)) calc(12px + var(--safe-left));
  outline: none;
}

.collection.drag-over {
  outline: 2px dashed var(--accent);
  outline-offset: -8px;
}

.collection-inner {
  max-width: 1380px;
  margin: 0 auto;
}

/* Grid Mode */
.work-grid {
  display: grid;
  grid-template-columns: repeat(var(--grid-cols), minmax(0, 1fr));
  gap: 8px;
}

.grid-tile {
  position: relative;
  aspect-ratio: 1 / 0.77;
  min-height: 82px;
  background: var(--surface);
  border: 1px solid transparent;
  border-radius: 10px;
  overflow: hidden;
  transition: border-color 140ms ease, transform 140ms ease;
}

.grid-tile.find-hit {
  border: 2px solid var(--match-fill);
}

.grid-tile.find-active {
  border: 2px solid var(--active-match-fill);
}

.grid-tile-btn {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  position: relative;
}

.grid-tile-media-wrap {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.thumb-img,
.thumb-video {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  display: block;
  border-radius: 6px;
}

.thumb-media-box {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  max-width: 100%;
  max-height: 100%;
}

.thumb-ink-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.memo-badge {
  position: absolute;
  right: 6px;
  bottom: 6px;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}

.video-badge {
  position: absolute;
  left: 6px;
  top: 6px;
  height: 24px;
  padding: 0 7px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.62);
  color: #FFFFFF;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  pointer-events: none;
}

.video-expand-btn {
  position: absolute;
  right: 6px;
  top: 6px;
  width: 30px;
  height: 30px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.62);
  color: #FFFFFF;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
}

.find-excerpt {
  position: absolute;
  left: 5px;
  right: 5px;
  bottom: 5px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 2px 6px;
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}

.insertion-tile {
  background: transparent;
  border: 1.5px dashed var(--muted);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: var(--muted);
  width: 100%;
  height: 100%;
  min-height: 96px;
}

.insertion-tile:hover {
  border-color: var(--accent);
  color: var(--text);
}

/* List Mode */
.work-list-header {
  display: none;
}

.work-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.list-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.list-card.find-active {
  border-color: var(--active-match-fill);
}

.list-media-col {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  border-radius: 10px;
  min-height: 170px;
  max-height: 300px;
  overflow: hidden;
}

.list-media-btn {
  width: 100%;
  height: 100%;
  min-height: 170px;
  max-height: 300px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
}

.list-note-col {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.note-textarea {
  width: 100%;
  min-height: 92px;
  resize: vertical;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  line-height: 1.55;
  font-size: 15px;
}

.note-textarea.inline-note {
  min-height: 84px;
  background: transparent;
  border-color: transparent;
}

.note-textarea.inline-note:focus {
  background: var(--bg);
  border-color: var(--focus);
}

.note-highlight-box {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  min-height: 84px;
  white-space: pre-wrap;
  word-break: break-word;
  cursor: text;
  font-size: 15px;
  line-height: 1.55;
}

.list-tag-col {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

.list-card-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
}

.list-add-row {
  padding: 12px;
  border: 1.5px dashed var(--muted);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--muted);
  min-height: 62px;
}

.list-add-row:hover {
  border-color: var(--accent);
  color: var(--text);
}

/* Tags */
.tag-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.tag-chip {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  border-radius: 999px;
  border: 1px solid var(--line);
  overflow: hidden;
  min-height: 30px;
}

.tag-chip.find-active {
  box-shadow: 0 0 0 2px var(--active-match-fill);
}

.tag-chip-filter {
  padding: 4px 8px 4px 11px;
  font-size: 13px;
  font-weight: 500;
  max-width: 200px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tag-chip-edit {
  padding: 4px 4px;
  font-size: 12px;
  opacity: 0.78;
  display: inline-flex;
  align-items: center;
}

.tag-chip-remove {
  padding: 4px 9px 4px 4px;
  font-size: 14px;
  line-height: 1;
  font-weight: 600;
}

.tag-add-chip {
  min-width: 34px;
  height: 30px;
  padding: 0 11px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.list-card .tag-add-chip {
  background: var(--bg);
}

mark.find-match {
  background: var(--match-fill);
  color: var(--match-ink);
  border-radius: 3px;
  padding: 0 1px;
}

mark.find-match.active {
  background: var(--active-match-fill);
}

/* Empty State */
.empty-state {
  max-width: 420px;
  margin: 14vh auto 0;
  text-align: center;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.empty-title {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
}

.empty-desc {
  margin: 0 0 8px;
  font-size: 14px;
  color: var(--muted);
}

/* Viewer Overlay */
.viewer-modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: var(--viewer-scrim);
  display: flex;
  flex-direction: column;
}

.viewer-layout {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

.viewer-stage-wrap {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: var(--safe-top) var(--safe-right) calc(8px + var(--safe-bottom)) var(--safe-left);
  position: relative;
}

.viewer-stage {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  user-select: none;
}

.viewer-content {
  position: relative;
  transform-origin: center center;
  will-change: transform;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.viewer-img {
  max-width: 100%;
  max-height: 100%;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
}

.viewer-ink-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.viewer-ink-canvas.drawing {
  cursor: crosshair;
}

.viewer-video-host {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
}

.viewer-video-host video {
  max-width: 100%;
  max-height: 100%;
  border-radius: 10px;
  background: #000000;
}

.viewer-status {
  color: #E8EAED;
  font-size: 14px;
  padding: 12px 16px;
}

/* Pen Palette */
.pen-palette {
  align-self: center;
  margin-bottom: 8px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: calc(100vw - 24px);
  overflow-x: auto;
  z-index: 3;
}

.pen-color-row,
.pen-width-row {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.pen-color-swatch {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
}

.pen-color-swatch.active {
  border-color: var(--focus);
  transform: scale(1.14);
}

.pen-width-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
}

.pen-width-btn.active {
  background: var(--accent);
  color: var(--accent-ink);
}

.pen-width-dot {
  border-radius: 50%;
  background: currentColor;
}

.pen-divider {
  width: 1px;
  height: 20px;
  background: var(--line);
}

.pen-action-btn {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--danger);
}

/* Viewer Bottom Bar */
.viewer-bar {
  margin: 0 10px;
  padding: 6px 8px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  z-index: 3;
}

.viewer-bar::-webkit-scrollbar {
  display: none;
}

.viewer-nav-group,
.viewer-action-group {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.viewer-pos {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  padding: 0 4px;
}

/* Viewer Details Drawer (Mobile Bottom Sheet -> Desktop Right Panel) */
.viewer-drawer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 65;
  background: var(--bg);
  border-top: 1px solid var(--line);
  border-radius: 18px 18px 0 0;
  max-height: 72dvh;
  display: flex;
  flex-direction: column;
  padding: 8px calc(16px + var(--safe-right)) calc(18px + var(--safe-bottom)) calc(16px + var(--safe-left));
  box-shadow: 0 -8px 28px rgba(0, 0, 0, 0.36);
}

.drawer-handle-bar {
  display: flex;
  justify-content: center;
  padding: 2px 0 6px;
}

.drawer-handle {
  width: 40px;
  height: 4px;
  border-radius: 999px;
  background: var(--line);
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.drawer-title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.drawer-header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.drawer-body {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.drawer-notes {
  min-height: 120px;
  background: var(--surface);
}

/* Sheets */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: var(--scrim);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.sheet-panel {
  width: 100%;
  max-width: 540px;
  max-height: 84dvh;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 18px 18px 0 0;
  padding: 8px calc(16px + var(--safe-right)) calc(18px + var(--safe-bottom)) calc(16px + var(--safe-left));
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sheet-handle {
  width: 40px;
  height: 4px;
  border-radius: 999px;
  background: var(--line);
  align-self: center;
  margin-bottom: 8px;
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.sheet-title {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
}

.sheet-body {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.field-label {
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
}

.field-label-row {
  margin-top: 4px;
}

.muted-label {
  font-size: 13px;
  color: var(--muted);
}

.text-input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
}

.tag-input-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.tag-input-row input {
  flex: 1;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 9px 14px;
}

.tag-color-section {
  margin-top: 10px;
}

.color-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 8px;
}

.color-swatch-btn {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid transparent;
}

.color-swatch-btn.active {
  border-color: var(--text);
  box-shadow: 0 0 0 2px var(--focus);
}

.tag-choice-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.tag-choice-item {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  overflow: hidden;
}

.tag-choice-toggle {
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 500;
}

.tag-choice-edit {
  padding: 7px 10px 7px 6px;
  border-left: 1px solid rgba(128, 128, 128, 0.25);
  display: inline-flex;
  align-items: center;
}

.custom-color-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
}

.color-native-input {
  width: 44px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
}

.sheet-actions-split {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 18px;
  flex-wrap: wrap;
}

.sheet-actions-right {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

/* Menu Sheet */
.menu-body {
  gap: 18px;
}

.menu-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.menu-help {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.5;
}

.segmented-control {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 3px;
  gap: 3px;
}

.seg-btn {
  min-height: 36px;
  border-radius: 9px;
  font-size: 13px;
  color: var(--muted);
}

.seg-btn.active {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 500;
}

.menu-btn-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.backup-progress {
  font-size: 13px;
  color: var(--accent);
  padding: 6px 10px;
  background: var(--surface);
  border-radius: 8px;
}

/* Toast Notice */
.toast {
  position: fixed;
  left: 16px;
  bottom: calc(18px + var(--safe-bottom));
  z-index: 95;
  max-width: min(420px, calc(100vw - 32px));
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.32);
}

.toast-text {
  font-size: 13px;
  line-height: 1.4;
}

/* Mobile specific refinements (prevent iOS Safari input zoom) */
@media (max-width: 719px) {
  input[type="text"],
  input[type="search"],
  textarea,
  .note-textarea {
    font-size: 16px;
  }

  .topbar {
    padding: calc(6px + var(--safe-top)) calc(10px + var(--safe-right)) 6px calc(10px + var(--safe-left));
  }

  .icon-btn {
    width: 42px;
    height: 42px;
  }

  .grid-controls .icon-btn {
    width: 34px;
    height: 34px;
  }
}

/* Tablet / Desktop Layout */
@media (min-width: 720px) {
  .topbar {
    padding: 10px 24px;
  }

  .find-bar {
    top: 59px;
    padding: 10px 24px;
  }

  .collection {
    padding: 16px 24px 64px;
  }

  .work-grid {
    gap: 10px;
  }

  .work-list-header {
    display: grid;
    grid-template-columns: minmax(220px, 28%) minmax(260px, 1fr) minmax(200px, 30%);
    gap: 16px;
    padding: 6px 12px 10px;
    color: var(--muted);
    font-size: 13px;
    border-bottom: 1px solid var(--line);
    margin-bottom: 8px;
  }

  .list-card {
    grid-template-columns: minmax(220px, 28%) minmax(260px, 1fr) minmax(200px, 30%);
    gap: 16px;
    align-items: start;
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--line);
    border-radius: 0;
    padding: 12px 10px;
  }

  .list-media-col {
    background: var(--surface);
    min-height: 140px;
    max-height: 220px;
  }

  .list-media-btn {
    min-height: 140px;
    max-height: 220px;
  }

  .sheet-backdrop {
    align-items: center;
    padding: 20px;
  }

  .sheet-panel {
    border-radius: 16px;
    padding: 16px 20px 20px;
  }

  .sheet-handle {
    display: none;
  }
}

@media (min-width: 840px) {
  .viewer-layout {
    flex-direction: row;
  }

  .viewer-stage-wrap {
    padding: 16px;
  }

  .viewer-drawer {
    position: static;
    width: 340px;
    max-height: none;
    height: 100%;
    border-top: none;
    border-left: 1px solid var(--line);
    border-radius: 0;
    padding: 16px;
    box-shadow: none;
  }

  .drawer-handle-bar {
    display: none;
  }
}

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