:root {
  color-scheme: light;
  --bg: #81d9f1;
  --panel: #fffefe;
  --ink: #214177;
  --muted: #5d7eb2;
  --line: rgba(71, 117, 180, 0.16);
  --accent: #20bca8;
  --accent-2: #ffb84f;
  --soft: #e4fbff;
  --danger: #f36b69;
  --green-tile: #9ddd58;
  --orange-tile: #ffb44b;
  --blue-tile: #55c4f3;
  --shadow: 0 18px 36px rgba(30, 66, 133, 0.22);
  --pop-shadow: none;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, rgba(69, 168, 224, 0.04), rgba(98, 74, 158, 0.08)),
    url("./assets/ocean-game-bg-v2.png") center / cover fixed,
    linear-gradient(145deg, #6fd5f4 0%, #81d9f1 38%, #a7ead7 100%);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

body::before,
body::after {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: -1;
  content: "";
  pointer-events: none;
}

body::before {
  inset: 0;
  height: auto;
  background:
    linear-gradient(180deg, rgba(14, 65, 134, 0.01), rgba(58, 92, 170, 0.08)),
    radial-gradient(ellipse at center, transparent 42%, rgba(63, 103, 180, 0.08));
  transition: background 0.2s ease, backdrop-filter 0.2s ease;
}

body.folder-mode::before {
  background:
    linear-gradient(180deg, rgba(80, 99, 188, 0.12), rgba(71, 113, 196, 0.18)),
    radial-gradient(ellipse at center, rgba(109, 139, 225, 0.04), rgba(73, 95, 187, 0.1));
  backdrop-filter: saturate(0.95) brightness(0.98);
}

body::after {
  height: 22svh;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0), rgba(36, 149, 151, 0.28));
}

button,
input {
  font: inherit;
}

button {
  border: 0;
}

.app-shell {
  min-height: 100svh;
  padding: max(18px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 auto 16px;
  max-width: 980px;
  padding: 2px 0;
}

.home-topbar {
  justify-content: space-between;
}

.app-title {
  max-width: min(60vw, 540px);
  color: #ffffff;
  font-size: clamp(22px, 5.3vw, 40px);
  line-height: 1;
  font-weight: 900;
  letter-spacing: 0;
  text-shadow: 0 2px 12px rgba(31, 81, 147, 0.24);
}

.title-block {
  min-width: 0;
}

.eyebrow {
  margin: 0 0 4px;
  color: #1178ad;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(24px, 6vw, 36px);
  line-height: 1.05;
  letter-spacing: 0;
  color: #ffffff;
  text-shadow: 0 3px 0 rgba(42, 102, 181, 0.28), 0 12px 24px rgba(31, 81, 147, 0.22);
}

.actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-start;
}

.button,
.icon-button,
.segment button {
  min-height: 40px;
  border-radius: 8px;
  cursor: pointer;
  transition: transform 0.16s ease, background 0.16s ease, color 0.16s ease;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
  background: linear-gradient(180deg, #ffffff 0%, #eef7ff 100%);
  color: #3262b5;
  font-weight: 800;
  box-shadow: 0 6px 0 rgba(47, 96, 172, 0.12), 0 14px 26px rgba(30, 66, 133, 0.14);
}

.button.secondary {
  background: rgba(255, 255, 255, 0.82);
  color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--line);
}

.button.danger {
  background: linear-gradient(180deg, #ff8b83, var(--danger));
  color: #fff;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 40px;
  padding: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.24);
  color: #ffffff;
  box-shadow: none;
  backdrop-filter: blur(12px);
}

.add-button {
  width: 42px;
  min-height: 42px;
  color: #ffffff;
  background: rgba(48, 106, 190, 0.22);
}

.button:active,
.icon-button:active,
.segment button:active {
  transform: scale(0.97);
}

.segment {
  position: relative;
  display: grid;
  grid-template-columns: repeat(2, 40px);
  gap: 0;
  padding: 4px;
  background: rgba(255, 255, 255, 0.22);
  border-radius: 999px;
  box-shadow: none;
  backdrop-filter: blur(14px);
}

.segment::before {
  position: absolute;
  top: 4px;
  bottom: 4px;
  left: 4px;
  width: 40px;
  border-radius: 999px;
  content: "";
  background: rgba(255, 255, 255, 0.36);
  box-shadow: none;
  transition: transform 0.18s ease;
}

.segment:has(button:nth-child(2).active)::before {
  transform: translateX(40px);
}

.segment button {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  min-height: 40px;
  padding: 0;
  background: transparent;
  color: rgba(255, 255, 255, 0.7);
  box-shadow: none;
  backdrop-filter: none;
}

.segment button.active {
  background: transparent;
  color: #ffffff;
  box-shadow: none;
}

.ui-icon {
  display: block;
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.25;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.ui-icon circle {
  fill: currentColor;
  stroke: none;
}

.content {
  max-width: 980px;
  margin: 0 auto;
}

.folders.grid,
.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}

.folders.list {
  display: grid;
  gap: 10px;
}

.folder-card,
.media-card {
  position: relative;
  overflow: visible;
  border-radius: 8px;
  border: 0;
  background: #ffffff;
  box-shadow: none;
  transition: transform 0.16s ease, box-shadow 0.16s ease, opacity 0.16s ease;
  touch-action: pan-y;
}

.folder-card > .thumb,
.media-card > .media-preview {
  overflow: hidden;
  border-radius: 8px 8px 0 0;
}

.folders.list .folder-card > .thumb {
  border-radius: 8px 0 0 8px;
}

.folder-body,
.media-body {
  border-radius: 0 0 8px 8px;
}

.folders.list .folder-body {
  border-radius: 0 8px 8px 0;
}

.folder-card {
  display: grid;
  grid-template-rows: 132px auto;
  min-height: 0;
}

.folder-card:nth-child(3n + 1) .thumb {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.22), rgba(61, 169, 225, 0.24)),
    linear-gradient(145deg, #75dcf8, #e5fbff);
}

.folder-card:nth-child(3n + 2) .thumb {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.24), rgba(255, 179, 75, 0.2)),
    linear-gradient(145deg, #fff0a7, #8ee4bc);
}

.folder-card:nth-child(3n + 3) .thumb {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.24), rgba(255, 138, 132, 0.18)),
    linear-gradient(145deg, #ffcf88, #b8f1df);
}

.folders.list .folder-card {
  grid-template-columns: 104px 1fr;
  grid-template-rows: 104px;
  min-height: 104px;
}

.add-folder-card {
  aspect-ratio: 1;
  min-height: 0;
  display: grid;
  place-items: center;
  grid-template-rows: 1fr;
  border: 1px dashed rgba(255, 255, 255, 0.76);
  background: rgba(255, 255, 255, 0.26);
  color: #ffffff;
  box-shadow: none;
  backdrop-filter: blur(14px);
  cursor: pointer;
}

.folders.list .add-folder-card {
  aspect-ratio: 1;
  min-height: 104px;
  width: 104px;
}

.thumb {
  position: relative;
  display: grid;
  place-items: center;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(63, 195, 237, 0.16), rgba(255, 199, 105, 0.2)),
    linear-gradient(145deg, #d7fbff, #fff5c7);
  color: #2c67b9;
  font-weight: 900;
}

.thumb::before,
.media-preview::before {
  position: absolute;
  inset: 0;
  z-index: 1;
  content: "";
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.12), transparent 34%, rgba(25, 84, 160, 0.16));
  pointer-events: none;
}

.thumb img,
.media-preview img,
.media-preview video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.folder-body {
  display: grid;
  gap: 8px;
  padding: 12px;
  background: #ffffff;
}

.folder-main {
  min-width: 0;
}

.folder-title {
  display: -webkit-box;
  margin-bottom: 4px;
  color: #244b8f;
  text-decoration: none;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  font-size: 15px;
  line-height: 1.18;
  font-weight: 800;
}

.meta {
  color: #5e82bd;
  font-size: 12px;
  line-height: 1.25;
  font-weight: 700;
}

.empty {
  display: grid;
  gap: 14px;
  place-items: center;
  min-height: 54svh;
  padding: 24px;
  text-align: center;
  border: 1px dashed rgba(255, 255, 255, 0.76);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.54);
  box-shadow: 0 16px 34px rgba(40, 116, 172, 0.13);
  backdrop-filter: blur(16px);
}

.empty strong {
  font-size: 22px;
}

.empty p {
  max-width: 320px;
  margin: 0;
  color: var(--muted);
}

.folder-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 980px;
  margin: 0 auto 16px;
  padding: 0;
}

.folder-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 0;
}

.folder-header h1 {
  color: #ffffff;
  font-size: clamp(24px, 7vw, 36px);
}

.header-meta {
  margin-top: 4px;
  color: rgba(255, 255, 255, 0.9);
  text-shadow: 0 2px 8px rgba(31, 81, 147, 0.2);
}

.media-card {
  display: grid;
  grid-template-rows: 178px auto;
  min-height: 0;
}

.media-card:nth-child(3n + 1) .media-preview {
  background: linear-gradient(145deg, #56c4f3, #dffbff);
}

.media-card:nth-child(3n + 2) .media-preview {
  background: linear-gradient(145deg, #ffcf62, #9fe569);
}

.media-card:nth-child(3n + 3) .media-preview {
  background: linear-gradient(145deg, #ff957f, #7be0d3);
}

.media-preview {
  position: relative;
  min-height: 178px;
  background:
    linear-gradient(180deg, rgba(90, 209, 241, 0.28), rgba(255, 195, 84, 0.2)),
    linear-gradient(145deg, #56c4f3, #b1eed0);
}

.media-body {
  display: grid;
  gap: 8px;
  padding: 10px 12px 12px;
  background: #ffffff;
}

.media-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #244b8f;
  font-size: 14px;
  font-weight: 800;
}

.sync-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: absolute;
  left: 8px;
  top: 8px;
  z-index: 2;
  width: 22px;
  height: 22px;
  color: #ffb02f;
  filter: drop-shadow(0 2px 4px rgba(106, 77, 12, 0.2));
}

.sync-icon .ui-icon {
  width: 20px;
  height: 20px;
  stroke-width: 2.4;
}

.menu-button {
  position: absolute;
  z-index: 4;
  display: grid;
  place-items: center;
  width: 32px;
  min-height: 32px;
  padding: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.22);
  color: #ffffff;
  box-shadow: none;
  backdrop-filter: blur(10px);
}

.folders.list .menu-button {
  color: #2d57a8;
  background: rgba(45, 87, 168, 0.08);
}

.menu-button {
  right: 8px;
  top: 8px;
  font-size: 0;
  line-height: 1;
}

.menu-button .ui-icon {
  width: 20px;
  height: 20px;
  stroke-width: 2.4;
}

.card-menu {
  position: absolute;
  right: 0;
  top: 0;
  z-index: 5;
}

.menu-panel {
  position: fixed;
  top: var(--menu-top, 48px);
  right: var(--menu-right, 16px);
  z-index: 100;
  display: none;
  min-width: 154px;
  overflow: hidden;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.68);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 16px 34px rgba(37, 91, 167, 0.22);
}

.card-menu.open .menu-panel {
  display: grid;
}

.menu-panel button {
  min-height: 42px;
  padding: 0 12px;
  background: transparent;
  color: #2b579b;
  text-align: left;
  font-weight: 800;
}

.menu-panel button + button {
  border-top: 1px solid var(--line);
}

.menu-panel button:hover {
  background: #eaf9ff;
}

.dragging {
  opacity: 0.72;
  z-index: 80;
  pointer-events: none;
  transform: translate3d(var(--drag-x, 0), var(--drag-y, 0), 0) scale(0.985);
  box-shadow: inset 0 0 0 2px var(--green-tile);
  cursor: grabbing;
}

.drop-target {
  box-shadow: inset 0 0 0 2px var(--orange-tile);
}

.add-media-card {
  aspect-ratio: 1;
  min-height: 0;
  grid-template-rows: 1fr;
  place-items: center;
  border: 1px dashed rgba(255, 255, 255, 0.78);
  background: rgba(255, 255, 255, 0.34);
  box-shadow: none;
  backdrop-filter: blur(14px);
  color: #ffffff;
  cursor: pointer;
}

.add-card-symbol {
  display: grid;
  place-items: center;
}

.add-card-symbol .ui-icon {
  width: 38px;
  height: 38px;
  stroke-width: 2.4;
}

.add-folder-card:active,
.add-media-card:active {
  transform: scale(0.98);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: start center;
  padding: 16px;
  padding-top: max(18px, env(safe-area-inset-top));
  background: rgba(33, 32, 29, 0.42);
}

.modal {
  width: min(100%, 460px);
  padding: 18px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.76);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.modal h2 {
  margin: 0 0 14px;
  font-size: 22px;
}

.field {
  display: grid;
  gap: 6px;
  margin-bottom: 16px;
}

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

.field input {
  width: 100%;
  min-height: 48px;
  padding: 0 12px;
  border: 1px solid rgba(73, 121, 189, 0.2);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  box-shadow: inset 0 3px 0 rgba(61, 119, 196, 0.06);
}

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

.visually-hidden {
  position: fixed;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

@media (max-width: 640px) {
  .topbar {
    align-items: flex-start;
  }

  .actions {
    max-width: none;
  }

  .folders.grid,
  .media-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .folder-card {
    grid-template-rows: 118px auto;
  }

  .folder-title {
    font-size: 14px;
  }

  .media-card {
    grid-template-rows: 128px auto;
  }

  .media-preview {
    min-height: 128px;
  }

  .menu-button {
    width: 30px;
    min-height: 30px;
  }

  .add-media-card {
    min-height: 0;
  }
}
