:root {
  color-scheme: dark;
  --bg: #101216;
  --panel: #191d24;
  --panel-2: #222733;
  --text: #f4f7fb;
  --muted: #9aa5b5;
  --line: #343b49;
  --accent: #38bdf8;
  --danger: #ef4444;
  --ok: #22c55e;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

button {
  min-height: 48px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #061018;
  font-weight: 800;
  cursor: pointer;
}

.link-btn {
  display: inline-flex;
  min-height: 48px;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  border-radius: 8px;
  font-weight: 800;
  text-decoration: none;
}

button:active {
  transform: translateY(1px);
}

input {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0d1015;
  color: var(--text);
  padding: 0 14px;
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.login-shell,
.student-shell,
.admin-shell {
  width: min(100%, 980px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 16px;
}

.login-shell {
  display: grid;
  place-items: center;
}

.login-card h1 {
  margin: 0;
  letter-spacing: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.top-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.topbar h1,
.account-head h2 {
  margin: 0;
  letter-spacing: 0;
}

.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
}

.ghost-btn {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
}

.danger-btn,
.stop-btn {
  background: var(--danger);
  color: white;
}

.media-panel {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #05070a;
  aspect-ratio: 16 / 10;
}

.media-panel img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  margin-top: 12px;
}

.form-row button {
  min-width: 84px;
  padding: 0 16px;
}

.control-wrap {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.drive-buttons {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.drive-btn {
  min-height: min(30vh, 180px);
  touch-action: none;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  font-size: clamp(1rem, 5vw, 1.5rem);
}

.drive-btn:active,
.drive-btn:focus-visible {
  background: var(--accent);
  color: #061018;
}

.both-btn {
  background: #1f3a46;
}

.stop-btn {
  width: 100%;
  min-height: 64px;
  font-size: 1.2rem;
}

.status,
.notice {
  min-height: 24px;
  color: var(--muted);
}

.notice {
  padding: 12px;
  border-radius: 8px;
  background: rgba(34, 197, 94, 0.14);
  color: #bbf7d0;
}

.notice.error {
  background: rgba(239, 68, 68, 0.16);
  color: #fecaca;
}

.admin-card {
  display: grid;
  gap: 12px;
  margin-bottom: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.login-card,
.create-card {
  max-width: 460px;
}

.account-list {
  display: grid;
  gap: 14px;
}

.account-head,
.button-row,
.inline-form {
  display: flex;
  align-items: center;
  gap: 10px;
}

.account-head {
  justify-content: space-between;
}

.account-head span {
  color: var(--muted);
  font-weight: 800;
}

.inline-form input {
  flex: 1;
}

.button-row {
  flex-wrap: wrap;
}

.button-row form {
  flex: 1;
}

.button-row button,
.inline-form button {
  width: 100%;
  padding: 0 14px;
}

@media (max-width: 680px) {
  .student-shell,
  .login-shell,
  .admin-shell {
    padding: 12px;
  }

  .topbar {
    align-items: flex-start;
  }

  .topbar h1 {
    font-size: 1.35rem;
  }

  .form-row,
  .inline-form {
    grid-template-columns: 1fr;
    display: grid;
  }

  .form-row button,
  .inline-form button {
    width: 100%;
  }

  .media-panel {
    aspect-ratio: 4 / 3;
  }

  .drive-buttons {
    gap: 8px;
  }

  .drive-btn {
    min-height: 120px;
  }
}

/* Student dashboard */
.dashboard-grid{
  display:grid;
  grid-template-columns:minmax(150px, 0.55fr) minmax(240px, 0.95fr) minmax(180px, 0.7fr);
  gap:12px;
  align-items:start;
  position:relative;
}

.face-stack{
  display:grid;
  gap:0;
  justify-items:center;
}

.phone-frame{
  width:min(100%, 360px);
  justify-self:center;
  display:grid;
  overflow:hidden;
  border:8px solid #090b0f;
  border-radius:28px;
  background:#090b0f;
  padding:8px;
  box-shadow:
    0 0 0 1px rgba(255,255,255,0.03) inset,
    0 14px 34px rgba(0,0,0,0.42);
}

.phone-screen{
  width:100%;
  aspect-ratio:720 / 1600;
  border:0;
  border-radius:18px;
  background:#fff;
  overflow:hidden;
  display:grid;
  grid-template-rows:64fr 1220fr 9fr 217fr 90fr;
}

.phone-top-system{
  min-height:0;
  background:#000;
}

.phone-image-area{
  width:calc(714 / 720 * 100%);
  min-height:0;
  justify-self:center;
  background:#fff;
}

.phone-image-area img{
  display:block;
  width:100%;
  height:100%;
  object-fit:fill;
}

.phone-status-line{
  width:100%;
  height:100%;
  background:#ff0000;
}

.phone-status-line.is-on{
  background:#00ff00;
}

.phone-button-row{
  display:grid;
  grid-template-columns:repeat(2, minmax(0, 1fr));
  gap:0;
  min-height:0;
  background:#fff;
}

.phone-system-nav{
  min-height:0;
  background:
    #000
    url("/src/img/one-ui-nav-bar.png")
    center / 100% 100%
    no-repeat;
}

.phone-screen-drive-btn{
  width:100%;
  height:100%;
  min-height:0;
  border:0;
  border-radius:0;
  background:#000;
  color:transparent;
  font-size:0;
  box-shadow:none;
  touch-action:none;
  transition:background-color 0.08s ease;
}

.phone-screen-drive-btn.is-on,
.phone-screen-drive-btn:active{
  background:#fff;
}

.image-history-panel{
  min-height:100%;
}

.image-url-panel{
  position:relative;
  align-self:start;
  min-height:0;
}

.image-url-row{
  display:grid;
  gap:8px;
}

.image-url-line{
  position:absolute;
  top:50%;
  right:100%;
  width:var(--image-url-line-width, 12px);
  height:2px;
  background:var(--line);
  transform:translateY(-1px);
}

.dashboard-drive{
  display:grid;
  gap:8px;
  width:min(100%, 360px);
  justify-self:center;
}

.dashboard-drive .drive-buttons{
  display:grid;
  grid-template-columns:minmax(0, 1fr);
  row-gap:0;
  position:relative;
}

.dashboard-drive .drive-btn{
  min-height:clamp(64px, 10vh, 96px);
  font-size:clamp(1rem, 3vw, 1.35rem);
  position:relative;
  z-index:2;
}

.dashboard-drive .both-btn{
  width:min(62%, 260px);
  justify-self:center;
  min-height:clamp(56px, 8vh, 74px);
  margin-top:0;
}

.dashboard-drive .stop-btn{
  min-height:48px;
  font-size:1rem;
}

.drive-lines{
  grid-column:1 / -1;
  position:relative;
  height:64px;
  z-index:1;
}

.drive-lines span{
  position:absolute;
  display:block;
  background:var(--line);
}

.drive-line-left,
.drive-line-right{
  top:0;
  width:2px;
  height:32px;
}

.drive-line-left{
  left:25%;
}

.drive-line-right{
  right:25%;
}

.drive-line-join{
  top:32px;
  left:25%;
  right:25%;
  height:2px;
}

.drive-line-down{
  top:32px;
  left:50%;
  width:2px;
  height:32px;
  transform:translateX(-1px);
}

.preset-section,
.sfx-section{
  margin-top:12px;
}

.side-panel{
  border:1px solid var(--line);
  border-radius:8px;
  background:var(--panel);
  padding:12px;
  overflow:hidden;
}

.side-panel-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:8px;
  margin-bottom:10px;
}

.compact-panel-head{
  margin-top:14px;
}

.side-panel h2{
  margin:0;
  font-size:1rem;
  letter-spacing:0;
}

.toggle-panel-row{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:14px;
}

.toggle-panel-row p{
  margin:4px 0 0;
  color:var(--muted);
  font-size:0.9rem;
  font-weight:700;
}

.stt-toggle-row{
  margin-bottom:0;
}

.toggle-switch{
  position:relative;
  display:block;
  width:64px;
  height:36px;
  flex:0 0 auto;
  cursor:pointer;
}

.toggle-switch input{
  position:absolute;
  opacity:0;
  width:1px;
  height:1px;
}

.toggle-slider{
  position:absolute;
  inset:0;
  border:1px solid var(--line);
  border-radius:999px;
  background:#0d1015;
  transition:background 0.16s ease, border-color 0.16s ease;
}

.toggle-slider::before{
  content:"";
  position:absolute;
  top:4px;
  left:4px;
  width:26px;
  height:26px;
  border-radius:50%;
  background:var(--muted);
  transition:transform 0.16s ease, background 0.16s ease;
}

.toggle-switch input:checked + .toggle-slider{
  border-color:rgba(34,197,94,0.65);
  background:rgba(34,197,94,0.24);
}

.toggle-switch input:checked + .toggle-slider::before{
  transform:translateX(28px);
  background:var(--ok);
}

.toggle-switch input:focus-visible + .toggle-slider{
  outline:2px solid var(--accent);
  outline-offset:3px;
}

.mini-btn{
  min-height:36px;
  min-width:auto;
  padding:0 10px;
  font-size:0.82rem;
}

.thumb-list,
.button-list{
  display:grid;
  gap:8px;
  max-height:220px;
  overflow-y:auto;
  padding-right:2px;
}

.thumb-list{
  grid-template-columns:repeat(auto-fill, minmax(56px, 1fr));
}

.image-thumb-card{
  position:relative;
  width:56px;
  height:56px;
}

.image-thumb-btn{
  width:56px;
  height:56px;
  min-height:56px;
  padding:0;
  overflow:hidden;
  border:1px solid var(--line);
  border-radius:8px;
  background:#05070a;
}

.image-thumb-remove{
  position:absolute;
  top:2px;
  right:2px;
  width:22px;
  height:22px;
  min-height:22px;
  padding:0;
  border:0;
  border-radius:999px;
  background:
    rgba(0,0,0,0.88)
    var(--trash-icon-url, url("/src/img/trash.svg")) center / 15px 15px no-repeat;
  filter:
    drop-shadow(0 0 1px rgba(255,255,255,0.7))
    drop-shadow(0 1px 2px rgba(0,0,0,0.8));
}

.image-thumb-btn img{
  display:block;
  width:100%;
  height:100%;
  object-fit:cover;
}

.tts-send-row,
.preset-add-row,
.sfx-row{
  display:grid;
  grid-template-columns:minmax(0,1fr) auto;
  gap:8px;
  margin-bottom:10px;
}

.tts-send-row input,
.preset-add-row input,
.sfx-row input{
  min-height:40px;
}

.sfx-row{
  grid-template-columns:minmax(0,1fr) auto auto;
}

.sfx-stop-hidden{
  display:none !important;
}

.preset-btn{
  min-height:40px;
  width:100%;
  white-space:normal;
  overflow-wrap:anywhere;
  text-align:left;
  padding:9px 10px;
  background:var(--panel-2);
  color:var(--text);
  border:1px solid var(--line);
  font-weight:700;
}

.empty-panel{
  padding:14px 8px;
  color:var(--muted);
  text-align:center;
  font-size:0.9rem;
}

.hidden-compat{
  display:none !important;
}

#sttBox{
  width:100%;
  background:linear-gradient(180deg,#111,#0d0d0d);
  border:1px solid rgba(42,132,255,0.35);
  border-radius:16px;
  padding:14px;
  color:#fff;
  font-family:Arial,sans-serif;
  box-shadow:
    0 0 0 1px rgba(255,255,255,0.03) inset,
    0 8px 24px rgba(0,0,0,0.45);
  overflow:hidden;
}

.stt-feed{
  max-height:0;
  opacity:0;
  overflow:hidden;
  transform:translateY(-4px);
  transition:
    max-height 0.28s ease,
    opacity 0.18s ease,
    transform 0.28s ease,
    margin-top 0.28s ease;
  margin-top:0;
}

.stt-feed.is-open{
  max-height:520px;
  opacity:1;
  transform:translateY(0);
  margin-top:14px;
}

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

.sttTitleWrap{
  display:flex;
  flex-direction:column;
}

.sttTitle{
  font-size:18px;
  font-weight:700;
  color:#58a6ff;
  letter-spacing:0.2px;
}

.sttSubtitle{
  font-size:12px;
  color:#888;
  margin-top:2px;
}

#clearBtn{
  background:linear-gradient(180deg,#2a84ff,#1767d4);
  border:none;
  color:white;
  padding:10px 14px;
  border-radius:10px;
  cursor:pointer;
  font-size:13px;
  font-weight:600;
  transition:
    transform 0.12s ease,
    opacity 0.12s ease,
    box-shadow 0.12s ease;
  box-shadow:0 4px 14px rgba(42,132,255,0.3);
}

#clearBtn:hover{
  transform:translateY(-1px);
  box-shadow:0 6px 18px rgba(42,132,255,0.4);
}

#clearBtn:active{
  transform:scale(0.98);
}

#clearBtn.loading{
  opacity:0.7;
  pointer-events:none;
}

#sttStatus{
  font-size:12px;
  color:#777;
  margin-bottom:10px;
}

#sttLines{
  display:flex;
  flex-direction:column;
  gap:8px;
  max-height:320px;
  overflow-y:auto;
  padding-right:4px;
}

#sttLines::-webkit-scrollbar,
.thumb-list::-webkit-scrollbar,
.button-list::-webkit-scrollbar{
  width:8px;
}

#sttLines::-webkit-scrollbar-thumb,
.thumb-list::-webkit-scrollbar-thumb,
.button-list::-webkit-scrollbar-thumb{
  background:#2a84ff55;
  border-radius:999px;
}

.sttLine{
  background:
    linear-gradient(
      180deg,
      rgba(255,255,255,0.03),
      rgba(255,255,255,0.01)
    );
  border:1px solid rgba(255,255,255,0.05);
  border-left:4px solid #2a84ff;
  border-radius:12px;
  padding:10px;
  animation:fadeIn 0.18s ease;
}

.sttTime{
  color:#6faeff;
  font-size:11px;
  margin-bottom:6px;
  font-family:monospace;
  opacity:0.85;
}

.sttText{
  font-size:14px;
  line-height:1.45;
  word-break:break-word;
  color:#f2f2f2;
}

.sttEmpty{
  color:#777;
  text-align:center;
  padding:18px;
  font-size:13px;
}

@keyframes fadeIn{
  from{
    opacity:0;
    transform:translateY(4px);
  }
  to{
    opacity:1;
    transform:translateY(0);
  }
}

@media (max-width:1180px){
  .image-history-panel{
    width:100%;
    max-height:none;
    margin-top:0;
  }

  .thumb-list{
    display:flex;
    overflow-x:auto;
    overflow-y:hidden;
    max-height:none;
    padding-bottom:2px;
  }

  .image-thumb-btn{
    flex:0 0 auto;
  }
}

@media (max-width:900px){
  .dashboard-grid{
    grid-template-columns:1fr;
  }

  .image-url-panel{
    order:3;
    margin-top:0;
  }

  .image-url-line{
    display:none;
  }

  .face-stack{
    order:2;
  }

  .image-history-panel{
    order:1;
  }
}

@media (max-width:760px){
  .button-list{
    max-height:220px;
  }
}

@media (max-width:600px){
  .tts-send-row,
  .preset-add-row,
  .sfx-row{
    grid-template-columns:1fr;
  }
}

@media (max-width:600px){
  .sttHeader{
    flex-direction:column;
    align-items:stretch;
  }

  #clearBtn{
    width:100%;
  }
}
