:root {
  --highlight: #3AA0FF;
  --highlight-dark: #1B4B81;
  --highlight-light: #A5D8FF;
  --foam: #F5FBFF;
  --surface: rgba(255, 255, 255, 0.88);
  --background: linear-gradient(180deg, #E8F3FF 0%, #F5FBFF 100%);
  --text: #0D2C4F;
  --muted: #4A6075;
  --shadow: rgba(11, 53, 94, 0.18);
}

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

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: 'Inter', sans-serif;
  font-family: 'Quicksand', 'Inter', sans-serif;
  background: var(--background);
  color: var(--text);
  line-height: 1.6;
}

a {
  color: inherit;
}

a:hover,
a:focus {
  text-decoration: none;
}

.app-header {
  position: relative;
  background: #1B4B81;
  color: #fff;
  padding: 1.75rem 1.25rem 1.5rem;
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
  align-items: flex-start;
  z-index: 1;
}

.branding {
  flex: 1 1 260px;
  position: relative;
  z-index: 1;
}

.home-link {
  display: inline-block;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.85);
}

.home-link:hover,
.home-link:focus {
  color: #fff;
}

.branding h1 {
  margin: 0.25rem 0 0;
  font-size: 1.9rem;
  font-weight: 700;
}

.tagline {
  margin: 0.45rem 0 0;
  font-size: 0.98rem;
  color: rgba(255, 255, 255, 0.9);
  max-width: 36ch;
}
.puzzle-meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  width: min(580px, 100%);
  margin: 0 auto 1.8rem;
  position: relative;
  z-index: 1;
}
.meta-card {
  background: rgba(245, 251, 255, 0.78);
  border-radius: 18px;
  padding: 1rem 1.2rem;
  border: 1px solid rgba(165, 216, 255, 0.42);
  box-shadow: 0 16px 32px rgba(18, 65, 110, 0.18);
  backdrop-filter: blur(6px);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-height: 96px;
  transition: transform 0.35s ease, box-shadow 0.35s ease;
}
.meta-card--accent {
  background: linear-gradient(140deg, rgba(58, 160, 255, 0.28), rgba(27, 75, 129, 0.3));
  border-color: rgba(27, 75, 129, 0.35);
  color: #fff;
}
.meta-card--accent .meta-label {
  color: rgba(245, 251, 255, 0.8);
}
.meta-card--accent .meta-value {
  color: rgba(255, 255, 255, 0.95);
}
.meta-label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: rgba(13, 44, 79, 0.68);
  font-weight: 600;
}
.meta-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--highlight-dark);
  font-family: 'Quicksand', 'Inter', sans-serif;
}
.meta-card:hover,
.meta-card:focus-within {
  transform: translateY(-3px);
  box-shadow: 0 22px 42px rgba(18, 65, 110, 0.22);
}
.share-hint {
  margin: 0.75rem 0 0;
  font-size: 0.95rem;
  color: rgba(13, 44, 79, 0.68);
  text-align: center;
}
.puzzle-stage {
  position: relative;
  margin: 0 auto;
  width: 92vw;
  max-width: 600px;
  display: flex;
  justify-content: center;
}
.puzzle-frame {
  position: relative;
  background: linear-gradient(160deg, rgba(245, 251, 255, 0.92) 0%, rgba(214, 233, 255, 0.86) 65%);
  backdrop-filter: blur(10px);
  border-radius: 20px;
  padding: 1.8rem;
  box-shadow: 0 32px 64px rgba(18, 65, 110, 0.22);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 92vw;
  max-width: 540px;
  height: 92vw;
  max-height: 540px;
  z-index: 1;
}
@supports (width: min(100%, 1px)) {
  .puzzle-stage {
    width: min(92vw, 600px);
  }
  .puzzle-frame {
    width: min(92vw, 540px);
    height: auto;
    min-height: min(92vw, 540px);
  }
}
.puzzle-ornaments {
  position: absolute;
  inset: -70px -40px -70px -40px;
  pointer-events: none;
  z-index: 0;
}
.ornament {
  position: absolute;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  border-radius: 18px;
  font-size: 2rem;
  background: rgba(245, 251, 255, 0.85);
  box-shadow: 0 12px 28px rgba(18, 65, 110, 0.18);
  animation: ornamentFloat 18s ease-in-out infinite;
  filter: drop-shadow(0 10px 22px rgba(18, 65, 110, 0.26));
}
.ornament--loaf {
  top: 6%;
  left: -12%;
  transform: rotate(-4deg);
  animation-delay: 1s;
}
.ornament--sparkle {
  top: -9%;
  right: 2%;
  width: 52px;
  height: 52px;
  font-size: 1.6rem;
  animation-duration: 16s;
  animation-delay: 4s;
}
.ornament--dove {
  bottom: -6%;
  left: 6%;
  animation-duration: 20s;
  animation-delay: 6.5s;
}
.ornament--heart {
  bottom: -12%;
  right: -10%;
  width: 70px;
  height: 70px;
  font-size: 2.1rem;
  transform: rotate(8deg);
  animation-duration: 19s;
  animation-delay: 9s;
}
.tip-deck {
  margin: 2.6rem auto 0;
  width: min(900px, 100%);
  display: grid;
  gap: 1.4rem;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}
.tip-card {
  background: rgba(245, 251, 255, 0.8);
  border-radius: 20px;
  padding: 1.8rem;
  box-shadow: 0 24px 48px rgba(18, 65, 110, 0.18);
  border: 1px solid rgba(165, 216, 255, 0.32);
  backdrop-filter: blur(6px);
  transition: transform 0.35s ease, box-shadow 0.35s ease;
}
.tip-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 54px;
  height: 54px;
  border-radius: 16px;
  background: rgba(58, 160, 255, 0.12);
  font-size: 1.45rem;
  margin-bottom: 1rem;
}
.tip-title {
  margin: 0 0 0.5rem;
  font-size: 1.35rem;
  color: var(--highlight-dark);
  font-weight: 700;
  font-family: 'Quicksand', 'Inter', sans-serif;
}
.tip-copy {
  margin: 0;
  color: rgba(13, 44, 79, 0.72);
  line-height: 1.65;
  font-size: 1rem;
  font-family: 'Inter', sans-serif;
}
.tip-card:hover,
.tip-card:focus-within {
  transform: translateY(-4px);
  box-shadow: 0 26px 54px rgba(18, 65, 110, 0.24);
}
.hud {
  align-self: center;
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.75rem 1.25rem;
  border-radius: 999px;
  background: rgba(58, 160, 255, 0.12);
  border: 1px solid rgba(58, 160, 255, 0.35);
  font-weight: 600;
  font-size: 1rem;
  color: #0D2C4F;
}

.control-panel {
  margin: 1.5rem auto 2rem;
  padding: 1rem 1.2rem;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(165, 216, 255, 0.4);
  box-shadow: 0 18px 36px rgba(18, 65, 110, 0.14);
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
  justify-content: space-between;
  max-width: 520px;
}

.difficulty-control {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.35rem;
  padding: 0.6rem 1rem;
  border-radius: 14px;
  background: rgba(58, 160, 255, 0.08);
  border: 1px solid rgba(58, 160, 255, 0.2);
}

.difficulty-control label {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.72rem;
  font-weight: 600;
  color: rgba(13, 44, 79, 0.7);
}

.difficulty-control select {
  appearance: none;
  border: 1px solid rgba(58, 160, 255, 0.5);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.95);
  color: #0D2C4F;
  font-size: 0.95rem;
  font-weight: 600;
  padding: 0.35rem 2.1rem 0.35rem 0.85rem;
  line-height: 1.4;
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.difficulty-control select:focus {
  outline: none;
  border-color: rgba(58, 160, 255, 0.9);
  background: rgba(255, 255, 255, 1);
}

.difficulty-control select option {
  color: #0D2C4F;
}

.hud-label {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.75rem;
  color: rgba(13, 44, 79, 0.65);
}

.hud-value {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--highlight-dark);
}

.status {
  min-width: 9rem;
  text-align: right;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--highlight-dark);
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  transform: translateY(4px);
}

.status.is-solved {
  opacity: 1;
  transform: translateY(0);
}

.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 1.5rem;
  position: relative;
  overflow: hidden;
  z-index: 1;
}

.app-main::before {
  content: '';
  position: absolute;
  top: -110px;
  left: -15%;
  width: 130%;
  height: 260px;
  background: radial-gradient(130% 100% at 50% 0%, rgba(58, 160, 255, 0.16), rgba(58, 160, 255, 0));
  pointer-events: none;
  animation: waveGlide 26s ease-in-out infinite;
}

.app-main::after {
  content: '';
  position: absolute;
  bottom: -120px;
  left: -20%;
  width: 140%;
  height: 240px;
  background: radial-gradient(120% 120% at 50% 100%, rgba(181, 223, 255, 0.32), rgba(181, 223, 255, 0));
  pointer-events: none;
  animation: waveRise 32s ease-in-out infinite;
}

.puzzle-frame::before {
  content: '';
  position: absolute;
  inset: 10px;
  border-radius: 16px;
  border: 1px solid rgba(58, 160, 255, 0.22);
  pointer-events: none;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.4);
}

#habit-cta {
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--highlight-dark);
  margin: 0 0 1.75rem;
  text-align: center;
  line-height: 1.5;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

#habit-cta.is-visible {
  opacity: 1;
  transform: translateY(0);
}

#puzzle {
  position: relative;
  user-select: none;
  width: 100%;
  height: 100%;
}

.tile {
  position: absolute;
  background-repeat: no-repeat;
  cursor: pointer;
  transition: left 0.2s ease, top 0.2s ease, border-radius 0.2s ease, box-shadow 0.2s ease;
  border-radius: 16px;
  border: 1px solid rgba(58, 160, 255, 0.14);
  box-shadow: 0 6px 18px rgba(13, 59, 101, 0.18);
}

.tile.misplaced {
  border-radius: 20px;
  box-shadow: 0 12px 26px rgba(13, 59, 101, 0.24);
}

.tile::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.6);
  font-size: clamp(1.4rem, 4vw, 2.4rem);
  font-weight: 700;
  color: #26B7C8;
  text-shadow: 0 0 12px rgba(255, 255, 255, 0.85);
  opacity: 0;
  pointer-events: none;
}

.tile.flash-check::after {
  content: '✓';
  animation: tile-checkmark 0.85s ease forwards;
}

.puzzle-solved .tile {
  border-color: transparent;
  box-shadow: none;
}

.tile.selected {
  outline: 3px solid var(--highlight-light);
  z-index: 2;
}

.tile.locked {
  cursor: default;
  z-index: 1;
  border-radius: 0;
  box-shadow: none;
}

.tile.jiggle {
  animation: tile-jiggle 0.36s ease;
}

.app-footer {
  padding: 2.6rem 1rem 2.2rem;
  font-size: 0.9rem;
  color: rgba(13, 44, 79, 0.7);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.85rem;
  border-top: 1px solid rgba(13, 44, 79, 0.12);
}

.footer-copy {
  margin: 0;
}

.app-footer a {
  color: var(--highlight-dark);
}

.app-footer a:hover,
.app-footer a:focus-visible {
  color: var(--highlight);
}

.share-actions {
  margin-top: 1.6rem;
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 0 1rem;
}

.share-actions.is-visible {
  display: flex;
}

.share-actions button {
  min-width: min(320px, 100%);
  padding: 0.9rem 2.4rem;
  font-size: 1.05rem;
}

button {
  background: linear-gradient(140deg, #3AA0FF 0%, #2F8BEA 100%);
  color: #fff;
  border: none;
  padding: 0.5rem 1.1rem;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 600;
  transition: transform 0.15s ease, background-color 0.15s ease, box-shadow 0.15s ease;
}

button:hover,
button:focus-visible {
  background: linear-gradient(140deg, #2F8BEA 0%, #1B6FCD 100%);
  color: #fff;
  transform: translateY(-1px);
  box-shadow: 0 10px 24px rgba(13, 59, 101, 0.26);
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}


@keyframes tile-jiggle {
  0%, 100% { transform: translate3d(0, 0, 0); }
  20% { transform: translate3d(-3px, 0, 0); }
  40% { transform: translate3d(3px, 0, 0); }
  60% { transform: translate3d(-3px, 0, 0); }
  80% { transform: translate3d(3px, 0, 0); }
}

@keyframes tile-checkmark {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.4);
  }
  45% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
  80% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(1.15);
  }
}

@keyframes ornamentFloat {
  0% {
    transform: translate3d(0, 0, 0) scale(0.98) rotate(0deg);
    opacity: 0.75;
  }
  25% {
    transform: translate3d(4%, -6%, 0) scale(1.02) rotate(4deg);
  }
  50% {
    transform: translate3d(-3%, -10%, 0) scale(1) rotate(-3deg);
    opacity: 0.8;
  }
  75% {
    transform: translate3d(2%, -14%, 0) scale(1.03) rotate(2deg);
  }
  100% {
    transform: translate3d(0, -20%, 0) scale(0.99) rotate(0deg);
    opacity: 0;
  }
}

@keyframes taglineWave {
  0% {
    transform: translateX(-10%) scaleX(1);
    opacity: 1;
  }
  50% {
    transform: translateX(10%) scaleX(1.1);
    opacity: 0.85;
  }
  100% {
    transform: translateX(-10%) scaleX(1);
    opacity: 1;
  }
}

@keyframes waveGlide {
  0% {
    transform: translate3d(0, 0, 0) scale(1);
  }
  30% {
    transform: translate3d(-2%, 4%, 0) scale(1.08);
  }
  55% {
    transform: translate3d(1.5%, -3%, 0) scale(1.05);
  }
  85% {
    transform: translate3d(-1%, 2%, 0) scale(1.1);
  }
  100% {
    transform: translate3d(0, 0, 0) scale(1);
  }
}

@keyframes waveRise {
  0% {
    transform: translate3d(0, 0, 0) scale(1.05);
  }
  40% {
    transform: translate3d(2%, -3%, 0) scale(1.12);
  }
  70% {
    transform: translate3d(-1%, 3%, 0) scale(1.08);
  }
  100% {
    transform: translate3d(0, 0, 0) scale(1.05);
  }
}

@media (prefers-reduced-motion: reduce) {
  .ornament,
  .app-main::before,
  .app-main::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}

@media (max-width: 700px) {
  .app-header {
    padding: 1.5rem 1.1rem 1.4rem;
    gap: 1.1rem;
  }
  .branding h1 {
    font-size: 1.7rem;
  }
  .tagline {
    font-size: 0.9rem;
  }
  .hud {
    width: 100%;
    justify-content: space-between;
    border-radius: 14px;
    padding: 0.85rem 1.5rem;
    background: rgba(58, 160, 255, 0.18);
    border-color: rgba(58, 160, 255, 0.3);
  }
  .control-panel {
    width: 100%;
    justify-content: center;
    gap: 0.75rem;
  }
  .hud-value {
    font-size: 1.25rem;
  }
  .status {
    text-align: left;
    min-width: auto;
  }
  .app-main {
    padding: 2.2rem 1rem 2.6rem;
  }
  .puzzle-frame {
    width: 100%;
    max-width: 440px;
    height: calc(100vw - 2.5rem);
    max-height: 440px;
    padding: 1.2rem;
  }
  .puzzle-stage {
    width: 100%;
  }
  .puzzle-ornaments {
    display: none;
  }
  .puzzle-meta {
    gap: 0.75rem;
    margin-bottom: 1.4rem;
  }
  .meta-card {
    padding: 0.85rem 1rem;
    min-height: 88px;
  }
  .tip-deck {
    margin-top: 2rem;
    gap: 1rem;
  }
  .tip-card {
    padding: 1.4rem;
  }
  .app-footer {
    gap: 0.7rem;
  }
  #habit-cta {
    font-size: 1.05rem;
    margin: 0 0 1.4rem;
  }
}
@supports (width: min(100%, 1px)) {
  @media (max-width: 700px) {
    .puzzle-frame {
      width: min(100%, 440px);
      min-height: min(100vw - 2.5rem, 440px);
      height: auto;
    }
  }
}

@media (max-width: 480px) {
  .app-header {
    padding: 1.35rem 1rem 1.2rem;
  }
  .home-link {
    font-size: 0.72rem;
  }
  .branding h1 {
    font-size: 1.55rem;
  }
  .tagline {
    font-size: 0.85rem;
  }
  .hud {
    padding: 0.6rem 0.9rem;
    gap: 0.5rem;
  }
  .hud-label {
    font-size: 0.7rem;
  }
  .hud-value {
    font-size: 1.15rem;
  }
  .app-main {
    padding: 2rem 0.85rem 2.4rem;
  }
  .puzzle-frame {
    width: 100%;
    max-width: 400px;
    height: calc(100vw - 2rem);
    max-height: 400px;
    padding: 1rem;
    border-radius: 16px;
  }
  .puzzle-meta {
    grid-template-columns: 1fr;
  }
  .tip-card {
    padding: 1.25rem;
  }
  #habit-cta {
    font-size: 1rem;
    margin: 0 0 1.2rem;
  }
  .app-footer {
    padding: 1.2rem 0.8rem 1.4rem;
  }
}
@supports (width: min(100%, 1px)) {
  @media (max-width: 480px) {
    .puzzle-frame {
      width: min(100%, 400px);
      min-height: min(100vw - 2rem, 400px);
      height: auto;
    }
  }
}

@media (prefers-color-scheme: dark) {
  body {
    background: #121212;
    color: #f1f1f1;
  }
  .ornament {
    background: rgba(20, 38, 58, 0.82);
    box-shadow: 0 14px 30px rgba(0, 0, 0, 0.55);
    filter: drop-shadow(0 12px 26px rgba(0, 0, 0, 0.6));
  }
  .app-header {
    background: var(--highlight-dark);
  }
  .home-link {
    color: rgba(255, 255, 255, 0.75);
  }
  .control-panel {
    background: rgba(9, 32, 52, 0.88);
    border-color: rgba(145, 201, 255, 0.25);
    box-shadow: 0 24px 48px rgba(0, 0, 0, 0.45);
  }
  .difficulty-control {
    background: rgba(58, 160, 255, 0.12);
    border-color: rgba(145, 201, 255, 0.35);
  }
  .difficulty-control label {
    color: rgba(214, 233, 255, 0.75);
  }
  .difficulty-control select {
    background: rgba(9, 24, 38, 0.85);
    color: #f6fbff;
    border-color: rgba(145, 201, 255, 0.45);
  }
  .hud {
    background: rgba(0, 0, 0, 0.35);
    border-color: rgba(145, 201, 255, 0.25);
    color: #f6fbff;
  }
  .hud-label {
    color: rgba(214, 233, 255, 0.7);
  }
  .hud-value {
    color: var(--highlight-light);
  }
  .status {
    color: var(--highlight-light);
  }
  .tagline {
    color: rgba(255, 255, 255, 0.82);
  }
  .app-main {
    background: #101010;
  }
  .puzzle-frame {
    background: linear-gradient(160deg, rgba(26, 40, 61, 0.95) 0%, rgba(12, 24, 40, 0.9) 65%);
    box-shadow: 0 30px 64px rgba(0, 0, 0, 0.6);
  }
  .puzzle-frame::before {
    border-color: rgba(85, 150, 220, 0.35);
    box-shadow: inset 0 0 0 1px rgba(12, 24, 40, 0.7);
  }
  .tile {
    border: 1px solid rgba(255, 255, 255, 0.07);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
  }
  .tile.selected {
    outline: 3px solid var(--highlight-light);
  }
  .puzzle-meta {
    background: none;
  }
  .meta-card {
    background: rgba(9, 32, 52, 0.78);
    border-color: rgba(145, 201, 255, 0.38);
    box-shadow: 0 22px 44px rgba(3, 13, 23, 0.6);
  }
  .meta-card--accent {
    background: linear-gradient(140deg, rgba(58, 160, 255, 0.32), rgba(10, 32, 56, 0.6));
    border-color: rgba(58, 160, 255, 0.4);
  }
  .meta-label {
    color: rgba(198, 214, 230, 0.72);
  }
  .meta-value {
    color: #A5D8FF;
  }
  .meta-card--accent .meta-label {
    color: rgba(214, 233, 255, 0.8);
  }
  .meta-card--accent .meta-value {
    color: rgba(245, 251, 255, 0.95);
  }
  .share-hint {
    color: rgba(198, 214, 230, 0.68);
  }
  .tip-card {
    background: rgba(9, 32, 52, 0.78);
    border-color: rgba(145, 201, 255, 0.32);
    box-shadow: 0 26px 54px rgba(2, 12, 22, 0.62);
  }
  .tip-title {
    color: #A5D8FF;
  }
  .tip-copy {
    color: rgba(198, 214, 230, 0.78);
  }
  .tip-icon {
    background: rgba(58, 160, 255, 0.2);
  }
  .app-footer {
    background: transparent;
    color: rgba(214, 233, 255, 0.75);
    border-top: 1px solid rgba(145, 201, 255, 0.25);
  }
  button {
    background: var(--highlight-dark);
    color: #111;
  }
  button:hover,
  button:focus-visible {
    background: var(--highlight-light);
    color: #111;
  }
  #habit-cta {
    color: var(--highlight-light);
  }
}
