:root {
  --bg: #071426;
  --surface: #0d2037;
  --surface-2: #112b47;
  --line: rgba(178, 213, 240, .17);
  --text: #f4f8fc;
  --muted: #9fb4c8;
  --cyan: #36d6d0;
  --blue: #45a8ff;
  --green: #45d49b;
  --red: #ff626c;
  --yellow: #ffcf66;
}

.access-gate {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(4, 12, 24, .94);
  backdrop-filter: blur(18px);
}

.access-gate.unlocked {
  display: none;
}

.access-box {
  width: min(460px, 100%);
  display: grid;
  gap: 16px;
  padding: 30px;
  border: 1px solid var(--line);
  border-radius: 28px;
  background: linear-gradient(145deg, rgba(19, 43, 67, .98), rgba(8, 24, 42, .98));
  box-shadow: 0 30px 80px rgba(0, 0, 0, .45);
}

.access-box h2,
.access-box p {
  margin: 0;
}

.access-box input {
  width: 100%;
  min-height: 58px;
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: 16px;
  color: var(--text);
  background: rgba(3, 15, 28, .72);
  font: inherit;
}

.access-error {
  min-height: 22px;
  color: #ff9eaa;
  font-weight: 700;
}

.mqtt-login {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  gap: 10px;
  margin: 14px 0 8px;
}

.mqtt-login input {
  min-width: 0;
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--text);
  background: rgba(3, 15, 28, .72);
  font: inherit;
}

.mqtt-login button {
  white-space: nowrap;
}

.mqtt-help {
  min-height: 22px;
  margin: 0 0 12px;
  color: var(--muted);
  font-size: .88rem;
}

@media (max-width: 700px) {
  .mqtt-login {
    grid-template-columns: 1fr;
  }
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at 8% 4%, rgba(54, 214, 208, .15), transparent 28rem),
    radial-gradient(circle at 94% 15%, rgba(69, 168, 255, .14), transparent 32rem),
    var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, textarea { font: inherit; }
button { color: inherit; }
button, label { -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible, textarea:focus-visible, label:focus-visible {
  outline: 3px solid rgba(54, 214, 208, .65);
  outline-offset: 3px;
}
[hidden] { display: none !important; }

.app-shell { width: min(1440px, 100%); min-height: 100vh; margin: 0 auto; padding-bottom: 32px; }
.topbar {
  min-height: 88px;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px clamp(16px, 3vw, 38px);
  border-bottom: 1px solid var(--line);
  background: rgba(7, 20, 38, .86);
  backdrop-filter: blur(18px);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand-mark {
  width: 58px;
  height: 58px;
  flex: 0 0 58px;
  display: grid;
  place-items: center;
  border-radius: 18px;
  color: #061420;
  font-weight: 1000;
  background: linear-gradient(145deg, var(--cyan), var(--blue));
  box-shadow: 0 12px 30px rgba(54, 214, 208, .2);
}
.brand-copy { min-width: 180px; }
.brand-copy span, .card-heading span { color: var(--muted); font-size: 11px; font-weight: 900; letter-spacing: .13em; }
.brand-copy h1 { margin: 2px 0 0; font-size: clamp(23px, 3vw, 32px); line-height: 1; }
.system-status { margin-left: auto; display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.status-pill {
  padding: 9px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  background: rgba(255, 255, 255, .035);
  font-size: 12px;
  font-weight: 800;
}
.status-pill.ready { color: #83f1c4; border-color: rgba(69, 212, 155, .35); background: rgba(69, 212, 155, .09); }
.status-pill.error { color: #ff9da3; border-color: rgba(255, 98, 108, .32); background: rgba(255, 98, 108, .08); }

.hero {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  padding: 30px clamp(16px, 3vw, 38px) 20px;
}
.eyebrow { margin: 0 0 7px; color: var(--cyan); font-size: 12px; font-weight: 950; letter-spacing: .13em; }
.hero h2 { margin: 0; font-size: clamp(28px, 4vw, 48px); letter-spacing: -.045em; }
.notice {
  max-width: 420px;
  padding: 12px 16px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, .035);
  font-weight: 750;
}
.notice[data-tone="good"], .task-status[data-tone="good"] { color: #84efc5; }
.notice[data-tone="error"], .task-status[data-tone="error"] { color: #ff9da3; }

.control-layout {
  display: grid;
  grid-template-columns: minmax(360px, .86fr) minmax(520px, 1.4fr);
  gap: 18px;
  padding: 0 clamp(16px, 3vw, 38px) 18px;
}
.card {
  border: 1px solid var(--line);
  border-radius: 26px;
  background: linear-gradient(145deg, rgba(17, 43, 71, .92), rgba(10, 29, 50, .95));
  box-shadow: 0 20px 70px rgba(0, 0, 0, .18);
}
.lift-card { padding: 22px; }
.card-heading { display: flex; align-items: center; gap: 13px; }
.card-heading h3, .workspace-heading h3 { margin: 3px 0 0; font-size: 25px; }
.card-icon {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border-radius: 16px;
  color: var(--cyan);
  background: rgba(54, 214, 208, .1);
  border: 1px solid rgba(54, 214, 208, .25);
  font-size: 29px;
  font-weight: 900;
}
.hint { margin: 13px 0 16px; color: var(--muted); }
.lift-controls { display: grid; grid-template-columns: 1fr .68fr 1fr; gap: 10px; }
.lift-button, .stop-button {
  min-height: 124px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border-radius: 20px;
  border: 1px solid var(--line);
  cursor: pointer;
  touch-action: none;
  user-select: none;
  transition: transform .12s ease, border-color .12s ease, background .12s ease;
}
.lift-button { background: linear-gradient(145deg, rgba(54, 214, 208, .18), rgba(69, 168, 255, .11)); }
.lift-button b { color: var(--cyan); font-size: 42px; line-height: .8; }
.lift-button span, .stop-button span { font-weight: 950; letter-spacing: .08em; }
.stop-button { background: rgba(255, 98, 108, .1); }
.stop-button b { color: var(--red); font-size: 25px; }
.lift-button.pressed { transform: translateY(3px) scale(.98); border-color: var(--cyan); background: rgba(54, 214, 208, .28); }
.lift-state { margin-top: 12px; padding: 11px; text-align: center; border-radius: 13px; color: var(--muted); background: rgba(4, 15, 28, .45); font-weight: 800; }

.feature-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.feature-card {
  min-height: 142px;
  padding: 18px;
  display: grid;
  grid-template-columns: 58px 1fr;
  grid-template-rows: auto auto;
  align-content: center;
  column-gap: 14px;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 23px;
  background: rgba(15, 37, 61, .82);
  cursor: pointer;
  transition: transform .16s ease, border-color .16s ease, background .16s ease;
}
.feature-card:hover { transform: translateY(-2px); border-color: rgba(69, 168, 255, .48); }
.feature-card.active { border-color: var(--cyan); background: linear-gradient(140deg, rgba(54, 214, 208, .17), rgba(69, 168, 255, .12)); }
.feature-icon {
  grid-row: 1 / 3;
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  border-radius: 18px;
  color: #071426;
  background: linear-gradient(145deg, var(--cyan), var(--blue));
  font-size: 23px;
  font-weight: 1000;
}
.feature-card b { align-self: end; font-size: clamp(18px, 2vw, 23px); }
.feature-card small { align-self: start; margin-top: 4px; color: var(--muted); font-size: 13px; }

.workspace { min-height: 320px; margin: 0 clamp(16px, 3vw, 38px); padding: clamp(20px, 3vw, 30px); }
.workspace-panel { display: none; }
.workspace-panel.active { display: block; animation: panel-in .18s ease; }
@keyframes panel-in { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }
.workspace-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.workspace-heading h3 { font-size: clamp(23px, 3vw, 32px); }
.file-button, .primary-button, .secondary-button, .read-button {
  border: 0;
  border-radius: 15px;
  padding: 13px 18px;
  cursor: pointer;
  font-weight: 900;
}
.file-button, .primary-button { color: #061420; background: linear-gradient(135deg, var(--cyan), var(--blue)); }
.secondary-button, .read-button { color: var(--text); border: 1px solid var(--line); background: rgba(255, 255, 255, .055); }
.secondary-button.compact { padding: 10px 14px; }
.empty-state { min-height: 150px; display: grid; place-items: center; padding: 20px; text-align: center; color: var(--muted); border: 1px dashed rgba(159, 180, 200, .3); border-radius: 20px; }
.player-box { display: grid; gap: 13px; padding: 20px; border-radius: 20px; background: rgba(4, 15, 28, .45); }
audio { width: 100%; }
.field-label { display: block; margin-bottom: 8px; color: var(--muted); font-weight: 800; }
textarea, .chat-form input {
  width: 100%;
  color: var(--text);
  border: 1px solid var(--line);
  background: rgba(4, 15, 28, .62);
}
textarea { min-height: 118px; resize: vertical; padding: 15px; border-radius: 17px; }
.action-row { display: flex; gap: 10px; margin-top: 12px; }
.task-status { margin-top: 14px; padding: 13px 15px; color: var(--muted); border-radius: 14px; background: rgba(4, 15, 28, .5); }
#generatedMusicPlayer { margin-top: 15px; }
.chat-log { min-height: 190px; max-height: 360px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 16px; border: 1px solid var(--line); border-radius: 19px; background: rgba(4, 15, 28, .48); }
.message { max-width: min(82%, 780px); padding: 12px 15px; border-radius: 16px; line-height: 1.5; white-space: pre-wrap; }
.message.assistant { align-self: flex-start; background: rgba(69, 168, 255, .13); border: 1px solid rgba(69, 168, 255, .22); }
.message.user { align-self: flex-end; color: #071426; background: var(--cyan); font-weight: 700; }
.chat-form { display: grid; grid-template-columns: 1fr auto; gap: 10px; margin-top: 12px; }
.chat-form input { min-height: 52px; padding: 0 15px; border-radius: 15px; }
.read-button { margin-top: 10px; }
button:disabled { opacity: .5; cursor: not-allowed; }

@media (max-width: 900px) {
  .topbar { position: static; flex-wrap: wrap; }
  .system-status { width: 100%; margin-left: 0; justify-content: flex-start; }
  .hero { align-items: stretch; flex-direction: column; }
  .control-layout { grid-template-columns: 1fr; }
  .feature-card { min-height: 122px; }
}

@media (max-width: 600px) {
  .app-shell { padding-bottom: 18px; }
  .topbar { min-height: 74px; padding: 10px 14px; }
  .brand-mark { width: 48px; height: 48px; flex-basis: 48px; border-radius: 14px; }
  .brand-copy span { display: none; }
  .status-pill { padding: 7px 9px; font-size: 10px; }
  .hero { padding: 20px 14px 14px; }
  .hero h2 { font-size: 30px; }
  .control-layout { padding: 0 12px 12px; gap: 12px; }
  .lift-card { padding: 16px; }
  .lift-controls { grid-template-columns: 1fr 1fr; }
  .stop-button { grid-column: 1 / 3; grid-row: 2; min-height: 62px; flex-direction: row; }
  .lift-button { min-height: 105px; }
  .feature-grid { gap: 8px; }
  .feature-card { min-height: 126px; padding: 12px; grid-template-columns: 43px 1fr; column-gap: 9px; border-radius: 18px; }
  .feature-icon { width: 43px; height: 43px; border-radius: 13px; font-size: 17px; }
  .feature-card b { font-size: 16px; }
  .feature-card small { font-size: 11px; }
  .workspace { margin: 0 12px; padding: 16px; border-radius: 21px; }
  .workspace-heading { align-items: flex-start; }
  .action-row { flex-direction: column; }
  .chat-form { grid-template-columns: 1fr; }
  .message { max-width: 94%; }
}
