* {
  box-sizing: border-box;
}

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

body {
  background: #eee6d6;
  color: #4b5246;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

.page {
  min-height: 100vh;
  min-height: 100dvh;
  padding: 0;
}

.sand-workspace {
  height: 100vh;
  height: 100dvh;
  border: 1px solid #b0a48b;
  background: #eee6d6;
  color: #4b5246;
}

.sand-stage {
  position: relative;
  height: 100%;
  overflow: hidden;
  background: #cbb18a;
}

.sand-canvas,
.sand-canvas canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.sand-top {
  position: absolute;
  top: 27px;
  left: 30px;
  right: 30px;
  display: flex;
  justify-content: space-between;
  gap: 20px;
  font-size: 10px;
  color: #e4ece0;
  letter-spacing: 0.1em;
  pointer-events: none;
}

.sand-top > span:first-child {
  display: flex;
  align-items: center;
  gap: 14px;
}

.sand-top i {
  width: 28px;
  height: 1px;
  background: rgba(216, 229, 213, 0.6);
}

.sand-note {
  position: absolute;
  top: 95px;
  left: 39px;
  pointer-events: none;
}

.sand-note small {
  font-size: 9px;
  color: #4c756d;
  letter-spacing: 0.13em;
}

.sand-note strong {
  display: block;
  margin-top: 16px;
  color: #3b625b;
  font-family: "Songti SC", SimSun, serif;
  font-size: clamp(27px, 3vw, 40px);
  font-weight: 400;
  line-height: 1.5;
  letter-spacing: 0.04em;
}

.sand-caption {
  position: absolute;
  bottom: 26px;
  left: 30px;
  right: 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  color: #625b49;
  font-size: 10px;
  line-height: 1.8;
  pointer-events: none;
}

.sand-caption i {
  width: 23px;
  height: 1px;
  flex-shrink: 0;
  background: #78705b;
}

.sand-progress {
  position: absolute;
  top: 96px;
  right: 33px;
  display: grid;
  gap: 10px;
  justify-items: end;
  color: #3b625b;
  pointer-events: none;
}

.sand-progress[hidden] {
  display: none;
}

.sand-progress > span {
  font-size: 10px;
}

.sand-progress b {
  font-size: 30px;
  font-weight: 400;
  font-variant-numeric: tabular-nums;
}

.sand-progress small {
  margin-left: 3px;
  font-size: 12px;
}

.sand-error {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  padding: 25px;
  background: rgba(238, 230, 214, 0.93);
  text-align: center;
  font-size: 14px;
}

.sand-error[hidden] {
  display: none;
}

/* 悬浮在海面上的「更改文字」按钮 */
.change-text-btn {
  position: absolute;
  top: 22px;
  left: 50%;
  z-index: 6;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-width: 148px;
  padding: 12px 24px;
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 999px;
  background: rgba(53, 95, 87, 0.82);
  color: #f7f4e8;
  font-size: 13px;
  letter-spacing: 0.08em;
  backdrop-filter: blur(6px);
  box-shadow: 0 10px 24px rgba(10, 58, 51, 0.22);
  transform: translateX(-50%);
  animation: button-sway 4.2s ease-in-out infinite;
  transition: background 0.18s ease, box-shadow 0.18s ease;
}

@keyframes button-sway {
  0%,
  100% {
    transform: translateX(-50%) translateY(0) rotate(-1deg);
  }
  50% {
    transform: translateX(-50%) translateY(-6px) rotate(1deg);
  }
}

.change-text-btn__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #c9e3d7;
}

.change-text-btn:hover {
  background: rgba(43, 81, 74, 0.92);
  box-shadow: 0 14px 30px rgba(10, 58, 51, 0.3);
}

@media (prefers-reduced-motion: reduce) {
  .change-text-btn {
    animation: none;
  }
}

/* 独立弹窗样式 —— 不复用原输入区样式 */
.text-modal[hidden] {
  display: none;
}

.text-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 24px;
}

.text-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(22, 34, 30, 0.56);
  backdrop-filter: blur(5px);
}

.text-modal__dialog {
  position: relative;
  width: min(560px, 100%);
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  padding: 34px 36px 30px;
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: 20px;
  background: #fffdf7;
  box-shadow: 0 28px 80px rgba(20, 38, 33, 0.28);
  animation: modal-enter 0.22s ease-out;
}

@keyframes modal-enter {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.text-modal__close {
  position: absolute;
  top: 18px;
  right: 20px;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  background: #f0ede2;
  color: #5c6a60;
  font-size: 22px;
  line-height: 1;
}

.text-modal__close:hover {
  background: #e4e9df;
}

.text-modal__header {
  padding-bottom: 22px;
  border-bottom: 1px solid #e7e2d4;
}

.text-modal__eyebrow {
  display: inline-block;
  margin-bottom: 10px;
  color: #6c9487;
  font-size: 10px;
  letter-spacing: 0.22em;
}

.text-modal__header h2 {
  margin: 0;
  color: #2f4c44;
  font-family: "Songti SC", SimSun, serif;
  font-size: 26px;
  font-weight: 500;
  letter-spacing: 0.03em;
}

.text-modal__header p {
  margin: 9px 0 0;
  color: #8a8d7c;
  font-size: 12px;
}

.text-modal__form {
  padding-top: 22px;
}

.modal-field {
  display: block;
}

.modal-field__label {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
  color: #42574e;
  font-size: 12px;
}

.modal-field__label small {
  color: #9a9583;
  font-size: 10px;
}

.modal-field textarea {
  display: block;
  width: 100%;
  min-height: 108px;
  padding: 14px 16px;
  resize: vertical;
  border: 1px solid #d5d8cb;
  border-radius: 12px;
  background: #f6f7f1;
  color: #35483f;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.7;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.modal-field textarea:focus {
  outline: 0;
  border-color: #5f8f81;
  box-shadow: 0 0 0 3px rgba(95, 143, 129, 0.16);
}

.modal-error {
  margin: 10px 0 0;
  color: #a25637;
  font-size: 11px;
}

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

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

.modal-btn {
  min-height: 40px;
  padding: 9px 18px;
  border-radius: 10px;
  border: 1px solid transparent;
  font-size: 12px;
  transition: background 0.18s ease, border-color 0.18s ease, transform 0.18s ease;
}

.modal-btn:hover:not(:disabled) {
  transform: translateY(-1px);
}

.modal-btn--ghost {
  border-color: #d7d5c8;
  background: transparent;
  color: #6f7567;
}

.modal-btn--ghost:hover {
  background: #f2f1e8;
}

.modal-btn--primary {
  border-color: #d9c9a8;
  background: #f1e6cd;
  color: #5b5540;
}

.modal-btn--primary:hover {
  background: #e9dbba;
}

.modal-btn--wave {
  display: inline-flex;
  align-items: center;
  gap: 16px;
  border-color: #355f57;
  background: #355f57;
  color: #f7f4e8;
}

.modal-btn--wave:hover:not(:disabled) {
  background: #2b514a;
}

.modal-btn--wave span {
  font-size: 16px;
}

button:not(:disabled) {
  cursor: pointer;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

button:focus-visible,
textarea:focus-visible {
  outline: 2px solid #456f66;
  outline-offset: 3px;
}

@media (max-width: 600px) {
  .change-text-btn {
    top: 64px;
    padding: 10px 20px;
    font-size: 12px;
  }

  .sand-top {
    top: 22px;
    left: 20px;
    right: 20px;
    font-size: 8px;
  }

  .sand-top i {
    display: none;
  }

  .sand-note {
    top: 75px;
    left: 24px;
  }

  .sand-note strong {
    margin-top: 12px;
    font-size: 29px;
  }

  .sand-note small {
    font-size: 8px;
  }

  .sand-caption {
    bottom: 23px;
    left: 22px;
    font-size: 9px;
  }

  .sand-progress {
    top: 77px;
    right: 23px;
  }

  .sand-progress b {
    font-size: 25px;
  }

  .text-modal {
    padding: 16px;
  }

  .text-modal__dialog {
    padding: 28px 22px 24px;
    border-radius: 16px;
  }

  .modal-field__label {
    flex-direction: column;
    gap: 5px;
  }

  .modal-actions {
    flex-wrap: wrap;
  }

  .modal-btn {
    flex: 1 1 auto;
  }
}
