html, body {
  margin: 0; height: 100%; background: #000; color: #fff;
  font-family: system-ui, sans-serif; overflow: hidden; touch-action: none;
  -webkit-user-select: none; user-select: none;
}
#wrap, canvas, #settings, #about, #saves { position: absolute; inset: 0; }
canvas { width: 100%; height: 100%; }
#canvas { background: #000; }
#water { pointer-events: none; opacity: .85; }

#gear, #shapeBtn {
  position: absolute; right: 8px; top: 8px; width: 44px; height: 44px; padding: 0;
  font-size: 32px; line-height: 1; cursor: pointer; background: none; border: 0; color: #fff;
}
#shapeBtn { top: 56px; font-size: 28px; }

/* shared look for the full-screen panels */
#settings, #about, #saves {
  background:
    radial-gradient(600px 300px at 85% -60px, rgba(120, 140, 255, .16), transparent 70%),
    radial-gradient(500px 260px at -10% 110%, rgba(255, 120, 190, .09), transparent 70%),
    #16161d;
}
#settings h1, #saves h1 {
  letter-spacing: .3px; background: linear-gradient(90deg, #fff, #aab6ff 60%, #ff9fd0);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}

/* settings overlay */
#settings {
  display: none; flex-wrap: wrap; justify-content: center;
  align-content: flex-start; text-align: center; padding-top: 30px; box-sizing: border-box;
}
#settings h1 { font-size: 32px; margin: 0 0 8px; flex: 0 0 100%; }
#sliders { display: contents; }
.group { flex: 0 0 100%; }
#settings label { display: block; font-size: 18px; margin-top: 16px; color: #b8b8cc; }
#settings input[type=range] { width: 280px; margin-top: 8px; accent-color: #a9b7ff; }
.link { display: inline-block; margin-top: 12px; font-size: 22px; font-weight: bold; cursor: pointer; color: #ccf; background: none; border: 0; }
#settings .group .link {
  margin-top: 16px; padding: 10px 26px; font-size: 18px; border-radius: 999px; color: #d6dbff;
  background: rgba(255, 255, 255, .07); border: 1px solid rgba(255, 255, 255, .1); transition: background .15s, transform .12s;
}
#settings .group .link:hover { background: rgba(142, 162, 255, .22); }
#settings .group .link:active { transform: scale(.96); }
#back {
  position: absolute; left: 0; right: 0; bottom: 30px; width: max-content; margin: auto;
  padding: 10px 34px; font-size: 22px; border-radius: 999px; color: #11131f;
  background: linear-gradient(135deg, #a9b7ff, #ff9fd0);
}

/* landscape: two columns */
body.land #settings { padding-top: 8px; }
body.land #settings h1 { font-size: 24px; margin: 0; }
body.land .group { flex: 0 0 50%; }
body.land #settings label { font-size: 16px; margin-top: 8px; }
body.land #settings input[type=range] { width: 200px; margin-top: 4px; }
body.land #settings .group .link { margin-top: 8px; padding: 6px 22px; }
body.land #back { bottom: 8px; padding: 6px 28px; }

/* footer + about panel */
#footer {
  position: absolute; left: 0; right: 0; bottom: env(safe-area-inset-bottom, 0px); padding: 0 8px; text-align: center;
  font-size: 10px; line-height: 1; color: #777; pointer-events: none;
}
#footer button {
  pointer-events: auto; background: none; border: 0; padding: 0; font: inherit;
  color: #99c; text-decoration: underline; cursor: pointer;
}
#about, #saves {
  display: none; overflow-y: auto; box-sizing: border-box;
  padding: 16px 20px 48px; touch-action: pan-y; -webkit-user-select: text; user-select: text;
}
#about .inner, #saves .inner { max-width: 640px; margin: 0 auto; text-align: left; line-height: 1.5; font-size: 15px; color: #ddd; }
#about h1, #saves h1 { font-size: 28px; margin: 8px 0; }
#about h2 { font-size: 18px; margin: 24px 0 6px; color: #fff; }
#about p, #about ul { margin: 6px 0; }
#about a { color: #ccf; }
#about pre { white-space: pre-wrap; font: 12px/1.45 ui-monospace, monospace; background: #111; padding: 12px; border-radius: 6px; margin: 8px 0; }
#aboutBack, #savesBack { display: block; margin: 0 0 8px; font-size: 22px; color: #fcc; }

/* ============================================================
   saves panel
   ============================================================ */
#saves h1 { font-size: 30px; margin: 4px 0 6px; }
#saves p { margin: 4px 0 14px; color: #9a9ab0; }

/* new-save row */
#saveRow {
  display: flex; gap: 8px; align-items: center; margin: 12px 0 4px; padding: 8px;
  background: rgba(255, 255, 255, .04); border: 1px solid rgba(255, 255, 255, .08); border-radius: 14px;
}
#saveName {
  flex: 1; min-width: 0; font: inherit; font-size: 16px; color: #fff; background: rgba(0, 0, 0, .35);
  border: 1px solid rgba(255, 255, 255, .1); border-radius: 10px; padding: 9px 12px; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
#saveName:focus { border-color: #8ea2ff; box-shadow: 0 0 0 3px rgba(142, 162, 255, .2); }
#saveNew {
  margin: 0; font-size: 16px; white-space: nowrap; color: #11131f;
  background: linear-gradient(135deg, #a9b7ff, #ff9fd0); border-radius: 10px; padding: 9px 16px;
  transition: transform .12s, filter .12s;
}
#saveNew:hover { filter: brightness(1.08); }
#saveNew:active { transform: scale(.96); }
#saveMsg { min-height: 1.4em; margin: 8px 2px; font-size: 14px; color: #8fe0a8; }
#saveMsg.err { color: #ff9a9a; }
#saveEmpty { color: #777790; font-size: 14px; text-align: center; padding: 28px 0; }
.saveHint { font-size: 12px; color: #6f6f88; margin: 0 2px 8px; }

/* a save slot (a card you can drag) */
#saveList { position: relative; }
.saveItem {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin: 0 0 8px; padding: 10px 12px 10px 6px; position: relative;
  background: linear-gradient(180deg, rgba(255, 255, 255, .06), rgba(255, 255, 255, .03));
  border: 1px solid rgba(255, 255, 255, .08); border-radius: 14px;
  transition: border-color .15s, background .15s;
}
.saveItem:hover { border-color: rgba(142, 162, 255, .45); }
@media (hover: hover) and (pointer: fine) { .saveItem { cursor: grab; } }
.saveItem.dragging {
  z-index: 5; cursor: grabbing; border-color: #8ea2ff; background: rgba(40, 44, 70, .95);
  box-shadow: 0 14px 34px rgba(0, 0, 0, .55), 0 0 0 1px rgba(142, 162, 255, .4);
  scale: 1.02; transition: box-shadow .15s, scale .15s;
}
body.reordering, body.reordering * { cursor: grabbing !important; -webkit-user-select: none !important; user-select: none !important; }

.saveItem .grip {
  flex: 0 0 26px; align-self: stretch; display: flex; align-items: center; justify-content: center;
  color: #5d5d78; font-size: 18px; letter-spacing: -3px; touch-action: none; cursor: grab;
  border-radius: 8px; transition: color .15s;
}
.saveItem:hover .grip, .saveItem.dragging .grip { color: #a9b7ff; }

.saveItem .info { flex: 1 1 140px; min-width: 0; }
.saveItem .name {
  font-size: 17px; font-weight: 600; color: #fff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  cursor: text; border-radius: 6px; padding: 1px 4px; margin-left: -4px; width: fit-content; max-width: 100%;
  transition: background .15s;
}
.saveItem .name:hover { background: rgba(255, 255, 255, .08); }
.saveItem .name:has(.renameInput) { background: none; width: auto; padding: 0; margin-left: 0; }
.saveItem .meta { font-size: 12px; color: #8a8aa3; margin-top: 2px; }
.saveItem .renameInput {
  width: 100%; box-sizing: border-box; font: inherit; font-weight: 600; color: #fff;
  background: rgba(0, 0, 0, .4); border: 1px solid #8ea2ff; border-radius: 8px; padding: 4px 8px; outline: none;
  box-shadow: 0 0 0 3px rgba(142, 162, 255, .2);
}

.saveItem .actions { display: flex; gap: 6px; flex: 0 0 auto; }
.saveItem .actions .link {
  margin: 0; font-size: 14px; font-weight: 600; padding: 7px 12px; border-radius: 999px;
  background: rgba(255, 255, 255, .07); color: #d6dbff; border: 1px solid rgba(255, 255, 255, .08);
  transition: background .15s, transform .12s, border-color .15s;
}
.saveItem .actions .link:hover { background: rgba(142, 162, 255, .22); border-color: rgba(142, 162, 255, .5); }
.saveItem .actions .link:active { transform: scale(.95); }
.saveItem .actions .load { background: linear-gradient(135deg, #8ea2ff, #b48cff); color: #10121e; border-color: transparent; }
.saveItem .actions .load:hover { filter: brightness(1.1); background: linear-gradient(135deg, #8ea2ff, #b48cff); }
.saveItem .actions .del { color: #ffb3b3; }
.saveItem .actions .del:hover { background: rgba(255, 110, 110, .2); border-color: rgba(255, 110, 110, .5); }
@media (max-width: 480px) {
  .saveItem .actions { flex: 1 1 100%; padding-left: 36px; box-sizing: border-box; }
}

/* "Are you sure?" popup */
#confirmBack {
  position: fixed; inset: 0; z-index: 99999; display: none; align-items: center; justify-content: center;
  background: rgba(5, 5, 12, .65); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); padding: 16px;
  touch-action: none; -webkit-user-select: none; user-select: none;
}
#confirmBack[style*="flex"] #confirmBox { animation: confirmPop .18s ease-out; }
@keyframes confirmPop { from { opacity: 0; transform: translateY(10px) scale(.96); } to { opacity: 1; transform: none; } }
#confirmBox {
  background: linear-gradient(180deg, #25253a, #1b1b2a); color: #eee; width: 100%; max-width: 340px; box-sizing: border-box;
  border: 1px solid rgba(255, 255, 255, .12); border-radius: 16px; padding: 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .6);
}
#confirmBox h2 { margin: 0 0 8px; font-size: 20px; color: #fff; }
#confirmBox p { margin: 0 0 18px; line-height: 1.4; color: #b8b8cc; word-break: break-word; }
#confirmBox .row { display: flex; gap: 10px; justify-content: flex-end; }
#confirmBox .link { margin: 0; font-size: 16px; padding: 9px 16px; border-radius: 999px; background: rgba(255, 255, 255, .08); color: #d6dbff; }
#confirmBox .link:disabled { opacity: .45; cursor: not-allowed; }
#confirmBox #confirmYes { background: linear-gradient(135deg, #ff8a8a, #ff6fa8); color: #1a0d12; }
#confirmBox #confirmYes:disabled { background: rgba(255, 255, 255, .08); color: #ff9a9a; }