* { box-sizing: border-box; }

:root[data-theme="dark"] {
  --bg: #141416;
  --surface: #1c1c1f;
  --surface-2: #26262a;
  --border: #38383d;
  --text: #ffffff;
  --muted: #8f8f95;
  --accent: #2ecc71;
  --accent-text: #04150a;
  --danger: #ff4d4d;
  --shadow: rgba(0, 0, 0, 0.5);
}

:root[data-theme="light"] {
  --bg: #ffffff;
  --surface: #f7f7f7;
  --surface-2: #eeeeee;
  --border: #dcdcdc;
  --text: #0a0a0a;
  --muted: #6b6b6b;
  --accent: #16a34a;
  --accent-text: #ffffff;
  --danger: #dc2626;
  --shadow: rgba(0, 0, 0, 0.12);
}

html { transition: background-color .3s ease; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  min-height: 100vh;
  transition: background-color .3s ease, color .3s ease;
}

button { font-family: inherit; cursor: pointer; }
a { color: inherit; text-decoration: none; }

img.emoji { height: 1em; width: 1em; vertical-align: -0.15em; }

/* subtle entrance — plays once per item's first appearance, not on every re-render */
@keyframes popIn {
  0% { transform: scale(0.9) rotate(-2deg) translateY(-6px); opacity: 0; }
  65% { transform: scale(1.015) rotate(0.6deg) translateY(1px); opacity: 1; }
  100% { transform: scale(1) rotate(0deg) translateY(0); }
}
.pop-in { animation: popIn .28s cubic-bezier(.22,1,.36,1) both; }

/* dragging state — no CSS transitions fighting the JS-driven position updates */
.dragging, .dragging * { transition: none !important; }
.dragging { box-shadow: 0 20px 50px rgba(0,0,0,0.55); cursor: grabbing !important; opacity: 0.98; }

@keyframes lightboxFade { from { opacity: 0; } to { opacity: 1; } }
@keyframes lightboxPop { from { transform: scale(.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes modalPop { from { transform: scale(.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes menuPop { from { transform: scale(.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* topbar */

.topbar {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 22px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  z-index: 10;
  transition: background-color .3s ease, border-color .3s ease;
  gap: 12px;
}

.topbar-left-fixed { position: absolute; left: 24px; top: 50%; transform: translateY(-50%); }
.topbar-right-fixed { position: absolute; right: 24px; top: 50%; transform: translateY(-50%); display: flex; align-items: center; gap: 8px; }

.topbar-title-block { text-align: center; max-width: 60%; }
.topbar-title-block h1 {
  margin: 0;
  font-size: 27px;
  font-weight: 800;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-title-block .sub { margin-top: 5px; font-size: 13px; color: var(--muted); transition: color .3s ease; }

.back-btn, .icon-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  width: 38px;
  height: 38px;
  border-radius: 10px;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background-color .2s ease, border-color .2s ease, color .2s ease, transform .12s ease;
}
.icon-btn { width: 40px; height: 40px; }
.back-btn:hover, .icon-btn:hover { background: var(--surface-2); transform: scale(1.05); }
.back-btn:active, .icon-btn:active { transform: scale(0.9); }

.search-input {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 12px;
  border-radius: 10px;
  font-size: 13px;
  width: 150px;
  transition: background-color .2s ease, border-color .2s ease, color .2s ease, width .2s ease;
}
.search-input:focus { outline: none; border-color: var(--accent); width: 190px; }

.container { max-width: 1100px; margin: 0 auto; padding: 28px 32px 120px; }

/* project list */

.project-row {
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 18px;
  margin-bottom: 12px;
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease, border-color .2s ease, background-color .3s ease;
}
.project-row:hover { transform: translateY(-2px); box-shadow: 0 6px 18px var(--shadow); border-color: var(--accent); }
.project-row:active { transform: translateY(0) scale(.99); }

.project-thumb {
  width: 72px;
  height: 72px;
  border-radius: 10px;
  object-fit: cover;
  cursor: zoom-in;
  flex-shrink: 0;
}

.project-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.project-name-line { display: flex; align-items: center; gap: 8px; }
.project-name { font-weight: 700; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.project-counts { display: flex; gap: 8px; flex-wrap: wrap; }
.count-chip {
  font-size: 12px;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  white-space: nowrap;
  transition: background-color .3s ease, color .3s ease;
}
.count-chip b { color: var(--text); }

.empty-state { text-align: center; color: var(--muted); padding: 80px 20px; font-size: 15px; }
.empty-state .big { font-size: 40px; margin-bottom: 10px; }

.fab {
  position: fixed;
  bottom: 32px;
  right: 32px;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--accent);
  color: #ffffff;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 24px var(--shadow);
  transition: transform .12s ease, background-color .25s ease;
}
.fab svg { display: block; }
.fab:hover { transform: scale(1.08) rotate(8deg); }
.fab:active { transform: scale(0.92) rotate(0deg); }

/* updates grid */

.updates-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 18px;
  max-width: 900px;
  margin: 0 auto;
}
@media (max-width: 900px) { .updates-grid { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 560px) { .updates-grid { grid-template-columns: repeat(2, 1fr); } }

.update-square {
  position: relative;
  overflow: hidden;
  aspect-ratio: 1 / 1;
  border-radius: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  border: 1px solid rgba(255,255,255,0.08);
  cursor: pointer;
  transition: transform .15s ease, box-shadow .15s ease, outline-color .15s ease;
  outline: 2px solid transparent;
  outline-offset: 2px;
}
.update-square:hover {
  transform: translateY(-3px) scale(1.02);
  box-shadow: 0 10px 26px var(--shadow);
  outline-color: rgba(255,255,255,0.5);
}
.update-square:active { transform: translateY(0) scale(.97); }

.update-square .u-name {
  font-weight: 700;
  font-size: 15px;
  text-align: center;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0,0,0,0.4);
  word-break: break-word;
  line-height: 1.2;
}
.update-square .u-version { position: absolute; bottom: 10px; left: 12px; font-size: 11px; color: rgba(255,255,255,0.65); }
.update-square .u-progress {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 700;
  color: #fff;
  border: 2px solid rgba(255,255,255,0.3);
}

/* cancelled tint + stamp, used on rows/squares at every level */

.is-cancelled::before {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(220, 38, 38, 0.38);
  pointer-events: none;
  z-index: 1;
}
.cancelled-stamp {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(-45deg);
  font-weight: 800;
  font-size: 14px;
  letter-spacing: 0.09em;
  color: #fff;
  background: rgba(153, 18, 18, 0.95);
  padding: 4px 16px;
  border-radius: 4px;
  pointer-events: none;
  white-space: nowrap;
  box-shadow: 0 2px 10px rgba(0,0,0,0.45);
  z-index: 2;
}

/* feature list (update detail page) */

.category-frame {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  margin-bottom: 20px;
  min-height: 60px;
  transition: background-color .3s ease, border-color .2s ease, outline-color .15s ease;
}
.category-frame.drag-over { outline: 2px dashed var(--accent); outline-offset: 3px; }

.category-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  gap: 10px;
}
.category-header h3 {
  margin: 0;
  font-size: 14px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  transition: color .3s ease;
}

.drag-handle {
  cursor: grab;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 5px;
  border-radius: 6px;
  flex-shrink: 0;
  touch-action: none;
  transition: background-color .15s ease, color .15s ease;
}
.drag-handle:hover { background: var(--surface-2); color: var(--text); }
.drag-handle:active { cursor: grabbing; }

.feature-row {
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  gap: 12px;
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 10px;
  border: 1px solid rgba(255,255,255,0.08);
  color: #fff;
  transition: outline-color .15s ease, filter .15s ease;
  outline: 2px solid transparent;
  outline-offset: -2px;
}
.feature-row:last-child { margin-bottom: 0; }
.feature-row.drag-over { outline-color: #fff; outline-style: dashed; }
.feature-row:hover { filter: brightness(1.12); }

.feature-row .drag-handle { color: rgba(255,255,255,0.65); z-index: 2; position: relative; }
.feature-row .drag-handle:hover { background: rgba(255,255,255,0.15); color: #fff; }

.feature-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
  cursor: zoom-in;
  z-index: 2;
  position: relative;
}

.feature-main {
  flex: 1;
  min-width: 0;
  z-index: 2;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.feature-name-line {
  font-weight: 600;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.feature-meta-line {
  font-size: 12px;
  color: rgba(255,255,255,0.68);
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.feature-meta-line .credits { font-style: italic; color: rgba(255,255,255,0.55); }
.feature-meta-line .dot { opacity: .5; }

.feature-progress-box {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  border-radius: 7px;
  padding: 5px 8px;
  z-index: 2;
  position: relative;
}
.feature-progress-box input[type="number"] {
  width: 42px;
  background: transparent;
  border: none;
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  text-align: right;
}
.feature-progress-box input[type="number"]:focus { outline: none; }
.feature-progress-box .pct-sign { font-size: 12px; opacity: 0.9; }
.feature-progress-box input[type="checkbox"] { width: 18px; height: 18px; accent-color: #fff; }

/* lightbox */

.lightbox-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
  cursor: zoom-out;
  padding: 30px;
  animation: lightboxFade .18s ease;
}
.lightbox-overlay img {
  max-width: 92vw;
  max-height: 92vh;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
  animation: lightboxPop .22s cubic-bezier(.22,1,.36,1);
}

/* modal */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal-overlay.open { display: flex; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 100%;
  max-width: 440px;
  padding: 26px;
  max-height: 90vh;
  overflow-y: auto;
  transition: background-color .3s ease, border-color .3s ease;
  animation: modalPop .25s cubic-bezier(.34,1.56,.64,1);
}

.modal h2 { margin: 0 0 18px 0; font-size: 18px; font-weight: 800; }

.confirm-modal { max-width: 380px; text-align: center; }
.confirm-modal h2 { text-align: center; }
.confirm-modal .modal-actions { justify-content: center; }
.confirm-message { color: var(--muted); font-size: 14px; margin: 0 0 20px 0; line-height: 1.5; transition: color .3s ease; }

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; transition: color .3s ease; }
.field input[type="text"],
.field input[type="number"],
.field select,
.field textarea {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 9px;
  font-size: 14px;
  transition: background-color .3s ease, border-color .2s ease, color .3s ease;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--accent); }

.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }

.image-drop {
  border: 1.5px dashed var(--border);
  border-radius: 12px;
  padding: 16px;
  text-align: center;
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
  position: relative;
  transition: border-color .2s ease, color .3s ease;
}
.image-drop input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; z-index: 1; }

.image-preview-wrap { position: relative; display: inline-block; max-width: 100%; z-index: 2; }
.image-preview-wrap img { max-width: 100%; max-height: 120px; border-radius: 8px; display: block; margin: 0 auto; }
.image-remove-btn {
  position: absolute;
  top: -9px;
  right: -9px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--danger);
  color: #fff;
  border: 2px solid var(--surface);
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 5;
  transition: filter .15s ease, transform .12s ease;
}
.image-remove-btn:hover { filter: brightness(1.1); transform: scale(1.08); }

.color-field { display: flex; align-items: center; gap: 14px; }
.color-swatch-wrap { display: flex; flex-direction: column; align-items: center; gap: 6px; }

input[type="color"] {
  -webkit-appearance: none;
  appearance: none;
  width: 46px;
  height: 46px;
  border: none;
  border-radius: 50%;
  overflow: hidden;
  padding: 0;
  background: none;
  cursor: pointer;
}
input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; border-radius: 50%; }
input[type="color"]::-webkit-color-swatch { border: 2px solid var(--border); border-radius: 50%; }

.rgb-boxes { display: flex; gap: 8px; flex: 1; }
.rgb-boxes .field { margin-bottom: 0; }
.rgb-boxes label { text-align: center; }
.rgb-boxes input { text-align: center; padding: 8px 6px !important; }

.type-toggle { display: flex; gap: 8px; }
.type-toggle button {
  flex: 1;
  padding: 9px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 13px;
  transition: background-color .2s ease, border-color .2s ease, color .2s ease;
}
.type-toggle button.active {
  border-color: var(--accent);
  color: var(--text);
  background: color-mix(in srgb, var(--accent) 16%, transparent);
}

.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }

.btn {
  padding: 10px 18px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  transition: background-color .2s ease, border-color .2s ease, color .2s ease, transform .12s ease;
}
.btn:hover { background: var(--border); }
.btn:active { transform: scale(0.94); }

.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-primary:hover { filter: brightness(1.08); }

.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.1); }

.category-select-row { display: flex; gap: 8px; }
.category-select-row select { flex: 1; }
.category-select-row button {
  flex-shrink: 0;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  padding: 0 12px;
  transition: background-color .2s ease, border-color .2s ease, color .2s ease;
}

/* context menu */

.context-menu {
  position: fixed;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 10px 30px var(--shadow);
  padding: 6px;
  min-width: 180px;
  z-index: 200;
  animation: menuPop .16s cubic-bezier(.22,1,.36,1);
}
.context-menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 9px 12px;
  border: none;
  background: none;
  color: var(--text);
  border-radius: 7px;
  font-size: 13.5px;
  transition: transform .1s ease;
}
.context-menu button:hover { background: var(--surface-2); transform: translateX(2px); }
.context-menu button.danger { color: var(--danger); }
.context-menu-divider { height: 1px; background: var(--border); margin: 5px 4px; }

.badge { font-size: 11px; padding: 3px 8px; border-radius: 999px; font-weight: 600; }
.badge-finished { background: color-mix(in srgb, var(--accent) 20%, transparent); color: var(--accent); }
.badge-cancelled { background: color-mix(in srgb, var(--danger) 20%, transparent); color: var(--danger); }
