/* =========================================================
   Port / TCYMC Port — light tablet home + in-page windows
   ========================================================= */

:root {
  --bg-deep: #dfe8f5;
  --surface: rgba(255, 255, 255, 0.55);
  --surface-strong: rgba(255, 255, 255, 0.78);
  --surface-solid: #ffffff;
  --border: rgba(30, 40, 70, 0.1);
  --border-strong: rgba(30, 40, 70, 0.16);
  --text: #1a2236;
  --text-muted: rgba(26, 34, 54, 0.58);
  --text-soft: rgba(26, 34, 54, 0.4);
  --accent: #3d9b8f;
  --accent-soft: rgba(61, 155, 143, 0.14);
  --shadow: 0 16px 40px rgba(40, 60, 100, 0.12);
  --shadow-win: 0 24px 64px rgba(30, 45, 80, 0.22), 0 2px 0 rgba(255, 255, 255, 0.7) inset;
  --radius-icon: 22px;
  --radius-panel: 26px;
  --radius-win: 14px;
  --radius-pill: 999px;
  --dock-h: 88px;
  --status-h: 52px;
  --titlebar-h: 42px;
  --font-sans: "Outfit", "Noto Sans SC", system-ui, -apple-system, sans-serif;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --icon-size: 72px;
  --icon-size-dock: 56px;
  --win-bg: #f7f8fb;
  --win-titlebar: rgba(248, 250, 253, 0.92);
  --danger: #e25555;
  --warn: #e0a030;
}

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

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

body {
  font-family: var(--font-sans);
  color: var(--text);
  background: var(--bg-deep);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

/* ---------- Wallpaper (light default) ---------- */

.wallpaper {
  position: fixed;
  inset: 0;
  z-index: 0;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  /* Prefer smooth scaling of photographic wallpapers */
  image-rendering: auto;
  transition: background-image 0.45s ease, background 0.45s ease;
}

/* Soft daylight — Kimi / macOS-like bright default */
.wallpaper[data-theme="daylight"],
.wallpaper:not([data-theme]) {
  background:
    radial-gradient(ellipse 90% 70% at 12% 8%, rgba(255, 210, 230, 0.65), transparent 52%),
    radial-gradient(ellipse 80% 60% at 88% 12%, rgba(170, 210, 255, 0.7), transparent 50%),
    radial-gradient(ellipse 70% 55% at 70% 88%, rgba(190, 230, 210, 0.55), transparent 52%),
    radial-gradient(ellipse 55% 45% at 18% 78%, rgba(255, 230, 190, 0.4), transparent 50%),
    linear-gradient(165deg, #eef3fb 0%, #e4ecf8 45%, #f0eaf6 100%);
}

.wallpaper[data-theme="aurora"] {
  background:
    radial-gradient(ellipse 90% 70% at 10% 10%, rgba(170, 150, 255, 0.45), transparent 50%),
    radial-gradient(ellipse 70% 55% at 90% 20%, rgba(130, 190, 255, 0.4), transparent 48%),
    radial-gradient(ellipse 65% 50% at 75% 85%, rgba(255, 160, 190, 0.35), transparent 52%),
    linear-gradient(165deg, #e8eefc 0%, #dde6f6 50%, #ebe4f4 100%);
}

.wallpaper[data-theme="dusk"] {
  background:
    radial-gradient(ellipse 80% 60% at 20% 30%, rgba(255, 180, 140, 0.45), transparent 55%),
    radial-gradient(ellipse 70% 50% at 80% 20%, rgba(230, 150, 200, 0.35), transparent 50%),
    linear-gradient(180deg, #f5e6dc 0%, #e8d8e8 60%, #d8d0e8 100%);
}

.wallpaper[data-theme="sakura"] {
  background:
    radial-gradient(ellipse 80% 60% at 15% 25%, rgba(255, 190, 210, 0.55), transparent 55%),
    radial-gradient(ellipse 70% 50% at 85% 30%, rgba(230, 190, 240, 0.4), transparent 50%),
    linear-gradient(165deg, #fdf0f4 0%, #f4e8f0 50%, #ebe4f2 100%);
}

.wallpaper[data-theme="night"] {
  background:
    radial-gradient(ellipse 50% 40% at 50% 0%, rgba(100, 140, 220, 0.35), transparent 60%),
    linear-gradient(180deg, #1a2238 0%, #0e1424 100%);
}

.wallpaper-overlay {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background:
    radial-gradient(ellipse 100% 70% at 50% 100%, rgba(255, 255, 255, 0.25), transparent 55%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.15) 0%, transparent 20%, transparent 75%, rgba(180, 200, 230, 0.18) 100%);
}

.wallpaper-overlay::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.03;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 180px 180px;
}

body[data-theme="light"] .wallpaper[data-theme="night"] ~ .wallpaper-overlay,
.wallpaper[data-theme="night"] + .wallpaper-overlay {
  background:
    radial-gradient(ellipse 100% 80% at 50% 100%, rgba(0, 0, 0, 0.35), transparent 55%),
    linear-gradient(180deg, rgba(0, 0, 0, 0.18) 0%, transparent 18%, transparent 70%, rgba(0, 0, 0, 0.28) 100%);
}

/* ---------- Shell ---------- */

.shell {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-rows: var(--status-h) 1fr auto auto;
  grid-template-areas:
    "status"
    "desktop"
    "minibar"
    "dock";
  height: 100dvh;
  max-height: 100dvh;
  padding:
    env(safe-area-inset-top, 0)
    env(safe-area-inset-right, 0)
    env(safe-area-inset-bottom, 0)
    env(safe-area-inset-left, 0);
  pointer-events: none;
}

.shell > * {
  pointer-events: auto;
}

.status-bar { grid-area: status; }
.desktop { grid-area: desktop; }
.minibar { grid-area: minibar; }
.dock { grid-area: dock; }

/* ---------- Status bar ---------- */

.status-bar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  height: var(--status-h);
  padding: 0 20px;
  user-select: none;
}

.status-left {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
  max-width: 100%;
  padding: 6px 12px 6px 14px;
  border-radius: var(--radius-pill);
  background: var(--surface-strong);
  border: 1px solid var(--border);
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  box-shadow: 0 4px 16px rgba(40, 60, 100, 0.08);
}

.brand {
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
  color: var(--text);
  text-shadow: none;
}

.brand-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-center time {
  display: block;
  font-variant-numeric: tabular-nums;
  font-size: 0.92rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  background: var(--surface-strong);
  border: 1px solid var(--border);
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  box-shadow: 0 4px 16px rgba(40, 60, 100, 0.06);
  white-space: nowrap;
  min-width: 4.5em;
  text-align: center;
}

.status-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--surface-strong);
  color: var(--text);
  cursor: pointer;
  transition: background 0.2s var(--ease), transform 0.15s var(--ease), border-color 0.2s;
  box-shadow: 0 2px 10px rgba(40, 60, 100, 0.05);
  text-decoration: none;
  flex-shrink: 0;
}

a.icon-btn.project-link:hover {
  color: var(--text);
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.95);
  border-color: var(--border-strong);
}

.icon-btn:active {
  transform: scale(0.94);
}

.icon-btn[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: rgba(61, 155, 143, 0.35);
  color: var(--accent);
}

.status-pill {
  min-width: 36px;
  height: 28px;
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  border-radius: var(--radius-pill);
  background: var(--surface-strong);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

/* ---------- Search ---------- */

.search-panel {
  position: absolute;
  top: calc(var(--status-h) + 4px);
  left: 0;
  right: 0;
  z-index: 10;
  padding: 0 20px 8px;
  pointer-events: none;
}

.search-panel:not([hidden]) .search-field {
  pointer-events: auto;
}

.search-panel[hidden] {
  display: none;
}

.search-field {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 520px;
  margin: 0 auto;
  padding: 10px 14px;
  border-radius: 16px;
  background: var(--surface-strong);
  border: 1px solid var(--border-strong);
  backdrop-filter: blur(20px) saturate(140%);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  box-shadow: var(--shadow);
}

.search-field svg {
  flex-shrink: 0;
  color: var(--text-soft);
}

.search-field input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: none;
  background: transparent;
  font-size: 0.95rem;
}

.search-field input::placeholder {
  color: var(--text-soft);
}

.search-hint {
  font-size: 0.68rem;
  font-weight: 500;
  color: var(--text-soft);
  padding: 3px 7px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.5);
}

/* ---------- Desktop / App grid ---------- */

.desktop {
  min-height: 0;
  overflow: auto;
  padding: 12px 24px 16px;
  scrollbar-width: thin;
  scrollbar-color: rgba(30, 40, 70, 0.15) transparent;
}

.desktop::-webkit-scrollbar {
  width: 6px;
}

.desktop::-webkit-scrollbar-thumb {
  background: rgba(30, 40, 70, 0.15);
  border-radius: 99px;
}

.app-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 18px 12px;
  max-width: 1100px;
  margin: 0 auto;
  padding: 8px 0 24px;
  justify-items: center;
}

@media (min-width: 640px) {
  .app-grid {
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 24px 16px;
  }
}

@media (min-width: 960px) {
  .app-grid {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 28px 20px;
  }

  :root {
    --icon-size: 80px;
  }
}

/* ---------- App tile ---------- */

.app-tile {
  --tile-color: var(--accent);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
  max-width: 120px;
  padding: 8px 6px;
  border: 0;
  background: transparent;
  cursor: grab;
  text-decoration: none;
  color: inherit;
  border-radius: 18px;
  transition: transform 0.2s var(--ease), background 0.2s var(--ease);
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  animation: tile-in 0.5s var(--ease) both;
  animation-delay: calc(var(--i, 0) * 35ms);
}

.app-tile:hover {
  background: rgba(255, 255, 255, 0.35);
}

.app-tile:active {
  transform: scale(0.94);
}

.app-tile:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.app-icon {
  position: relative;
  width: var(--icon-size);
  height: var(--icon-size);
  border-radius: var(--radius-icon);
  overflow: hidden;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.55), transparent 50%),
    linear-gradient(160deg, color-mix(in srgb, var(--tile-color) 72%, #fff), color-mix(in srgb, var(--tile-color) 42%, #e8eef8));
  box-shadow:
    0 10px 24px color-mix(in srgb, var(--tile-color) 22%, transparent),
    0 1px 0 rgba(255, 255, 255, 0.7) inset,
    0 -1px 0 rgba(0, 0, 0, 0.06) inset;
  transition: transform 0.25s var(--ease), box-shadow 0.25s var(--ease);
}

.app-tile:hover .app-icon {
  transform: translateY(-3px) scale(1.04);
  box-shadow:
    0 16px 32px color-mix(in srgb, var(--tile-color) 30%, transparent),
    0 1px 0 rgba(255, 255, 255, 0.8) inset,
    0 -1px 0 rgba(0, 0, 0, 0.06) inset;
}

.app-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.app-icon .fallback-letter {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: calc(var(--icon-size) * 0.38);
  font-weight: 700;
  color: rgba(255, 255, 255, 0.95);
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
}

.target-badge {
  position: absolute;
  right: 5px;
  bottom: 5px;
  z-index: 2;
  width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  color: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
  pointer-events: none;
}

.target-badge--link {
  background: rgba(40, 55, 90, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.35);
}

.target-badge--folder {
  background: rgba(50, 140, 120, 0.88);
  border: 1px solid rgba(200, 255, 235, 0.45);
}

.dock-tile .target-badge {
  width: 15px;
  height: 15px;
  right: 3px;
  bottom: 3px;
}

.dock-tile .target-badge svg {
  width: 8px;
  height: 8px;
}

.app-label {
  font-size: 0.76rem;
  font-weight: 600;
  line-height: 1.3;
  text-align: center;
  color: #1a2236;
  max-width: 100%;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  word-break: break-word;
  /* Compact glass chip — same family as top-right controls */
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.55);
  backdrop-filter: blur(12px) saturate(140%);
  -webkit-backdrop-filter: blur(12px) saturate(140%);
  box-shadow:
    0 2px 10px rgba(20, 30, 50, 0.12),
    0 1px 0 rgba(255, 255, 255, 0.65) inset;
  text-shadow: none;
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  margin: 48px auto;
  font-size: 0.95rem;
}

/* ---------- Minibar (minimized windows) ---------- */

.minibar {
  display: flex;
  justify-content: center;
  padding: 0 16px 8px;
}

.minibar[hidden] {
  display: none;
}

.minibar-inner {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  max-width: min(960px, 100%);
}

.mini-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px 6px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--surface-strong);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 6px 18px rgba(40, 60, 100, 0.1);
  cursor: pointer;
  color: var(--text);
  font-size: 0.8rem;
  font-weight: 500;
  transition: transform 0.15s var(--ease), background 0.15s;
  max-width: 180px;
}

.mini-chip:hover {
  background: #fff;
  transform: translateY(-1px);
}

.mini-chip:active {
  transform: scale(0.97);
}

.mini-chip-icon {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
  background: color-mix(in srgb, var(--chip-color, var(--accent)) 50%, #fff);
}

.mini-chip-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Dock ---------- */

.dock {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  padding: 0 16px calc(14px + env(safe-area-inset-bottom, 0));
  pointer-events: none;
}

.dock[hidden] {
  display: none;
}

.dock-inner {
  pointer-events: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: var(--dock-h);
  padding: 12px 18px;
  border-radius: var(--radius-panel);
  background: var(--surface-strong);
  border: 1px solid var(--border-strong);
  backdrop-filter: blur(24px) saturate(160%);
  -webkit-backdrop-filter: blur(24px) saturate(160%);
  box-shadow:
    0 16px 40px rgba(40, 60, 100, 0.12),
    0 1px 0 rgba(255, 255, 255, 0.75) inset;
  max-width: calc(100vw - 32px);
  overflow-x: auto;
  scrollbar-width: none;
}

.dock-inner::-webkit-scrollbar {
  display: none;
}

.dock-tile {
  --tile-color: var(--accent);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  width: auto;
  padding: 4px;
  border: 0;
  background: transparent;
  cursor: grab;
  text-decoration: none;
  color: inherit;
  border-radius: 16px;
  transition: transform 0.2s var(--ease);
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

.dock-tile:hover {
  transform: translateY(-4px);
}

.dock-tile:active {
  transform: scale(0.94);
}

.dock-tile:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.dock-tile .app-icon {
  width: var(--icon-size-dock);
  height: var(--icon-size-dock);
  border-radius: 16px;
}

.dock-tile .app-label {
  display: none;
}

/* ---------- Window layer ---------- */

.window-layer {
  position: fixed;
  inset: 0;
  z-index: 20;
  pointer-events: none;
  overflow: hidden;
}

/* Floating window — title controls on the RIGHT */
.win {
  position: absolute;
  display: flex;
  flex-direction: column;
  min-width: 280px;
  min-height: 200px;
  max-width: calc(100vw - 24px);
  max-height: calc(100dvh - 24px);
  border-radius: var(--radius-win);
  background: var(--win-bg);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-win);
  overflow: hidden;
  pointer-events: auto;
  transform-origin: center center;
  animation: win-in 0.28s var(--ease) both;
}

.win.is-minimized {
  display: none;
}

.win.is-maximized {
  left: 12px !important;
  top: 12px !important;
  width: calc(100vw - 24px) !important;
  height: calc(100dvh - 24px) !important;
  border-radius: 12px;
}

/* Compact / phone: fill viewport so iframe width ≈ device width → sites use mobile CSS */
.win.is-maximized.win--compact,
.win.win--compact.is-maximized {
  left: 0 !important;
  top: 0 !important;
  width: 100vw !important;
  height: 100dvh !important;
  max-width: 100vw !important;
  max-height: 100dvh !important;
  border-radius: 0;
  border-left: 0;
  border-right: 0;
}

.win.win--compact .win-titlebar {
  height: 44px;
  padding: 0 8px 0 10px;
  /* Safe area for notched phones */
  padding-top: env(safe-area-inset-top, 0);
  height: calc(44px + env(safe-area-inset-top, 0));
}

.win.win--compact .win-resize {
  display: none;
}

.win.win--compact .win-body {
  /* iframe gets a true narrow CSS viewport */
  width: 100%;
}

.win.win--compact .win-frame {
  width: 100%;
  height: 100%;
  /* Hint some engines to treat as interactive mobile document */
  touch-action: manipulation;
}

.win.is-focused {
  box-shadow:
    0 28px 72px rgba(30, 45, 80, 0.28),
    0 0 0 1px rgba(61, 155, 143, 0.18),
    0 1px 0 rgba(255, 255, 255, 0.8) inset;
}

.win-titlebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  height: var(--titlebar-h);
  padding: 0 10px 0 12px;
  background: var(--win-titlebar);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  cursor: grab;
  user-select: none;
  flex-shrink: 0;
}

.win-titlebar:active {
  cursor: grabbing;
}

.win-title {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--text);
}

.win-title-icon {
  width: 20px;
  height: 20px;
  border-radius: 6px;
  object-fit: cover;
  flex-shrink: 0;
  background: #e8eef6;
}

.win-title-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.win-title-kind {
  flex-shrink: 0;
  font-size: 0.65rem;
  font-weight: 500;
  color: var(--text-soft);
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(30, 40, 70, 0.06);
  border: 1px solid var(--border);
}

/* Right-side window controls (NOT mac left traffic lights) */
.win-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.win-btn {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, transform 0.1s;
}

.win-btn:hover {
  background: rgba(30, 40, 70, 0.08);
  color: var(--text);
}

.win-btn:active {
  transform: scale(0.94);
}

.win-btn--close:hover {
  background: rgba(226, 85, 85, 0.14);
  color: var(--danger);
}

.win-btn--external:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

.win-body {
  position: relative;
  flex: 1;
  min-height: 0;
  background: #fff;
}

.win-frame {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
  background: #fff;
}

.win-loading {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-items: center;
  background: rgba(247, 248, 251, 0.92);
  pointer-events: none;
}

.win-loading-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  color: var(--text-muted);
  font-size: 0.88rem;
  font-weight: 500;
}

.win-loading-spinner {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2.5px solid rgba(30, 40, 70, 0.12);
  border-top-color: var(--accent);
  animation: win-spin 0.7s linear infinite;
}

@keyframes win-spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .win-loading-spinner {
    animation: none;
    border-top-color: rgba(30, 40, 70, 0.25);
  }
}

.win-fallback {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  place-items: center;
  padding: 28px;
  text-align: center;
  background:
    radial-gradient(ellipse 70% 50% at 50% 0%, rgba(170, 210, 255, 0.25), transparent 55%),
    #f7f8fb;
}

.win-fallback-card {
  max-width: 360px;
}

.win-fallback-card h3 {
  margin: 0 0 8px;
  font-size: 1.1rem;
}

.win-fallback-card p {
  margin: 0 0 18px;
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.55;
}

.win-fallback-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
}

.btn-primary,
.btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 10px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  border: 1px solid transparent;
  transition: transform 0.12s, background 0.15s;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: color-mix(in srgb, var(--accent) 80%, #000);
}

.btn-primary:hover {
  filter: brightness(1.05);
}

.btn-ghost {
  background: #fff;
  color: var(--text);
  border-color: var(--border-strong);
}

.btn-ghost:hover {
  background: #f0f3f8;
}

.btn-primary:active,
.btn-ghost:active {
  transform: scale(0.97);
}

/* Resize handles — all edges & corners */
.win-resize-handles {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
}

.win-rh {
  position: absolute;
  pointer-events: auto;
  touch-action: none;
  /* Larger hit area, invisible */
  background: transparent;
}

.win-rh--n {
  top: -3px;
  left: 10px;
  right: 10px;
  height: 8px;
  cursor: ns-resize;
}
.win-rh--s {
  bottom: -3px;
  left: 10px;
  right: 10px;
  height: 8px;
  cursor: ns-resize;
}
.win-rh--e {
  right: -3px;
  top: 10px;
  bottom: 10px;
  width: 8px;
  cursor: ew-resize;
}
.win-rh--w {
  left: -3px;
  top: 10px;
  bottom: 10px;
  width: 8px;
  cursor: ew-resize;
}
.win-rh--ne {
  top: -4px;
  right: -4px;
  width: 14px;
  height: 14px;
  cursor: nesw-resize;
}
.win-rh--nw {
  top: -4px;
  left: -4px;
  width: 14px;
  height: 14px;
  cursor: nwse-resize;
}
.win-rh--se {
  bottom: -4px;
  right: -4px;
  width: 16px;
  height: 16px;
  cursor: nwse-resize;
}
.win-rh--se::after {
  content: "";
  position: absolute;
  right: 3px;
  bottom: 3px;
  width: 8px;
  height: 8px;
  border-right: 2px solid rgba(30, 40, 70, 0.28);
  border-bottom: 2px solid rgba(30, 40, 70, 0.28);
}
.win-rh--sw {
  bottom: -4px;
  left: -4px;
  width: 14px;
  height: 14px;
  cursor: nesw-resize;
}

.win.is-maximized .win-resize-handles,
.win.win--compact .win-resize-handles {
  display: none;
}

/* While dragging/resizing: no iframe paint fighting */
.win.is-interacting {
  will-change: left, top, width, height;
  user-select: none;
}

.win.is-interacting .win-frame {
  pointer-events: none !important;
}

/* ---------- Icon drag (Android-like) ---------- */

.icon-drag-layer {
  position: fixed;
  inset: 0;
  z-index: 90;
  pointer-events: none;
  overflow: visible;
}

/* Floating icon under finger — position via left/top in JS */
.icon-drag-ghost {
  position: fixed !important;
  top: 0;
  left: 0;
  margin: 0 !important;
  max-width: none !important;
  opacity: 1;
  z-index: 100;
  pointer-events: none !important;
  will-change: left, top;
  filter: drop-shadow(0 16px 28px rgba(30, 45, 80, 0.35));
  transition: none !important;
  animation: none !important;
  cursor: grabbing;
}

.icon-drag-ghost .app-icon {
  transform: none !important;
  box-shadow:
    0 14px 32px color-mix(in srgb, var(--tile-color, #3d9b8f) 40%, transparent),
    0 2px 0 rgba(255, 255, 255, 0.5) inset;
}

/* Empty hole where the icon was */
.drag-slot {
  box-sizing: border-box;
  border-radius: 18px;
  border: 2px dashed rgba(61, 155, 143, 0.45);
  background: rgba(61, 155, 143, 0.08);
  flex-shrink: 0;
  pointer-events: none;
  transition: none;
}

.drag-slot--grid {
  width: 100%;
  max-width: 120px;
  min-height: 100px;
  justify-self: center;
}

.drag-slot--dock {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  align-self: center;
}

.app-tile,
.dock-tile {
  /* enable FLIP squeeze */
  will-change: transform;
}

.dock.is-drop-target .dock-inner {
  box-shadow:
    0 0 0 2px rgba(61, 155, 143, 0.5),
    0 16px 40px rgba(40, 60, 100, 0.12);
  background: rgba(255, 255, 255, 0.9);
}

.app-grid.is-drop-target {
  /* subtle — real feedback is the moving slot */
}

.dock-inner.is-empty {
  min-width: 140px;
  min-height: 56px;
  justify-content: center;
}

.dock-empty-hint {
  font-size: 0.78rem;
  color: var(--text-soft);
  padding: 0 8px;
  user-select: none;
  pointer-events: none;
}

body.is-icon-dragging {
  cursor: grabbing !important;
  user-select: none !important;
  -webkit-user-select: none !important;
  touch-action: none;
}

body.is-icon-dragging .win-frame {
  pointer-events: none !important;
}

body.is-icon-dragging .app-tile,
body.is-icon-dragging .dock-tile {
  cursor: grabbing;
}

.settings-row--stack {
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
}

.settings-check {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  font-size: 0.84rem;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.settings-check input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.wallpaper-preview {
  margin: 0 14px 12px;
  height: 88px;
  border-radius: 12px;
  background-size: cover;
  background-position: center;
  border: 1px solid var(--border);
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--dock-h) + 48px);
  transform: translateX(-50%) translateY(12px);
  z-index: 50;
  padding: 10px 16px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--border-strong);
  color: var(--text);
  font-size: 0.85rem;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s var(--ease), transform 0.25s var(--ease);
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast[hidden] {
  display: block;
  opacity: 0;
}

/* ---------- Noscript ---------- */

.noscript {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #eef3fb;
  color: #1a2236;
  text-align: center;
}

.noscript code {
  font-family: ui-monospace, monospace;
  background: rgba(30, 40, 70, 0.08);
  padding: 2px 6px;
  border-radius: 4px;
}

/* ---------- Animations ---------- */

@keyframes tile-in {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes win-in {
  from {
    opacity: 0;
    transform: scale(0.94) translateY(10px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .app-tile,
  .win {
    animation: none;
  }

  .app-tile:hover .app-icon,
  .dock-tile:hover,
  .app-tile:active,
  .dock-tile:active,
  .icon-btn:active,
  .mini-chip:hover {
    transform: none;
  }

  .wallpaper,
  .app-icon,
  .toast {
    transition: none;
  }
}

/* ---------- Mobile ---------- */

/* ---------- Settings panel (inside window body) ---------- */

.settings {
  height: 100%;
  overflow: auto;
  padding: 18px 20px 28px;
  background: linear-gradient(180deg, #fbfcfe 0%, #f4f6fa 100%);
  color: var(--text);
}

.settings-banner {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px 14px;
  margin-bottom: 18px;
  border-radius: 12px;
  background: rgba(61, 155, 143, 0.1);
  border: 1px solid rgba(61, 155, 143, 0.22);
  font-size: 0.82rem;
  line-height: 1.5;
  color: var(--text-muted);
}

.settings-banner strong {
  color: var(--accent);
  font-weight: 700;
}

.settings-banner code {
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 0.9em;
  padding: 0.05em 0.35em;
  border-radius: 4px;
  background: rgba(30, 40, 70, 0.06);
}

.settings-banner a {
  color: var(--accent);
  font-weight: 600;
  word-break: break-all;
}

.settings-section {
  margin-bottom: 22px;
}

.settings-section h3 {
  margin: 0 0 10px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-soft);
}

.settings-card {
  border-radius: 14px;
  background: #fff;
  border: 1px solid var(--border);
  box-shadow: 0 4px 16px rgba(40, 60, 100, 0.04);
  overflow: hidden;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 13px 14px;
  border-bottom: 1px solid rgba(30, 40, 70, 0.06);
}

.settings-row:last-child {
  border-bottom: 0;
}

.settings-row-text {
  min-width: 0;
  flex: 1;
}

.settings-row-title {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
}

.settings-row-desc {
  display: block;
  margin-top: 3px;
  font-size: 0.76rem;
  color: var(--text-muted);
  line-height: 1.4;
}

/* Toggle switch */
.switch {
  position: relative;
  width: 44px;
  height: 26px;
  flex-shrink: 0;
}

.switch input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.switch-slider {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: rgba(30, 40, 70, 0.14);
  cursor: pointer;
  transition: background 0.2s var(--ease);
}

.switch-slider::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18);
  transition: transform 0.2s var(--ease);
}

.switch input:checked + .switch-slider {
  background: var(--accent);
}

.switch input:checked + .switch-slider::after {
  transform: translateX(18px);
}

.switch input:focus-visible + .switch-slider {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.settings-select {
  min-width: 140px;
  max-width: 46%;
  padding: 7px 10px;
  border-radius: 9px;
  border: 1px solid var(--border-strong);
  background: #f7f8fb;
  color: var(--text);
  font-size: 0.84rem;
  font-weight: 500;
  cursor: pointer;
}

.settings-select:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent);
  outline-offset: 1px;
}

.settings-select:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  background: #eef0f4;
}

.settings-row.is-disabled {
  opacity: 0.92;
}

.settings-row.is-disabled .settings-row-title {
  opacity: 0.85;
}

.settings-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 4px;
}

/* App list in settings */
.app-prop-list {
  display: flex;
  flex-direction: column;
}

.app-prop-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 11px 14px;
  border: 0;
  border-bottom: 1px solid rgba(30, 40, 70, 0.06);
  background: transparent;
  text-align: left;
  cursor: pointer;
  color: inherit;
  transition: background 0.15s;
}

.app-prop-item:last-child {
  border-bottom: 0;
}

.app-prop-item:hover {
  background: rgba(61, 155, 143, 0.06);
}

.app-prop-item:active {
  background: rgba(61, 155, 143, 0.1);
}

.app-prop-icon {
  width: 40px;
  height: 40px;
  border-radius: 11px;
  object-fit: cover;
  flex-shrink: 0;
  background: #e8eef6;
  box-shadow: 0 2px 8px rgba(40, 60, 100, 0.08);
}

.app-prop-meta {
  min-width: 0;
  flex: 1;
}

.app-prop-name {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
}

.app-prop-hint {
  display: block;
  margin-top: 2px;
  font-size: 0.74rem;
  color: var(--text-soft);
}

.app-prop-chevron {
  color: var(--text-soft);
  flex-shrink: 0;
}

/* App property detail view */
.prop-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 14px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: #fff;
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}

.prop-back:hover {
  background: #f4f6fa;
}

.prop-hero {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
  padding: 14px;
  border-radius: 14px;
  background: #fff;
  border: 1px solid var(--border);
}

.prop-hero img {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  object-fit: cover;
  background: #e8eef6;
}

.prop-hero h2 {
  margin: 0 0 4px;
  font-size: 1.1rem;
}

.prop-hero p {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.prop-table {
  width: 100%;
  border-collapse: collapse;
  border-radius: 14px;
  overflow: hidden;
  background: #fff;
  border: 1px solid var(--border);
}

.prop-table th,
.prop-table td {
  padding: 11px 14px;
  text-align: left;
  font-size: 0.84rem;
  border-bottom: 1px solid rgba(30, 40, 70, 0.06);
  vertical-align: top;
}

.prop-table tr:last-child th,
.prop-table tr:last-child td {
  border-bottom: 0;
}

.prop-table th {
  width: 32%;
  color: var(--text-muted);
  font-weight: 500;
  background: rgba(30, 40, 70, 0.02);
}

.prop-table td {
  font-weight: 500;
  word-break: break-all;
}

.prop-type-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
}

.prop-type-pill--folder {
  background: rgba(50, 140, 120, 0.12);
  color: #2a7a6a;
  border: 1px solid rgba(50, 140, 120, 0.25);
}

.prop-type-pill--link {
  background: rgba(70, 100, 180, 0.1);
  color: #3a5a9a;
  border: 1px solid rgba(70, 100, 180, 0.22);
}

.prop-type-pill--none {
  background: rgba(30, 40, 70, 0.06);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

body.is-no-motion .app-tile,
body.is-no-motion .win {
  animation: none !important;
}

body.is-no-motion .app-tile:hover .app-icon,
body.is-no-motion .dock-tile:hover {
  transform: none !important;
}

/* ---------- Warning modal ---------- */

.warn-modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(20, 24, 40, 0.45);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  animation: warn-in 0.2s var(--ease) both;
}

.warn-modal[hidden] {
  display: none;
}

.warn-dialog {
  width: min(400px, 100%);
  padding: 22px 22px 18px;
  border-radius: 18px;
  background: #fff;
  border: 1px solid var(--border-strong);
  box-shadow: 0 24px 64px rgba(20, 30, 50, 0.28);
  color: var(--text);
}

.warn-badge {
  display: inline-block;
  margin-bottom: 10px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: #a63d3d;
  background: rgba(226, 85, 85, 0.12);
  border: 1px solid rgba(226, 85, 85, 0.25);
}

.warn-title {
  margin: 0 0 10px;
  font-size: 1.1rem;
  font-weight: 700;
}

.warn-message {
  margin: 0 0 20px;
  font-size: 0.92rem;
  line-height: 1.65;
  color: var(--text-muted);
  white-space: pre-wrap;
}

.warn-actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px;
}

@keyframes warn-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@media (max-width: 768px) {
  .brand-sub {
    display: none;
  }

  .status-bar {
    padding: 0 14px;
  }

  .desktop {
    padding: 8px 12px 12px;
  }

  .app-grid {
    grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
    gap: 14px 8px;
  }

  :root {
    --icon-size: 64px;
    --icon-size-dock: 50px;
    --radius-icon: 18px;
  }

  /* Non-maximized windows also go near full-bleed on phones */
  .win:not(.is-maximized) {
    left: 0 !important;
    top: 0 !important;
    width: 100vw !important;
    height: 100dvh !important;
    min-width: 0;
    border-radius: 0;
  }

  .win-resize {
    display: none;
  }

  .warn-dialog {
    padding: 20px 18px 16px;
  }
}

@media (max-width: 480px) {
  :root {
    --icon-size: 60px;
    --icon-size-dock: 48px;
  }
}
