:root {
  --bg: #fff8f5;
  --surface: rgba(255, 255, 255, 0.78);
  --text: #302724;
  --secondary: #776a66;
  --tertiary: #b5a8a3;
  --separator: rgba(83, 61, 54, 0.11);
  --blue: #ed806f;
  --blue-soft: rgba(237, 128, 111, 0.14);
  --red: #e45f57;
  --green: #68b692;
  --radius: 24px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* {
  box-sizing: border-box;
}

html {
  background: #efe7e3;
}

body {
  min-height: 100dvh;
  margin: 0;
  overflow-x: hidden;
  color: var(--text);
  background: #efe7e3;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Helvetica Neue", sans-serif;
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

button {
  color: inherit;
  font: inherit;
  letter-spacing: 0;
  touch-action: manipulation;
}

[hidden] {
  display: none !important;
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.app {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(100%, 430px);
  min-height: 100dvh;
  margin: 0 auto;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 42%, rgba(244, 134, 116, 0.1), transparent 34%),
    radial-gradient(circle at 8% 88%, rgba(104, 182, 146, 0.06), transparent 30%),
    var(--bg);
  isolation: isolate;
}

.app-header {
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: max(18px, env(safe-area-inset-top)) 20px 12px;
}

.app-name,
.app-subtitle {
  margin: 0;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-lockup img {
  width: 42px;
  height: 42px;
  border-radius: 11px;
  box-shadow: 0 7px 18px rgba(214, 102, 86, 0.2);
}

.app-name {
  font-size: 21px;
  font-weight: 700;
  line-height: 1.15;
}

.app-subtitle {
  margin-top: 2px;
  color: var(--secondary);
  font-size: 13px;
  font-weight: 500;
}

.history-button {
  display: grid;
  width: 44px;
  height: 44px;
  padding: 0;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.6);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.05);
  backdrop-filter: blur(24px) saturate(180%);
  cursor: pointer;
}

.history-icon {
  position: relative;
  width: 19px;
  height: 19px;
  border: 1.8px solid var(--text);
  border-radius: 50%;
}

.history-icon::before,
.history-icon::after {
  position: absolute;
  left: 8px;
  width: 1.8px;
  border-radius: 2px;
  background: var(--text);
  content: "";
  transform-origin: bottom center;
}

.history-icon::before {
  top: 3px;
  height: 6px;
}

.history-icon::after {
  top: 7px;
  height: 5px;
  transform: rotate(125deg);
}

.listen-view {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  min-height: 0;
  padding: 30px 22px max(28px, env(safe-area-inset-bottom));
  transition: opacity 300ms ease, transform 500ms var(--ease);
}

.listen-copy {
  width: 100%;
  text-align: center;
}

.state-label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin: 0 0 12px;
  color: var(--secondary);
  font-size: 14px;
  font-weight: 600;
}

.state-label span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 5px rgba(104, 182, 146, 0.13);
  transition: background 240ms ease, box-shadow 240ms ease;
}

h1 {
  margin: 0;
  font-size: 34px;
  font-weight: 740;
  line-height: 1.14;
}

#mainHint {
  margin: 13px 0 0;
  color: var(--secondary);
  font-size: 16px;
  line-height: 1.45;
}

.first-use {
  width: 100%;
  margin-top: 26px;
}

.feature-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.82);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.58);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.035);
  backdrop-filter: blur(24px) saturate(160%);
}

.feature-item {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
  min-height: 102px;
  padding: 15px 5px 12px;
  text-align: center;
}

.feature-item + .feature-item::before {
  position: absolute;
  top: 18px;
  bottom: 18px;
  left: 0;
  width: 1px;
  background: var(--separator);
  content: "";
}

.feature-item > span:last-child {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.feature-item strong {
  margin-top: 8px;
  font-size: 13px;
  font-weight: 700;
}

.feature-item small {
  margin-top: 3px;
  color: var(--secondary);
  font-size: 10px;
  line-height: 1.25;
}

.feature-icon {
  position: relative;
  display: block;
  width: 28px;
  height: 28px;
  border-radius: 9px;
  color: var(--blue);
  background: var(--blue-soft);
}

.sound-icon::before {
  position: absolute;
  top: 8px;
  left: 7px;
  width: 2px;
  height: 12px;
  border-radius: 2px;
  background: currentColor;
  box-shadow: 4px 3px 0 -0.2px currentColor, 8px -2px 0 -0.2px currentColor, 12px 2px 0 -0.2px currentColor;
  content: "";
}

.mood-icon {
  color: #d8758d;
  background: rgba(216, 117, 141, 0.12);
}

.mood-icon::before,
.mood-icon::after {
  position: absolute;
  top: 8px;
  width: 10px;
  height: 15px;
  border-radius: 10px 10px 4px 4px;
  background: currentColor;
  content: "";
}

.mood-icon::before {
  left: 7px;
  transform: rotate(-45deg);
  transform-origin: 0 100%;
}

.mood-icon::after {
  right: 7px;
  transform: rotate(45deg);
  transform-origin: 100% 100%;
}

.learn-icon {
  color: #559f7e;
  background: rgba(85, 159, 126, 0.12);
}

.learn-icon::before {
  position: absolute;
  inset: 7px;
  border: 2px solid currentColor;
  border-radius: 50%;
  content: "";
}

.learn-icon::after {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 6px;
  height: 6px;
  border: 2px solid var(--bg);
  border-radius: 50%;
  background: currentColor;
  content: "";
}

.scope-button {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  margin: 4px auto 0;
  padding: 0 8px;
  border: 0;
  color: var(--secondary);
  background: transparent;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.scope-button span {
  display: grid;
  width: 16px;
  height: 16px;
  place-items: center;
  border: 1px solid var(--tertiary);
  border-radius: 50%;
  font-family: Georgia, serif;
  font-size: 10px;
}

.sound-stage {
  position: relative;
  display: grid;
  width: 100%;
  height: 88px;
  margin: 4px 0 14px;
  place-items: center;
}

#waveCanvas {
  display: block;
  width: 100%;
  height: 82px;
  opacity: 0.82;
}

.timer {
  position: absolute;
  bottom: -2px;
  color: var(--secondary);
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  opacity: 0;
  transform: translateY(5px);
  transition: opacity 200ms ease, transform 300ms var(--ease);
}

.record-button {
  position: relative;
  display: grid;
  flex: 0 0 auto;
  width: 124px;
  height: 124px;
  padding: 0;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
}

.record-halo {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: var(--blue-soft);
  transition: transform 500ms var(--ease), opacity 300ms ease;
}

.record-face {
  z-index: 1;
  display: grid;
  width: 92px;
  height: 92px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.76);
  border-radius: 50%;
  color: #fff;
  background: var(--blue);
  box-shadow:
    0 18px 42px rgba(225, 105, 88, 0.25),
    inset 0 1px 1px rgba(255, 255, 255, 0.36);
  transition: transform 220ms var(--ease), background 240ms ease, box-shadow 240ms ease;
}

.record-button:active .record-face {
  transform: scale(0.92);
}

.record-button:disabled,
.feedback-control button:disabled,
.history-nav-button:disabled {
  cursor: wait;
  opacity: 0.62;
}

.mic-icon,
.small-mic {
  position: relative;
  display: block;
  width: 18px;
  height: 29px;
  border: 2.5px solid currentColor;
  border-radius: 10px;
}

.mic-icon::before,
.small-mic::before {
  position: absolute;
  right: -8px;
  bottom: -8px;
  left: -8px;
  height: 15px;
  border: 2.5px solid currentColor;
  border-top: 0;
  border-radius: 0 0 14px 14px;
  content: "";
}

.mic-icon::after,
.small-mic::after {
  position: absolute;
  bottom: -13px;
  left: 50%;
  width: 2.5px;
  height: 6px;
  border-radius: 2px;
  background: currentColor;
  content: "";
  transform: translateX(-50%);
}

.record-caption {
  margin: 15px 0 0;
  color: var(--secondary);
  font-size: 15px;
  font-weight: 600;
}

.app.is-recording .state-label {
  color: var(--red);
}

.app.is-recording .state-label span {
  background: var(--red);
  box-shadow: 0 0 0 5px rgba(228, 95, 87, 0.12);
  animation: status-pulse 1s ease-in-out infinite;
}

.app.is-recording .record-face {
  background: var(--red);
  box-shadow: 0 18px 42px rgba(228, 95, 87, 0.24);
}

.app.is-recording .record-halo {
  background: rgba(228, 95, 87, 0.1);
  animation: listen-pulse 1.4s ease-out infinite;
}

.app.is-recording .timer,
.app.is-analyzing .timer {
  opacity: 1;
  transform: none;
}

.app.is-analyzing .record-halo {
  animation: analyzing 1.2s ease-in-out infinite;
}

.app.is-analyzing .record-face {
  background: #8e8e93;
  box-shadow: 0 14px 34px rgba(60, 60, 67, 0.18);
}

.result-sheet {
  position: absolute;
  z-index: 20;
  inset: 68px 0 0;
  overflow-y: auto;
  padding: 10px 22px max(28px, env(safe-area-inset-bottom));
  border-top: 1px solid rgba(255, 255, 255, 0.84);
  border-radius: 32px 32px 0 0;
  background: rgba(255, 250, 247, 0.93);
  box-shadow: 0 -24px 70px rgba(0, 0, 0, 0.11);
  backdrop-filter: blur(36px) saturate(180%);
  opacity: 0;
  pointer-events: none;
  transform: translateY(102%);
  transition: transform 650ms var(--ease), opacity 300ms ease;
  scrollbar-width: none;
}

.result-sheet::-webkit-scrollbar {
  display: none;
}

.app.has-result .listen-view {
  opacity: 0.18;
  transform: scale(0.96) translateY(-18px);
}

.app.has-result .result-sheet {
  opacity: 1;
  pointer-events: auto;
  transform: none;
}

.sheet-handle {
  width: 36px;
  height: 5px;
  margin: 0 auto 24px;
  border-radius: 3px;
  background: rgba(60, 60, 67, 0.22);
}

.result-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--secondary);
  font-size: 13px;
  font-weight: 600;
}

.result-meta span:last-child {
  padding: 5px 9px;
  border-radius: 9px;
  color: var(--blue);
  background: var(--blue-soft);
}

.result-kicker {
  margin: 28px 0 7px;
  color: var(--secondary);
  font-size: 15px;
  font-weight: 600;
}

h2 {
  margin: 0;
  font-size: 32px;
  font-weight: 750;
  line-height: 1.16;
}

.explanation {
  margin: 15px 0 25px;
  color: var(--secondary);
  font-size: 16px;
  line-height: 1.62;
}

.probability-list {
  display: grid;
  gap: 17px;
  padding: 20px;
  border: 1px solid rgba(255, 255, 255, 0.8);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.7);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.04);
}

.probability-row {
  display: grid;
  grid-template-columns: 74px 1fr 38px;
  align-items: center;
  gap: 11px;
  min-height: 24px;
  font-size: 13px;
}

.probability-row span {
  font-weight: 600;
}

.probability-row progress {
  width: 100%;
  height: 6px;
  overflow: hidden;
  border: 0;
  border-radius: 3px;
  background: rgba(60, 60, 67, 0.1);
  appearance: none;
}

.probability-row progress::-webkit-progress-bar {
  border-radius: 3px;
  background: rgba(60, 60, 67, 0.1);
}

.probability-row progress::-webkit-progress-value {
  border-radius: 3px;
  background: var(--blue);
}

.probability-row progress::-moz-progress-bar {
  border-radius: 3px;
  background: var(--blue);
}

.probability-row strong {
  color: var(--secondary);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.feedback-block {
  margin: 27px 0 18px;
}

.feedback-block > p:first-child {
  margin: 0 0 11px;
  font-size: 15px;
  font-weight: 650;
}

.feedback-control {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border-radius: 13px;
  background: rgba(118, 118, 128, 0.12);
}

.feedback-control button {
  min-height: 44px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  font-size: 15px;
  font-weight: 650;
  cursor: pointer;
  transition: background 180ms ease, box-shadow 180ms ease, color 180ms ease;
}

.feedback-control button.is-selected {
  background: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  color: var(--blue);
}

.feedback-state {
  margin: 10px 0 0;
  color: var(--tertiary);
  font-size: 12px;
  text-align: center;
}

.again-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 11px;
  width: 100%;
  min-height: 54px;
  border: 0;
  border-radius: 16px;
  color: #fff;
  background: #3a2d29;
  font-size: 16px;
  font-weight: 680;
  cursor: pointer;
}

.history-view {
  position: absolute;
  z-index: 40;
  inset: 0;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(circle at 86% 12%, rgba(104, 182, 146, 0.08), transparent 28%),
    var(--bg);
  opacity: 0;
  pointer-events: none;
  transform: translateX(100%);
  transition: transform 520ms var(--ease), opacity 220ms ease;
}

.app.has-history .history-view {
  opacity: 1;
  pointer-events: auto;
  transform: none;
}

.history-header {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  gap: 12px;
  padding: max(18px, env(safe-area-inset-top)) 18px 14px;
  border-bottom: 1px solid var(--separator);
  background: rgba(255, 248, 245, 0.84);
  backdrop-filter: blur(24px) saturate(170%);
}

.history-header > div {
  min-width: 0;
  text-align: center;
}

.history-header p,
.history-header h2 {
  margin: 0;
}

.history-header p {
  margin-bottom: 2px;
  color: var(--secondary);
  font-size: 11px;
  font-weight: 600;
}

.history-header h2 {
  font-size: 20px;
}

.history-nav-button {
  display: grid;
  width: 44px;
  height: 44px;
  padding: 0;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.7);
  box-shadow: 0 5px 16px rgba(77, 48, 40, 0.06);
  cursor: pointer;
}

.history-nav-button span {
  display: block;
  margin-top: -3px;
  font-size: 34px;
  font-weight: 300;
  line-height: 1;
}

.refresh-button span {
  margin: 0;
  color: var(--blue);
  font-size: 23px;
  font-weight: 500;
}

.history-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 18px max(28px, env(safe-area-inset-bottom));
  scrollbar-width: none;
}

.history-body::-webkit-scrollbar {
  display: none;
}

.history-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 360px;
  padding: 24px;
  color: var(--secondary);
  text-align: center;
}

.history-state strong {
  margin-top: 18px;
  color: var(--text);
  font-size: 17px;
}

.history-state p {
  max-width: 260px;
  margin: 8px 0 0;
  font-size: 14px;
  line-height: 1.55;
}

.history-loader {
  width: 28px;
  height: 28px;
  border: 3px solid var(--blue-soft);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: history-spin 800ms linear infinite;
}

.history-state-icon {
  position: relative;
  display: grid;
  width: 54px;
  height: 54px;
  place-items: center;
  border-radius: 18px;
  background: var(--blue-soft);
}

.history-state-icon::before {
  width: 20px;
  height: 20px;
  border: 2px solid var(--blue);
  border-radius: 50%;
  content: "";
}

.history-state.error .history-state-icon::after {
  position: absolute;
  width: 2px;
  height: 13px;
  border-radius: 2px;
  background: var(--blue);
  content: "";
}

.history-list {
  display: grid;
  gap: 12px;
}

.history-card {
  width: 100%;
  min-height: 152px;
  padding: 17px;
  border: 1px solid rgba(255, 255, 255, 0.84);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.7);
  box-shadow: 0 10px 28px rgba(78, 48, 40, 0.05);
  cursor: pointer;
  text-align: left;
  transition: transform 180ms var(--ease), box-shadow 180ms ease;
}

.history-card:active {
  transform: scale(0.985);
}

.history-card-top,
.history-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--secondary);
  font-size: 12px;
}

.history-feedback {
  padding: 4px 8px;
  border-radius: 8px;
  color: var(--blue);
  background: var(--blue-soft);
  font-weight: 650;
}

.history-card > strong {
  display: block;
  margin-top: 15px;
  font-size: 18px;
}

.history-card > p {
  margin: 5px 0 16px;
  color: var(--secondary);
  font-size: 14px;
}

.history-card-footer span:first-child {
  color: var(--text);
  font-weight: 650;
}

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

.small-mic {
  width: 10px;
  height: 16px;
  border-width: 1.7px;
  border-radius: 6px;
}

.small-mic::before {
  right: -5px;
  bottom: -5px;
  left: -5px;
  height: 8px;
  border-width: 1.7px;
}

.small-mic::after {
  bottom: -8px;
  width: 1.7px;
  height: 4px;
}

.toast {
  position: absolute;
  z-index: 50;
  top: max(82px, calc(env(safe-area-inset-top) + 62px));
  left: 50%;
  max-width: calc(100% - 40px);
  padding: 11px 15px;
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 14px;
  color: #fff;
  background: rgba(29, 29, 31, 0.84);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.16);
  backdrop-filter: blur(20px);
  font-size: 13px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  text-align: center;
  transform: translate(-50%, -10px);
  transition: opacity 180ms ease, transform 300ms var(--ease);
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

button:focus-visible {
  outline: 3px solid rgba(237, 128, 111, 0.42);
  outline-offset: 3px;
}

@keyframes status-pulse {
  50% { opacity: 0.45; }
}

@keyframes listen-pulse {
  0% { opacity: 0.78; transform: scale(0.88); }
  100% { opacity: 0; transform: scale(1.38); }
}

@keyframes analyzing {
  50% { opacity: 0.28; transform: scale(0.84); }
}

@media (min-width: 560px) {
  body {
    display: grid;
    padding: 24px;
    place-items: center;
  }

  .app {
    min-height: min(884px, calc(100dvh - 48px));
    border: 1px solid rgba(255, 255, 255, 0.9);
    border-radius: 44px;
    box-shadow: 0 35px 90px rgba(0, 0, 0, 0.16);
  }
}

@media (max-height: 760px) {
  .listen-view {
    padding-top: 12px;
  }

  .sound-stage {
    height: 68px;
    margin: 0 0 6px;
  }

  .first-use {
    margin-top: 16px;
  }

  .feature-item {
    min-height: 88px;
    padding-top: 10px;
  }

  .record-button {
    width: 112px;
    height: 112px;
  }

  .record-face {
    width: 84px;
    height: 84px;
  }
}

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