:root {
  --control-size: 44px;
  --toolbar-symbol-size: 24px;
  --selection-done-symbol-size: 33px;
  --export-symbol-size: 37px;
  --trash-symbol-size: 35px;
  --label: #1c1c1e;
  --secondary: #6e6e73;
  --blue: #0a84ff;
  --red: #ff3b30;
  --glass-fill:
    radial-gradient(125% 135% at 10% -28%, rgba(255, 255, 255, 0.96) 0%, rgba(255, 255, 255, 0.35) 42%, transparent 66%),
    linear-gradient(145deg, rgba(255, 255, 255, 0.68) 0%, rgba(255, 255, 255, 0.25) 54%, rgba(255, 255, 255, 0.48) 100%);
  --glass-border: rgba(255, 255, 255, 0.94);
  --glass-filter: blur(28px) saturate(1.7) brightness(1.15);
  --glass-shadow:
    0 10px 30px rgba(0, 0, 0, 0.07),
    0 2px 5px rgba(0, 0, 0, 0.025),
    inset 0 1.2px 0 rgba(255, 255, 255, 0.98),
    inset 0 -0.7px 0 rgba(60, 60, 67, 0.055);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", sans-serif;
  color: var(--label);
  background: #f2f2f7;
  -webkit-font-smoothing: antialiased;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #f2f2f7;
}

body {
  display: grid;
  place-items: start center;
  overscroll-behavior: none;
  -webkit-touch-callout: none;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  color: inherit;
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition:
    transform 160ms cubic-bezier(0.22, 1, 0.36, 1),
    filter 140ms cubic-bezier(0.25, 0.1, 0.25, 1),
    opacity 120ms cubic-bezier(0.25, 0.1, 0.25, 1);
}

.text-button:active,
.icon-button:active,
.batch-button:active,
.popover button:active {
  filter: brightness(1.09);
  transform: scale(1.04);
}

button:active .system-symbol,
button:active .plus-symbol,
button:active .sort-symbol,
button:active > span:last-child {
  opacity: 0.52;
}

button:disabled {
  cursor: default;
}

.library {
  --house-content-top: 157px;
  position: relative;
  width: min(100vw, 430px);
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 90% 8%, rgba(255, 255, 255, 0.56), transparent 28%),
    #f2f2f7;
}

.glass {
  border: 0.5px solid var(--glass-border);
  background: var(--glass-fill);
  -webkit-backdrop-filter: var(--glass-filter);
  backdrop-filter: var(--glass-filter);
  box-shadow: var(--glass-shadow);
}

.topbar {
  position: absolute;
  z-index: 20;
  top: 0;
  right: 16px;
  left: 16px;
  height: 86px;
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: end;
  padding-bottom: 14px;
}

.title {
  align-self: end;
  justify-self: start;
  padding: 0 0 6px 2px;
  font-family: -apple-system, BlinkMacSystemFont, "Apple Color Emoji", sans-serif;
  font-size: 25px;
  font-weight: 600;
  line-height: 30px;
  letter-spacing: 0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  cursor: default;
}

.top-actions {
  display: flex;
  align-items: center;
  justify-self: end;
  gap: 6px;
}

.text-button {
  width: 62px;
  height: var(--control-size);
  border-radius: calc(var(--control-size) / 2);
  color: #3a3a3c;
  font-size: 16px;
  font-weight: 500;
}

.icon-button {
  width: var(--control-size);
  height: var(--control-size);
  display: grid;
  place-items: center;
  border-radius: 50%;
}

.icon-button.selection-done {
  display: none;
  justify-self: end;
  color: #fff;
  background: linear-gradient(145deg, rgba(255, 225, 64, 0.98), rgba(247, 202, 5, 0.9));
}

.add-button {
  flex: 0 0 var(--control-size);
  width: var(--control-size);
  height: var(--control-size);
  display: grid;
  place-items: center;
  border: 0.5px solid var(--glass-border);
  border-radius: 50%;
  color: #fff;
  background: linear-gradient(145deg, rgba(255, 217, 28, 0.96), rgba(242, 197, 0, 0.82));
  box-shadow:
    0 5px 15px rgba(0, 0, 0, 0.065),
    0 1px 2px rgba(0, 0, 0, 0.035),
    inset 0 1px 0 rgba(255, 255, 255, 0.68),
    inset 0 -0.5px 0 rgba(60, 60, 67, 0.06);
}

.add-button:active {
  background: linear-gradient(145deg, rgba(255, 229, 74, 0.99), rgba(250, 207, 20, 0.94));
}

.plus-symbol {
  position: relative;
  width: var(--toolbar-symbol-size);
  height: var(--toolbar-symbol-size);
}

.plus-symbol::before,
.plus-symbol::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 19px;
  height: 2.4px;
  border-radius: 2px;
  background: currentColor;
  transform: translate(-50%, -50%);
}

.plus-symbol::after {
  transform: translate(-50%, -50%) rotate(90deg);
}

.sort-symbol {
  width: var(--toolbar-symbol-size);
  height: var(--toolbar-symbol-size);
  display: grid;
  align-content: center;
  gap: 4px;
}

.sort-symbol i {
  height: 2px;
  border-radius: 2px;
  background: #3a3a3c;
}

.sort-symbol i:nth-child(1) { width: 22px; }
.sort-symbol i:nth-child(2) { width: 16px; }
.sort-symbol i:nth-child(3) { width: 10px; }

.house-grid {
  display: grid;
  grid-template-columns: repeat(var(--columns, 2), minmax(0, 1fr));
  gap: 22px 14px;
  height: 100%;
  min-height: 0;
  padding: var(--house-content-top) 0 max(36px, env(safe-area-inset-bottom));
  overflow-x: hidden;
  overflow-y: auto;
  align-content: start;
  transform-origin: center top;
  touch-action: pan-y pinch-zoom;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  -webkit-mask-image: linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0.16) 0,
    rgba(0, 0, 0, 0.58) 62px,
    #000 136px
  );
  mask-image: linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0.16) 0,
    rgba(0, 0, 0, 0.58) 62px,
    #000 136px
  );
}

.house-grid::-webkit-scrollbar {
  display: none;
}

.house-scroll-frame {
  position: absolute;
  inset: 0 16px;
  overflow: hidden;
}

.house-scroll-fade {
  position: absolute;
  z-index: 8;
  top: 0;
  right: 0;
  left: 0;
  height: 110px;
  pointer-events: none;
  opacity: 0;
  background: linear-gradient(
    to bottom,
    rgba(242, 242, 247, 0.2) 0%,
    rgba(242, 242, 247, 0.065) 54%,
    rgba(242, 242, 247, 0) 100%
  );
  -webkit-backdrop-filter: blur(4px) saturate(1.04);
  backdrop-filter: blur(4px) saturate(1.04);
  -webkit-mask-image: linear-gradient(to bottom, #000 0%, rgba(0, 0, 0, 0.68) 58%, transparent 100%);
  mask-image: linear-gradient(to bottom, #000 0%, rgba(0, 0, 0, 0.68) 58%, transparent 100%);
  will-change: opacity;
}

.house-item {
  min-width: 0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  cursor: pointer;
  outline: 0;
  -webkit-tap-highlight-color: transparent;
}

.house-item:focus-visible {
  outline: 2px solid rgba(10, 132, 255, 0.52);
  outline-offset: 3px;
  border-radius: 8px;
}

.house-art {
  position: relative;
  width: 100%;
  aspect-ratio: 980 / 1107;
  transition:
    filter 180ms cubic-bezier(0.22, 1, 0.36, 1),
    transform 220ms cubic-bezier(0.22, 1, 0.36, 1);
}

.house-art > img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

.sticker-window {
  position: absolute;
  z-index: 1;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  -webkit-mask: url("../assets/house_canvas.png") center / contain no-repeat;
  mask: url("../assets/house_canvas.png") center / contain no-repeat;
}

.mini-sticker {
  position: absolute;
  font-family: "Apple Color Emoji";
  font-size: 16px;
  line-height: 1;
  transform: translate(-50%, -50%);
}

.sticker-1 { left: 50%; top: 46.2%; }
.sticker-2 { left: 63.6%; top: 60.7%; font-size: 18px; }
.sticker-3 { left: 35%; top: 68.3%; font-size: 18px; }

.house-info {
  position: relative;
  padding: 7px 2px 0;
}

.house-info h2 {
  margin: 0;
  overflow: hidden;
  font-size: 15px;
  font-weight: 600;
  line-height: 19px;
  letter-spacing: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.inline-name-input {
  width: 100%;
  height: 19px;
  margin: 0;
  padding: 0 3px 0 2px;
  border: 0;
  border-radius: 0;
  outline: 0;
  color: var(--label);
  caret-color: var(--blue);
  font-size: 15px;
  font-weight: 600;
  line-height: 19px;
  letter-spacing: 0;
  background: transparent;
  box-shadow: none;
  -webkit-appearance: none;
  appearance: none;
  -webkit-tap-highlight-color: transparent;
  will-change: transform, opacity;
}

.inline-name-input::selection {
  color: var(--label);
  background: rgba(10, 132, 255, 0.18);
}

.house-info p {
  margin: 2px 0 0;
  color: var(--secondary);
  font-size: 11px;
  line-height: 15px;
}

.selection-check {
  position: absolute;
  z-index: 4;
  right: 2px;
  bottom: 2px;
  width: 31px;
  height: 31px;
  display: none;
  place-items: center;
  border: 2.5px solid #fff;
  border-radius: 50%;
  background: var(--blue);
  box-shadow: 0 2px 7px rgba(0, 0, 0, 0.13);
}

.selection-check i {
  width: 15px;
  height: 9px;
  border-left: 2.4px solid #fff;
  border-bottom: 2.4px solid #fff;
  transform: translateY(-1px) rotate(-45deg);
}

.batch-actions {
  position: fixed;
  z-index: 20;
  left: max(18px, calc((100vw - 430px) / 2 + 18px));
  right: max(18px, calc((100vw - 430px) / 2 + 18px));
  bottom: max(22px, env(safe-area-inset-bottom));
}

.library-bottom {
  position: absolute;
  z-index: 20;
  top: 87px;
  right: 16px;
  left: 16px;
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 0;
}

.search-field {
  min-width: 0;
  height: 48px;
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 15px;
  border-color: rgba(255, 255, 255, 0.34);
  border-radius: 24px;
  background:
    radial-gradient(120% 170% at 8% -54%, rgba(255, 255, 255, 0.42) 0%, rgba(255, 255, 255, 0.07) 48%, transparent 72%),
    linear-gradient(145deg, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0.035));
  -webkit-backdrop-filter: blur(10px) saturate(1.6) brightness(1.07);
  backdrop-filter: blur(10px) saturate(1.6) brightness(1.07);
  box-shadow:
    0 6px 20px rgba(0, 0, 0, 0.028),
    inset 0 1px 0 rgba(255, 255, 255, 0.58),
    inset 0 -0.5px 0 rgba(60, 60, 67, 0.018);
}

.search-field input {
  min-width: 0;
  width: 100%;
  padding: 0;
  border: 0;
  outline: 0;
  color: var(--label);
  font-size: 16px;
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
}

.search-field input::placeholder {
  color: var(--secondary);
  opacity: 1;
}

.batch-actions {
  display: none;
  justify-content: space-between;
  pointer-events: none;
}

.batch-button {
  width: var(--control-size);
  min-width: var(--control-size);
  height: var(--control-size);
  display: grid;
  place-items: center;
  padding: 0;
  border-radius: 50%;
  pointer-events: auto;
}

.batch-button .system-symbol {
  width: var(--toolbar-symbol-size);
  height: var(--toolbar-symbol-size);
}

.batch-button .symbol-export {
  width: var(--export-symbol-size);
  height: var(--export-symbol-size);
  transform: translateY(-1px);
}

.batch-button .symbol-trash {
  width: var(--trash-symbol-size);
  height: var(--trash-symbol-size);
}

.batch-button:disabled {
  opacity: 0.34;
  pointer-events: none;
}

.delete-action,
.destructive {
  color: var(--red);
}

.system-symbol {
  --symbol: none;
  width: var(--toolbar-symbol-size);
  height: var(--toolbar-symbol-size);
  display: block;
  flex: 0 0 auto;
  background: currentColor;
  -webkit-mask: var(--symbol) center / contain no-repeat;
  mask: var(--symbol) center / contain no-repeat;
}

.symbol-export { --symbol: url("../symbols/export.png?v=7"); }
.symbol-trash { --symbol: url("../symbols/trash.png"); }
.symbol-search { --symbol: url("../symbols/search.png"); }
.symbol-check { --symbol: url("../symbols/check.png?v=1"); }
.symbol-edit { --symbol: url("../symbols/edit.png"); }
.symbol-copy { --symbol: url("../symbols/copy.png"); }

.search-field .system-symbol {
  width: var(--toolbar-symbol-size);
  height: var(--toolbar-symbol-size);
  color: var(--secondary);
}

.selection-done .system-symbol {
  width: var(--selection-done-symbol-size);
  height: var(--selection-done-symbol-size);
}

.popover {
  position: fixed;
  z-index: 60;
  overflow: hidden;
  border-radius: 20px;
  transform-origin: top right;
}

.sort-menu {
  top: 72px;
  right: max(16px, calc((100vw - 430px) / 2 + 16px));
  width: 168px;
  padding: 6px;
}

.sort-menu button,
.context-menu button {
  width: 100%;
  height: 44px;
  display: flex;
  align-items: center;
  border-radius: 14px;
}

.sort-menu button {
  justify-content: space-between;
  padding: 0 12px;
  font-size: 15px;
}

.sort-menu button[aria-checked="true"] {
  background: rgba(255, 255, 255, 0.42);
}

.sort-menu i {
  min-width: 14px;
  color: var(--blue);
  font-style: normal;
  font-weight: 650;
}

.context-menu {
  width: 184px;
  padding: 6px;
  transform-origin: center top;
}

.context-menu button {
  gap: 10px;
  padding: 0 12px;
  font-size: 15px;
  text-align: left;
}

.context-menu .system-symbol {
  width: var(--toolbar-symbol-size);
  height: var(--toolbar-symbol-size);
}

.popover-separator,
.confirm-separator {
  height: 0.5px;
  background: rgba(60, 60, 67, 0.15);
}

.popover-separator {
  margin: 4px 9px;
}

.confirm-popover {
  left: max(18px, calc((100vw - 430px) / 2 + 18px));
  right: max(18px, calc((100vw - 430px) / 2 + 18px));
  bottom: max(84px, calc(env(safe-area-inset-bottom) + 64px));
  max-width: 300px;
  margin: 0 auto;
  transform-origin: center bottom;
}

.confirm-copy {
  display: grid;
  gap: 3px;
  padding: 17px 18px 14px;
  text-align: center;
}

.confirm-copy strong {
  font-size: 16px;
  line-height: 20px;
}

.confirm-copy span {
  color: var(--secondary);
  font-size: 13px;
  line-height: 17px;
}

.confirm-separator {
  margin: 0 14px;
}

.confirm-popover button {
  width: 100%;
  height: 50px;
  color: var(--red);
  font-size: 16px;
  font-weight: 600;
}

.toast {
  position: fixed;
  z-index: 80;
  left: 50%;
  top: 96px;
  min-width: 108px;
  max-width: min(300px, calc(100vw - 36px));
  padding: 10px 14px;
  border-radius: 18px;
  color: #3a3a3c;
  font-size: 14px;
  font-weight: 550;
  text-align: center;
  transform: translateX(-50%);
  pointer-events: none;
}

.empty-library {
  grid-column: 1 / -1;
  padding: 96px 16px;
  color: var(--secondary);
  font-size: 15px;
  text-align: center;
}

.selection-mode .top-actions,
.selection-mode .library-bottom {
  display: none;
}

.selection-mode .library {
  --house-content-top: 99px;
}

.selection-mode .house-grid {
  padding-bottom: max(112px, calc(92px + env(safe-area-inset-bottom)));
  touch-action: pan-y;
}

.selection-mode .icon-button.selection-done {
  display: grid;
}

.selection-mode .batch-actions {
  display: flex;
}

.selection-mode .selected .selection-check {
  display: grid;
}

.selection-mode .selected .house-art {
  filter: brightness(1.15) saturate(0.82);
}

.compact-grid .house-grid {
  gap: 17px 7px;
  padding-top: var(--house-content-top);
}

.compact-grid .house-info {
  padding-top: 4px;
}

.compact-grid .house-info h2 {
  font-size: 11px;
  line-height: 14px;
}

.compact-grid .inline-name-input {
  height: 14px;
  font-size: 11px;
  line-height: 14px;
}

.compact-grid .house-info p {
  display: none;
}

.compact-grid .mini-sticker {
  font-size: 9px;
}

.compact-grid .sticker-2,
.compact-grid .sticker-3 {
  font-size: 10px;
}

.columns-1 .house-grid {
  width: 100%;
  max-width: none;
  margin-inline: 0;
  padding-right: max(12px, calc((100% - 326px) / 2));
  padding-left: max(12px, calc((100% - 326px) / 2));
}

@media (max-width: 360px) {
  .topbar,
  .library-bottom {
    right: 13px;
    left: 13px;
  }

  .house-scroll-frame {
    right: 13px;
    left: 13px;
  }
}

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