:root {
  color-scheme: light;
  --background: #f4f7fb;
  --surface: rgba(255, 255, 255, 0.74);
  --surface-strong: rgba(255, 255, 255, 0.94);
  --surface-accent: linear-gradient(160deg, rgba(255, 255, 255, 0.98), rgba(220, 230, 244, 0.92));
  --border: rgba(19, 35, 58, 0.12);
  --border-strong: rgba(19, 35, 58, 0.2);
  --text: #15263d;
  --text-muted: #5f6f85;
  --primary: #13233a;
  --primary-soft: #1f4e79;
  --highlight: #ffba49;
  --danger: #c94c4c;
  --shadow: 0 18px 48px rgba(18, 37, 59, 0.12);
  --radius-lg: 28px;
  --radius-md: 20px;
  --radius-sm: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
  background: var(--background);
}

body {
  min-height: 100svh;
  margin: 0;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top, rgba(141, 179, 226, 0.38), transparent 35%),
    linear-gradient(180deg, #dfe9f7 0%, var(--background) 24%, #edf2f9 100%);
  overflow-x: hidden;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  position: relative;
  min-height: 100svh;
  padding:
    calc(var(--safe-top) + 16px)
    calc(var(--safe-right) + 16px)
    calc(var(--safe-bottom) + 20px)
    calc(var(--safe-left) + 16px);
}

.top-bar {
  display: grid;
  grid-template-columns: minmax(72px, auto) 1fr minmax(52px, auto);
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}

.top-bar__button {
  min-height: 44px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.8);
  color: var(--primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 8px 24px rgba(18, 37, 59, 0.08);
}

.top-bar__button:focus-visible,
.app-tile:focus-visible,
.app-button:focus-visible,
.calculator-key:focus-visible,
.notes-editor__textarea:focus-visible,
.piano-controls__slider:focus-visible {
  outline: 3px solid rgba(31, 78, 121, 0.28);
  outline-offset: 2px;
}

.top-bar__button--icon {
  justify-self: end;
  min-width: 44px;
  padding-inline: 0;
}

.top-bar__title-group {
  min-width: 0;
  text-align: center;
}

.app-shell.is-immersive .top-bar {
  position: absolute;
  top: calc(var(--safe-top) + 6px);
  left: calc(var(--safe-left) + 10px);
  right: calc(var(--safe-right) + 10px);
  grid-template-columns: 44px 1fr 44px;
  margin: 0;
  z-index: 12;
  pointer-events: none;
}

.app-shell.is-immersive .top-bar__button {
  width: 44px;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border-radius: 50%;
  pointer-events: auto;
}

.app-shell.is-immersive .top-bar__button span:last-child,
.app-shell.is-immersive .top-bar__title-group,
.app-shell.is-immersive .top-bar__button--icon {
  display: none;
}

.top-bar__eyebrow,
.hero-card__eyebrow,
.section-label,
.app-card__label {
  margin: 0;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.top-bar__title {
  margin: 2px 0 0;
  font-size: clamp(1.4rem, 4vw, 1.85rem);
  line-height: 1.1;
}

.app-main {
  display: grid;
  gap: 16px;
}

.app-shell.is-immersive .app-main {
  gap: 0;
}

.status-region {
  min-height: 0;
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 180ms ease, transform 180ms ease, min-height 180ms ease;
  pointer-events: none;
}

.status-region.is-visible {
  min-height: 24px;
  opacity: 1;
  transform: translateY(0);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(19, 35, 58, 0.9);
  color: #f6f8fb;
  font-size: 0.9rem;
}

.view {
  opacity: 0;
  transform: translateY(18px) scale(0.985);
  pointer-events: none;
  transition: opacity 220ms ease, transform 220ms ease;
  display: none;
}

.view--active {
  display: grid;
  gap: 18px;
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.hero-card,
.mini-app-panel,
.app-card,
.calculator,
.notes-editor,
.piano {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface-accent);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.hero-card {
  padding: 22px;
}

.hero-card__title {
  margin: 8px 0 10px;
  font-size: clamp(1.7rem, 5vw, 2.4rem);
  line-height: 1.05;
}

.hero-card__text {
  margin: 0;
  max-width: 34rem;
  color: var(--text-muted);
  line-height: 1.55;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  gap: 16px;
}

.app-tile {
  min-height: 112px;
  padding: 14px 12px;
  border: 0;
  border-radius: 24px;
  background: transparent;
  display: grid;
  justify-items: center;
  align-content: start;
  gap: 10px;
  color: inherit;
  transition: transform 180ms ease, background-color 180ms ease;
  -webkit-tap-highlight-color: transparent;
}

.app-tile:active {
  transform: scale(0.97);
}

.app-tile__icon {
  width: 68px;
  height: 68px;
  border-radius: 22px;
  display: grid;
  place-items: center;
  font-size: 1.95rem;
  color: #fff;
  background:
    radial-gradient(circle at top, rgba(255, 255, 255, 0.3), transparent 48%),
    linear-gradient(155deg, var(--primary-soft), var(--primary));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.22),
    0 12px 26px rgba(18, 37, 59, 0.18);
}

.app-tile__label {
  font-size: 0.94rem;
  text-align: center;
  line-height: 1.3;
}

.mini-app-panel {
  padding: 18px;
  min-height: calc(100svh - 180px - var(--safe-top) - var(--safe-bottom));
}

.app-shell.is-immersive .mini-app-panel {
  padding: 0;
  min-height: calc(100svh - var(--safe-top) - var(--safe-bottom));
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

.app-card {
  padding: 18px;
}

.app-card__title {
  margin: 6px 0 8px;
  font-size: 1.45rem;
}

.app-card__text {
  margin: 0;
  color: var(--text-muted);
  line-height: 1.55;
}

.integrated-app-host {
  display: block;
  min-height: calc(100svh - var(--safe-top) - var(--safe-bottom));
}

.app-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.app-button,
.calculator-key {
  min-height: 44px;
  border: 0;
  border-radius: 16px;
  padding: 0 16px;
  background: var(--primary);
  color: #fff;
  box-shadow: 0 10px 20px rgba(19, 35, 58, 0.12);
}

.app-button--secondary,
.calculator-key--secondary {
  background: rgba(19, 35, 58, 0.08);
  color: var(--primary);
  box-shadow: none;
}

.app-button--danger {
  background: var(--danger);
}

.calculator {
  padding: 18px;
}

.calculator-display {
  min-height: 92px;
  padding: 16px;
  border-radius: 22px;
  background: rgba(16, 28, 44, 0.94);
  color: #f8fbff;
  display: grid;
  align-items: end;
  justify-items: end;
  margin-bottom: 18px;
}

.calculator-display__value {
  margin: 0;
  font-size: clamp(2rem, 9vw, 3.2rem);
  line-height: 1;
  word-break: break-all;
}

.calculator-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.calculator-key {
  padding: 0;
  font-size: 1.1rem;
}

.calculator-key--operator {
  background: linear-gradient(160deg, #ffb54d, #ff8f3f);
  color: #14253a;
}

.calculator-key--wide {
  grid-column: span 2;
}

.notes-editor {
  padding: 18px;
}

.notes-editor__meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  color: var(--text-muted);
  font-size: 0.92rem;
}

.notes-editor__textarea {
  width: 100%;
  min-height: 50svh;
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 16px;
  resize: vertical;
  background: rgba(255, 255, 255, 0.92);
  color: var(--text);
  line-height: 1.6;
}

.piano {
  padding: 18px;
}

.piano--studio {
  background:
    linear-gradient(180deg, rgba(35, 35, 42, 0.98), rgba(9, 9, 12, 0.98)),
    #101117;
  color: #f6f7fb;
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow:
    0 24px 60px rgba(10, 16, 26, 0.28),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.piano-studio__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.piano--studio .app-card__title,
.piano--studio .app-card__text,
.piano--studio .section-label {
  color: #edf1f9;
}

.piano--studio .app-card__text {
  max-width: 40rem;
  color: rgba(237, 241, 249, 0.72);
}

.piano-studio__controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 220px));
  gap: 12px;
  margin-bottom: 20px;
}

.piano-sample-status {
  margin: 0;
  align-self: end;
}

.piano-knob {
  padding: 12px 14px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  display: grid;
  gap: 10px;
}

.piano-knob__label,
.piano-knob__value {
  font-size: 0.88rem;
  font-weight: 700;
  color: rgba(237, 241, 249, 0.82);
}

.piano-knob__label {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.piano-controls__slider {
  width: 100%;
  accent-color: #9fb3d1;
}

.piano-stage {
  overflow-x: auto;
  padding-bottom: 6px;
}

.piano-stage::-webkit-scrollbar {
  height: 6px;
}

.piano-stage::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.18);
  border-radius: 999px;
}

.piano-keyboard {
  position: relative;
  min-width: 900px;
  padding: 22px 18px 18px;
  border-radius: 24px;
  background:
    linear-gradient(180deg, rgba(30, 30, 34, 0.96), rgba(7, 8, 11, 0.98)),
    #08090d;
  box-shadow:
    inset 0 3px 0 rgba(255, 255, 255, 0.05),
    inset 0 -16px 20px rgba(0, 0, 0, 0.36);
}

.piano-white-keys {
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: 2px;
  position: relative;
}

.piano-black-keys {
  position: absolute;
  top: 22px;
  left: 18px;
  right: 18px;
  height: 52%;
  pointer-events: none;
}

.piano-key {
  border: 0;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform 90ms ease, box-shadow 90ms ease, background 90ms ease;
  touch-action: none;
}

.piano-key--white {
  min-height: 360px;
  border-radius: 0 0 18px 18px;
  background:
    linear-gradient(180deg, #ffffff 0%, #fbfcff 32%, #e2e8f2 100%);
  color: #657997;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  gap: 12px;
  padding: 0 10px 18px;
  box-shadow:
    inset -6px 0 10px rgba(154, 171, 196, 0.22),
    inset 0 -8px 14px rgba(184, 194, 209, 0.28),
    0 6px 12px rgba(0, 0, 0, 0.18);
}

.piano-key--white.is-active {
  transform: translateY(4px);
  background:
    linear-gradient(180deg, #eef4fb 0%, #dde6f4 48%, #cad6e7 100%);
}

.piano-key--black {
  position: absolute;
  top: 0;
  width: 8%;
  height: 100%;
  border-radius: 0 0 12px 12px;
  background:
    linear-gradient(180deg, #3a3a3a 0%, #161616 60%, #000000 100%);
  color: #aab4c7;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 18px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.18),
    0 16px 18px rgba(0, 0, 0, 0.28);
  pointer-events: auto;
}

.piano-key--black.is-active {
  transform: translateY(4px);
  background:
    linear-gradient(180deg, #505050 0%, #1b1b1b 60%, #020202 100%);
}

.piano-key__note {
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: 0.01em;
}

.piano-key__hint {
  min-width: 44px;
  min-height: 44px;
  padding: 8px 10px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 800;
  background: rgba(235, 241, 248, 0.88);
  color: #a8b7cb;
  border: 1px solid rgba(183, 197, 218, 0.5);
  box-shadow: inset 0 -3px 6px rgba(194, 206, 223, 0.35);
}

.piano-key__hint--dark {
  min-width: 54px;
  min-height: 42px;
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.16);
  color: #afbad1;
  box-shadow: inset 0 -2px 4px rgba(0, 0, 0, 0.24);
}

@media (max-width: 640px) {
  .app-shell {
    padding-inline: calc(var(--safe-left) + 12px) calc(var(--safe-right) + 12px);
  }

  .top-bar {
    grid-template-columns: auto 1fr auto;
  }

  .mini-app-panel {
    padding: 14px;
  }

  .app-shell.is-immersive .top-bar {
    top: calc(var(--safe-top) + 4px);
    left: calc(var(--safe-left) + 8px);
    right: calc(var(--safe-right) + 8px);
  }

  .piano-studio__header {
    flex-direction: column;
  }

  .piano-studio__controls {
    grid-template-columns: 1fr;
  }

  .piano-sample-status {
    align-self: stretch;
  }

  .piano-keyboard {
    min-width: 760px;
  }

  .piano-key--white {
    min-height: 300px;
    padding-bottom: 14px;
  }

  .piano-key__note {
    font-size: 0.88rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
