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

body {
  background: #044269;
  background: radial-gradient(
    circle at 50% 60%,
    rgba(130, 165, 180, 1) 0%,
    rgba(90, 130, 160, 1) 40%,
    rgba(4, 70, 105, 1) 100%
  );
  margin: 0;
  padding: 0;
  height: 100vh;
  width: 100vw;
  position: relative;
  overflow: hidden;
  font-family: 'DM Sans', sans-serif;
  font-weight: 300;
}

body.active {
  filter: contrast(180%);
  font-weight: 400;
  background: #000;
  color: rgb(255, 255, 255);
}

.top-left-fixed {
  position: fixed;
  top: 2vh;
  left: 4vw;
  z-index: 1000;
  font-size: 5vw;
  color: #FFFFFF99;
  font-family: Verdana, Geneva, sans-serif;
}

.page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;

  /* Slightly safer than 100vh on iPhone Safari */
  min-height: 100vh;
  height: 100dvh;

  width: 100vw;
  padding: 1rem;
}

/* ── Button area ── */
.button-wrapper {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  width: fit-content;
  height: fit-content;
}

.liquid-wrapper {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  animation: wobble 8s ease-in-out infinite;
  z-index: 0;
}

.liquid_shape {
  position: absolute;
  z-index: 0;
  width: 58%;
  height: 58%;
  top: 21%;
  background: linear-gradient(135deg, #ffffff2f 0%, #ffffffff 100%);
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.3);
  animation: liquid 8s ease-in-out infinite, wobble 8s ease-in-out infinite;
  border-radius: 60% 40% 30% 70% / 60% 30% 70% 40%;
  transition: transform 0.5s ease-in-out;
}

.button-body {
  position: relative;
  z-index: 2;
  cursor: pointer;
}

.button-body.disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.button-body:active:not(.disabled) {
  transform: scale(0.97);
}

#btn {
  width: 100%;
  max-width: 300px;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
}

/* ── Liquid animations ── */
@keyframes liquid {
  0% {
    border-radius: 60% 40% 30% 70% / 60% 30% 70% 40%;
    background-size: 100% 100%;
  }
  50% {
    border-radius: 30% 60% 70% 40% / 50% 60% 30% 60%;
    background-size: 300% 150%;
  }
  100% {
    border-radius: 60% 40% 30% 70% / 60% 30% 70% 40%;
    background-size: 100% 100%;
  }
}

@keyframes wobble {
  0%   { transform: rotate(0deg) scale(1); }
  25%  { transform: rotate(1.5deg) scale(1.01); }
  50%  { transform: rotate(0deg) scale(1); }
  75%  { transform: rotate(-1.5deg) scale(1.01); }
  100% { transform: rotate(0deg) scale(1); }
}

@keyframes pulse {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.04); }
  100% { transform: scale(1); }
}

.pulsing {
  animation: liquid 6s ease-in-out infinite,
             wobble 6s ease-in-out infinite,
             pulse 2.5s ease-in-out infinite;
}

/* ── Waveform ── */
.audio-container {
  width: 100vw;
  margin-top: 1.5rem;
  background: transparent;
}

#waveform ::part(wrapper),
#waveform ::part(scroll) {
  background: transparent;
}

/* ── Spinner ── */
.spinner-wrap {
  height: 28px;
  margin-top: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.spinner {
  display: none;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-top-color: rgba(255, 255, 255, 0.85);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

.spinner.visible {
  display: block;
}

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

/* ── Status text ── */
.status {
  margin-top: .5rem;
  font-size: .78rem;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.45);
  transition: color .3s;
  text-align: center;
}

.status.active  { color: rgba(255, 255, 255, 0.95); }
.status.error   { color: #f08080; }
.status.working { color: rgba(255, 255, 255, 0.75); }
.status.warming { color: rgba(255, 255, 255, 0.45); }

.dot-pulse::after {
  content: '';
  display: inline-block;
  animation: dots 1.5s steps(4, end) infinite;
}

@keyframes dots {
  0%   { content: ''; }
  25%  { content: '.'; }
  50%  { content: '..'; }
  75%  { content: '...'; }
  100% { content: ''; }
}

/* ── NEW: Corrected result text ── */
.result-text {
  margin-top: 1rem;
  max-width: 82vw;
  min-height: 1.5rem;
  text-align: center;
  color: rgba(255, 255, 255, 0.95);
  font-size: 1rem;
  line-height: 1.45;
  font-family: 'DM Sans', sans-serif;
  font-weight: 400;
  word-wrap: break-word;
}

/* ── NEW: Manual speech button for iPhone/Safari ── */
.speak-btn {
  display: none;
  margin-top: 0.8rem;
  padding: 11px 20px;
  border: none;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  color: #044269;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.18);
  transition: transform 0.15s ease, background 0.2s ease;
}

.speak-btn:hover {
  background: #ffffff;
}

.speak-btn:active {
  transform: scale(0.97);
}

body.active .result-text {
  color: #ffffff;
}

body.active .speak-btn {
  background: #ffffff;
  color: #000000;
}

/* ── Footer ── */
.footer {
  position: fixed;
  bottom: 1.8rem;
  left: 50%;
  transform: translateX(-50%);
  font-size: .7rem;
  color: rgba(255, 255, 255, 0.3);
  letter-spacing: .04em;
  white-space: nowrap;
}

/* ── Settings icon ── */
.settings-icon-button {
  position: fixed;
  top: 20px;
  right: 20px;
  background: rgba(255, 255, 255, 0.15);
  color: white;
  border: none;
  border-radius: 8px;
  width: 46px;
  height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s;
  z-index: 100;
}

.settings-icon-button:hover {
  background: rgba(255, 255, 255, 0.28);
}

.settings-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 200;
}

.settings-overlay.open {
  display: block;
}

.settings-modal {
  display: none;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);

  width: 320px;
  min-height: 200px;
  max-height: 80vh;
  overflow-y: auto;

  background: #5d6a8e;
  border-radius: 12px;
  padding: 30px;
  flex-direction: column;
  gap: 10px;
  z-index: 300;
}

.settings-modal.open {
  display: flex;
}

.settings-modal-title {
  color: white;
  font-size: 20px;
  margin: 0 0 10px 0;
  font-family: 'DM Sans', sans-serif;
}

.settings-modal-close {
  position: absolute;
  top: 12px;
  right: 14px;
  background: none;
  border: none;
  color: #aaa;
  font-size: 18px;
  cursor: pointer;
}

.settings-modal-close:hover {
  color: white;
}

.settings-entry {
  display: flex;
  flex-direction: column;
}

.settings-item-detail {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease, padding 0.3s ease;
  background: #03334f;
  border-radius: 0 0 6px 6px;
  color: #ccc;
  font-size: 14px;
  font-family: 'DM Sans', sans-serif;
  line-height: 1.6;
  padding: 0 12px;
}

.settings-item-detail.open {
  max-height: 200px;
  padding: 12px;
}

.settings-item {
  width: 100%;
  padding: 20px 12px;
  background: #044269;
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 16px;
  font-family: 'DM Sans', sans-serif;
  cursor: pointer;
  transition: background 0.2s;
}

.settings-item:hover {
  background: #e74c3c;
}

.settings-entry:has(.settings-item-detail.open) .settings-item {
  border-radius: 6px 6px 0 0;
}

/* ── Media queries ── */
@media only screen and (max-width: 600px) {
  #btn {
    max-width: 220px;
  }

  .result-text {
    max-width: 88vw;
    font-size: 0.95rem;
  }

  .speak-btn {
    font-size: 0.88rem;
    padding: 10px 18px;
  }
}

@media only screen and (min-width: 600px) {
  .button-wrapper {
    margin-top: 0;
  }
}

@media only screen and (min-width: 768px) {
  .button-wrapper {
    margin-top: 0;
  }
}

@media only screen and (min-width: 992px) {
  .top-left-fixed {
    top: 2vh;
    left: 1vw;
    font-size: 3vw;
  }

  .button-wrapper {
    margin-top: 0;
  }
}

@media only screen and (min-width: 1200px) {
  .top-left-fixed {
    top: 2vh;
    left: 1vw;
    font-size: 3vw;
  }

  .button-wrapper {
    margin-top: 0;
  }
}
