/* web/style.css */
* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

[hidden] {
  display: none !important;
}

:root {
  --bg-0: #07070b;
  --bg-1: #0c0c14;
  --fg: #f1f1f7;
  --muted: #8b8b9c;
  --glass-bg: #ffffff0b;
  --glass-bg-hover: #ffffff13;
  --glass-border: #ffffff1a;
  --glass-border-strong: #ffffff2e;
  --accent-a: #7383ff;
  --accent-b: #b15eff;
  --rec-a: #f57;
  --rec-b: #ff7a4f;
  --shadow-deep: 0 30px 80px -20px #000000b3;
}

html, body {
  background: var(--bg-0);
  color: var(--fg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  letter-spacing: -.01em;
  overscroll-behavior: none;
  overflow: hidden;
  height: 100%;
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, SF Pro Display, system-ui, Segoe UI, Roboto, Noto Sans, Ubuntu, Cantarell, Helvetica Neue, sans-serif;
}

body:before, body:after {
  content: "";
  position: fixed;
  pointer-events: none;
  z-index: -1;
  inset: 0;
}

body:before {
  background: radial-gradient(ellipse 60% 50% at 30% 20%, #7383ff38, transparent 60%), radial-gradient(ellipse 60% 50% at 80% 90%, #b15eff2e, transparent 60%), radial-gradient(ellipse 80% 60% at 50% 50%, #141628, var(--bg-0) 80%);
}

body:after {
  mask-image: radial-gradient(70% 60% at 50% 40%, #000 30%, #0000 80%);
  -webkit-mask-image: radial-gradient(70% 60% at 50% 40%, #000 30%, #0000 80%);
  opacity: .6;
  background-image: radial-gradient(circle at 1px 1px, #ffffff0a 1px, #0000 0);
  background-size: 28px 28px;
}

main {
  position: relative;
  display: flex;
  padding: max(env(safe-area-inset-top), 24px) 20px max(env(safe-area-inset-bottom), 24px);
  flex-direction: column;
  justify-content: center;
  align-items:  center;
  gap: 24px;
  height: 100dvh;
}

#rec {
  --size: min(72vw, 62vh, 360px);
  position: relative;
  width: var(--size);
  height: var(--size);
  border: 1px solid var(--glass-border-strong);
  background: var(--glass-bg);
  backdrop-filter: blur(28px) saturate(180%);
  -webkit-backdrop-filter: blur(28px) saturate(180%);
  color: var(--fg);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  display: grid;
  box-shadow: var(--shadow-deep), inset 0 1px 0 #ffffff14, inset 0 -20px 40px #7383ff14;
  overflow: hidden;
  isolation: isolate;
  border-radius: 50%;
  place-items:  center;
  transition: transform .18s cubic-bezier(.34,1.4,.64,1), box-shadow .5s, border-color .5s;
}

#rec:before {
  content: "";
  position: absolute;
  filter: blur(40px);
  opacity: .5;
  z-index: -1;
  animation: spin 18s linear infinite;
  background: conic-gradient(#7383ff59, #b15eff40, #7383ff59);
  inset: -20%;
}

#rec:after {
  content: "";
  position: absolute;
  border-radius: inherit;
  pointer-events: none;
  background: linear-gradient(160deg, #ffffff1a 0%, #fff0 40% 60%, #ffffff0a 100%);
  inset: 0;
}

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

#rec:active {
  transform: scale(.97);
}

#rec.recording {
  --voice-level: 0;
  border-color: rgba(255, 85, 119, calc(.45 + var(--voice-level) * .4));
  box-shadow: var(--shadow-deep), 0 0 calc(40px + var(--voice-level) * 60px) rgba(255, 85, 119, calc(.28 + var(--voice-level) * .32)), inset 0 1px 0 #ffffff1a, inset 0 -20px 40px rgba(255, 85, 119, calc(.1 + var(--voice-level) * .15));
  transition: border-radius 90ms ease-out, border-color .3s, box-shadow .3s;
}

#rec.recording:before {
  opacity: .7;
  animation-duration: 6s;
  background: conic-gradient(#ff55778c, #ff7a4f73, #ff55778c);
}

#rec.busy {
  cursor: progress;
  border-color: #ffffff2e;
}

#rec.busy:before {
  animation-duration: 1.6s;
}

.rec-inner {
  position: relative;
  display: flex;
  z-index: 1;
  flex-direction: column;
  justify-content: center;
  align-items:  center;
  gap: 6px;
}

.mic-icon {
  fill: none;
  stroke: var(--fg);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 4px 16px #7383ff80);
  width: 28%;
  height: 28%;
  transition: opacity .2s, transform .2s;
}

#rec.recording .mic-icon, #rec.busy .mic-icon {
  opacity: 0;
  transform: scale(.8);
}

#rec-label {
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--muted);
  transition: opacity .2s;
  font-size: 13px;
  font-weight: 600;
}

#rec.recording #rec-label, #rec.busy #rec-label {
  opacity: 0;
}

#rec-time {
  position: absolute;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.02em;
  color: var(--fg);
  opacity: 0;
  text-shadow: 0 4px 24px #f576;
  transition: opacity .25s;
  font-size: clamp(40px, 9vw, 56px);
  font-weight: 300;
}

#rec.recording #rec-time, #rec.busy #rec-time {
  opacity: 1;
}

#rec.busy #rec-time {
  text-shadow: 0 4px 24px #7383ff66;
}

.busy-spinner {
  position: absolute;
  border: 2px solid #0000;
  border-top-color: var(--accent-a);
  border-right-color: var(--accent-b);
  opacity: 0;
  animation: spin .9s linear infinite;
  border-radius: 50%;
  width: 36%;
  height: 36%;
  transition: opacity .2s;
}

#rec.busy .busy-spinner {
  opacity: 1;
}

.topbar {
  position: fixed;
  display: flex;
  padding: max(env(safe-area-inset-top), 14px) 18px 0 18px;
  z-index: 10;
  pointer-events: none;
  justify-content: space-between;
  align-items:  center;
  top: 0;
  left: 0;
  right: 0;
}

.topbar > * {
  pointer-events: auto;
}

.topbar-btn {
  position: relative;
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  color: var(--fg);
  cursor: pointer;
  display: grid;
  -webkit-tap-highlight-color: transparent;
  background: #ffffff0a;
  border-radius: 50%;
  place-items:  center;
  width: 38px;
  height: 38px;
  transition: background .15s, transform .1s;
}

.topbar-btn:hover {
  background: #ffffff14;
}

.topbar-btn:active {
  transform: scale(.94);
}

.topbar-btn svg {
  width: 18px;
  height: 18px;
}

.topbar-badge {
  position: absolute;
  font-variant-numeric: tabular-nums;
  background: var(--rec-a);
  color: #fff;
  display: grid;
  border: 2px solid var(--bg-0);
  border-radius: 999px;
  place-items:  center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  font-size: 10px;
  font-weight: 700;
  top: -4px;
  right: -4px;
  box-shadow: 0 2px 6px #0006;
}

.total-pill {
  display: inline-block;
  letter-spacing: .04em;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  background: #ffffff0a;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 11px;
  font-weight: 500;
}

.topbar-right {
  display: flex;
  align-items:  center;
  gap: 8px;
}

.offline-pill {
  display: inline-block;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: #ff8a93;
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  animation: offline-pulse 1.8s ease-in-out infinite;
  background: #ff646424;
  border: 1px solid #ff64644d;
  border-radius: 999px;
  padding: 5px 11px;
  font-size: 10px;
  font-weight: 700;
}

.user-pill {
  display: inline-flex;
  letter-spacing: .02em;
  color: var(--fg);
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  border-radius: 999px;
  align-items:  center;
  gap: 6px;
  max-width: 120px;
  padding: 6px 11px;
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
}

.user-pill:active {
  transform: scale(.96);
}

.user-menu {
  position: fixed;
  z-index: 110;
  display: flex;
  align-items: stretch;
  inset: 0;
}

.user-menu-backdrop {
  position: absolute;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  animation: hist-fade .22s ease;
  background: #0000008c;
  inset: 0;
}

.user-menu-sheet {
  position: absolute;
  display: grid;
  backdrop-filter: blur(40px) saturate(180%);
  -webkit-backdrop-filter: blur(40px) saturate(180%);
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow-deep);
  animation: hist-fade .22s cubic-bezier(.16, 1, .3, 1);
  background: #0e0e16db;
  border-radius: 18px;
  gap: 8px;
  min-width: 240px;
  padding: 22px 22px 18px;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.user-menu-name {
  text-align: center;
  color: var(--muted);
  letter-spacing: .04em;
  text-transform: uppercase;
  margin: 0 0 6px;
  font-size: 13px;
  font-weight: 600;
}

.ghost-btn.danger {
  color: #ff8a93;
}

@keyframes offline-pulse {
  0%, 100% {
    opacity: .85;
  }

  50% {
    opacity: .55;
  }
}

.history-modal {
  position: fixed;
  z-index: 100;
  display: flex;
  align-items: stretch;
  inset: 0;
}

.history-backdrop {
  position: absolute;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  animation: hist-fade .22s ease;
  background: #0000008c;
  inset: 0;
}

.history-sheet {
  position: absolute;
  display: flex;
  backdrop-filter: blur(40px) saturate(180%);
  -webkit-backdrop-filter: blur(40px) saturate(180%);
  animation: hist-slide .32s cubic-bezier(.16, 1, .3, 1);
  background: #0e0e16db;
  flex-direction: column;
  inset: 0;
}

@keyframes hist-fade {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes hist-slide {
  from {
    transform: translateY(100%);
  }

  to {
    transform: translateY(0);
  }
}

.history-head {
  display: flex;
  padding: max(env(safe-area-inset-top), 16px) 16px 12px 16px;
  border-bottom: 1px solid var(--glass-border);
  align-items:  center;
  gap: 12px;
}

.history-head h2 {
  letter-spacing: -.01em;
  text-align: center;
  flex: 1;
  margin: 0;
  font-size: 17px;
  font-weight: 600;
}

.ghost-btn {
  color: var(--accent-a);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  background: none;
  border: none;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
}

.history-list {
  overflow-y: auto;
  padding: 12px 16px max(env(safe-area-inset-bottom), 24px) 16px;
  display: flex;
  flex-direction: column;
  flex: 1;
  gap: 10px;
}

.history-item {
  position: relative;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  padding: 12px 14px;
  transition: opacity .2s, background .2s;
}

.history-item.read {
  opacity: .55;
}

.history-item.unread:before {
  content: "";
  position: absolute;
  background: var(--accent-a);
  box-shadow: 0 0 8px var(--accent-a);
  border-radius: 50%;
  width: 6px;
  height: 6px;
  top: 14px;
  left: -3px;
}

.history-item-head {
  display: flex;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  align-items:  center;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 11px;
}

.history-time {
  flex: 1;
}

.badge {
  display: inline-block;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--accent-a);
  background: #7383ff2e;
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 9px;
  font-weight: 700;
}

.badge.offline {
  color: #ff9e7a;
  background: #ff7a4f2e;
}

.badge.pending {
  color: #ffd070;
  background: #ffc83c2e;
}

.history-text {
  color: var(--fg);
  word-wrap: break-word;
  white-space: pre-wrap;
  margin: 0;
  font-size: 14px;
  line-height: 1.45;
}

.history-pending {
  color: var(--muted);
  margin: 0;
  font-size: 13px;
  font-style: italic;
}

.history-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.history-actions button {
  color: var(--fg);
  border: 1px solid var(--glass-border);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  background: #ffffff0d;
  border-radius: 8px;
  padding: 6px 12px;
  transition: background .15s, transform 80ms;
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
}

.history-actions button:active {
  transform: scale(.96);
}

.history-actions button.danger {
  color: #ff8a93;
}

.history-cost {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 10px;
}

.history-empty {
  text-align: center;
  color: var(--muted);
  margin: 0;
  padding: 60px 20px;
  font-size: 14px;
}

#result {
  display: flex;
  background: var(--glass-bg);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow-deep), inset 0 1px 0 #ffffff0f;
  animation: slide-up .4s cubic-bezier(.16, 1, .3, 1);
  border-radius: 22px;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 560px;
  padding: 16px;
}

@keyframes slide-up {
  from {
    transform: translateY(16px);
    opacity: 0;
  }

  to {
    transform: translateY(0);
    opacity: 1;
  }
}

#text {
  color: var(--fg);
  resize: none;
  -webkit-user-select: text;
  user-select: text;
  outline: none;
  background: #00000040;
  border: 1px solid #ffffff0f;
  border-radius: 14px;
  width: 100%;
  min-height: 96px;
  max-height: 32vh;
  padding: 14px 16px;
  font-family: inherit;
  font-size: 16px;
  line-height: 1.45;
}

#text:focus {
  border-color: #7383ff66;
}

.result-footer {
  display: flex;
  justify-content: space-between;
  align-items:  center;
  gap: 12px;
}

.cost-line {
  letter-spacing: .04em;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 0 auto;
  min-width: 0;
  font-size: 11px;
  font-weight: 500;
}

#copy {
  position: relative;
  letter-spacing: .02em;
  color: #fff;
  background: linear-gradient(135deg, var(--accent-a), var(--accent-b));
  cursor: pointer;
  overflow: hidden;
  border: none;
  border-radius: 12px;
  flex: none;
  padding: 12px 22px;
  transition: transform .12s, box-shadow .2s;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 8px 24px #7383ff59, inset 0 1px #ffffff40;
}

#copy:active {
  transform: scale(.985);
}

#copy.copied {
  background: linear-gradient(135deg, #34d399, #10b981);
  box-shadow: 0 8px 24px #34d39959, inset 0 1px #ffffff40;
}

#status {
  letter-spacing: .02em;
  color: var(--muted);
  text-align: center;
  min-height: 1.6em;
  margin: 0;
  transition: color .2s;
  font-size: 13px;
  font-weight: 500;
}

#status.error {
  color: #ff8a93;
}

#status.success {
  color: #5be3a4;
}
