* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif; }
body { background: #0f1020; color: #fff; overflow: hidden; }
#app { position: relative; width: 100%; height: 100%; }
.hidden { display: none !important; }

.view { position: absolute; inset: 0; display: flex; flex-direction: column; }

/* ---------- Wallpaper ---------- */
.wallpaper {
  position: absolute; inset: 0; z-index: 0;
  background:
    radial-gradient(circle at 20% 15%, #5b7cfa 0%, transparent 45%),
    radial-gradient(circle at 85% 20%, #a855f7 0%, transparent 40%),
    radial-gradient(circle at 50% 90%, #ec4899 0%, transparent 45%),
    linear-gradient(160deg, #1e1b4b 0%, #0f1020 100%);
}
.wallpaper::after {
  content: ""; position: absolute; inset: 0;
  backdrop-filter: blur(2px);
  background: rgba(10, 10, 30, 0.35);
}

/* ---------- Login ---------- */
.login-view { align-items: center; justify-content: center; }
.login-card {
  position: relative; z-index: 2;
  width: min(360px, 86vw);
  padding: 36px 28px 28px;
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid rgba(255, 255, 255, 0.22);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
  text-align: center;
}
.login-logo { font-size: 52px; line-height: 1; margin-bottom: 10px; }
.login-card h1 { margin: 0 0 4px; font-size: 24px; font-weight: 700; }
.login-sub { margin: 0 0 22px; font-size: 13px; opacity: 0.8; }
.login-card form { display: flex; flex-direction: column; gap: 12px; }
.login-card input, .field input {
  width: 100%; padding: 13px 14px; font-size: 15px;
  border-radius: 12px; border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.14); color: #fff; outline: none;
  transition: border-color .15s, background .15s;
}
.login-card input::placeholder, .field input::placeholder { color: rgba(255, 255, 255, 0.55); }
.login-card input:focus, .field input:focus { border-color: rgba(167, 139, 250, 0.9); background: rgba(255, 255, 255, 0.2); }
.hint { margin: 18px 0 0; font-size: 12px; opacity: 0.7; }

/* ---------- Buttons ---------- */
.btn {
  border: none; cursor: pointer; padding: 12px 18px; font-size: 15px;
  border-radius: 12px; font-weight: 600; transition: transform .1s, opacity .15s, background .15s;
}
.btn:active { transform: scale(0.97); }
.btn.primary { background: linear-gradient(135deg, #6366f1, #a855f7); color: #fff; box-shadow: 0 6px 18px rgba(124, 58, 237, 0.45); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: rgba(255, 255, 255, 0.12); color: #fff; }
.btn.ghost:hover { background: rgba(255, 255, 255, 0.22); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.form-error { margin-top: 10px; color: #ffb4b4; font-size: 13px; min-height: 18px; }

/* ---------- Home ---------- */
.home-view .wallpaper::after { background: rgba(8, 8, 24, 0.28); }
.topbar {
  position: relative; z-index: 2; display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px 10px;
}
.topbar-title { display: flex; align-items: center; gap: 8px; font-size: 18px; font-weight: 700; }
.topbar-emoji { font-size: 22px; }
.topbar-actions { display: flex; gap: 6px; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 50%; border: none; cursor: pointer;
  background: rgba(255, 255, 255, 0.16); color: #fff; font-size: 17px;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s, transform .1s;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.28); }
.icon-btn:active { transform: scale(0.92); }
.icon-btn.active { background: rgba(236, 72, 153, 0.85); }

.screen { position: relative; z-index: 1; flex: 1; overflow-y: auto; padding: 8px 14px 20px; }

/* ---------- Icon grid (phone home screen style) ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 18px 10px;
  padding: 12px 4px;
}
@media (min-width: 540px) { .grid { grid-template-columns: repeat(5, 1fr); } }
@media (min-width: 760px) { .grid { grid-template-columns: repeat(6, 1fr); } }
@media (min-width: 1024px) { .grid { grid-template-columns: repeat(8, 1fr); } }

.tile {
  display: flex; flex-direction: column; align-items: center; gap: 7px;
  cursor: pointer; user-select: none; position: relative;
  animation: pop .25s ease;
}
@keyframes pop { from { transform: scale(0.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.tile .app-icon {
  width: 58px; height: 58px; border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  font-size: 30px; color: #fff;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.35);
  transition: transform .12s;
}
@media (min-width: 540px) { .tile .app-icon { width: 64px; height: 64px; font-size: 32px; } }
.tile:active .app-icon { transform: scale(0.9); }
.tile .app-name {
  font-size: 12px; text-align: center; color: #fff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
  max-width: 72px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* Add tile */
.tile.add .app-icon {
  background: rgba(255, 255, 255, 0.18);
  border: 2px dashed rgba(255, 255, 255, 0.5);
  font-size: 32px; box-shadow: none;
}

/* Edit mode badges */
.tile .badge {
  position: absolute; top: -6px; width: 22px; height: 22px; border-radius: 50%;
  display: none; align-items: center; justify-content: center; font-size: 12px;
  color: #fff; cursor: pointer; border: none; box-shadow: 0 2px 6px rgba(0,0,0,0.4);
}
.tile .del { right: 6px; background: #ff3b30; }
.tile .edt { left: 6px; background: #34c759; }
body.edit .tile .badge { display: flex; }
body.edit .tile { animation: wiggle 0.6s ease-in-out infinite; }
@keyframes wiggle {
  0%, 100% { transform: rotate(-1.2deg); }
  50% { transform: rotate(1.2deg); }
}
body.edit .tile.add { animation: none; }

.hint-bar {
  position: relative; z-index: 2; text-align: center; padding: 8px 12px calc(env(safe-area-inset-bottom, 0px) + 10px);
  font-size: 12px; opacity: 0.75;
}

/* ---------- Modals ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.55); backdrop-filter: blur(4px); }
.modal-card {
  position: relative; z-index: 2; width: min(380px, 92vw);
  background: rgba(30, 27, 75, 0.92); border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 20px; padding: 22px 20px;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.6);
  animation: pop .2s ease;
}
.modal-card h2 { margin: 0 0 16px; font-size: 18px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; margin-bottom: 6px; opacity: 0.85; }
.field input { padding: 11px 12px; font-size: 14px; }

.emoji-row { position: relative; }
.emoji-picker {
  margin-top: 8px; display: flex; flex-wrap: wrap; gap: 4px;
  background: rgba(255, 255, 255, 0.08); padding: 8px; border-radius: 10px;
  max-height: 130px; overflow-y: auto;
}
.emoji-picker span {
  width: 32px; height: 32px; display: flex; align-items: center; justify-content: center;
  font-size: 20px; cursor: pointer; border-radius: 8px;
}
.emoji-picker span:hover { background: rgba(255, 255, 255, 0.18); }

.color-row { display: flex; align-items: center; gap: 10px; }
.color-row input[type="color"] {
  width: 44px; height: 36px; border: none; background: transparent; cursor: pointer; padding: 0;
}
#fColorHex { font-family: monospace; font-size: 13px; opacity: 0.85; }

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

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 30px; transform: translateX(-50%);
  background: rgba(20, 20, 35, 0.92); color: #fff; padding: 10px 18px;
  border-radius: 12px; font-size: 14px; z-index: 100;
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  animation: pop .2s ease;
}
