/* =============================================================================
   GSi Gemini Editor – Web edition · application shell
   ============================================================================= */
:root {
  --bg: #0c0d0f;
  --bg-2: #141518;
  --panel: #1a1b1f;
  --panel-2: #222328;
  --line: #2c2e34;
  --line-2: #3a3c44;
  --text: #ece9e2;
  --text-2: #a6a39c;
  --text-3: #6d6b66;
  --accent: #ff8f3a;
  --accent-2: #ffb26b;
  --ok: #5fd27a;
  --danger: #e5484d;
  --radius: 8px;
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-display: 'Rajdhani', 'Inter', system-ui, sans-serif;
  --font-lcd: 'VT323', ui-monospace, monospace;
  --topbar-h: 60px;
  --bottombar-h: 76px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased; overflow: hidden;
}
#app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
button { font: inherit; color: inherit; }
a { color: var(--accent-2); }
[hidden] { display: none !important; }

/* ---------------------------------------------------------------- Top bar */
.topbar {
  height: var(--topbar-h); flex: none; display: flex; align-items: center; gap: 18px; padding: 0 16px;
  background: linear-gradient(#18191c, #111214); border-bottom: 1px solid #000; box-shadow: 0 1px 0 #26282d;
}
.brand { display: flex; align-items: center; gap: 10px; flex: none; }
.brand-icon { width: 34px; height: 34px; border-radius: 8px; }
.brand-text { display: flex; flex-direction: column; line-height: .9; font-family: var(--font-display); }
.brand-gemini { font-weight: 700; font-size: 22px; letter-spacing: .14em; }
.brand-editor { font-weight: 600; font-size: 11px; letter-spacing: .5em; color: var(--text-2); }

.tabs { display: flex; gap: 2px; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  background: none; border: 0; padding: 10px 14px; cursor: pointer; white-space: nowrap;
  font-family: var(--font-display); font-weight: 600; font-size: 15px; letter-spacing: .06em; text-transform: uppercase;
  color: var(--text-2); border-radius: 6px; position: relative;
}
.tabs button:hover { color: var(--text); background: #1f2024; }
.tabs button.is-active { color: var(--text); }
.tabs button.is-active::after { content: ''; position: absolute; left: 12px; right: 12px; bottom: 2px; height: 2px; background: var(--accent); border-radius: 2px; box-shadow: 0 0 10px var(--accent); }

.conn { display: flex; align-items: center; gap: 10px; flex: none; }
.conn-led { width: 10px; height: 10px; border-radius: 50%; background: #3b2222; box-shadow: inset 0 1px 2px #000; }
.conn-led.is-ok { background: var(--ok); box-shadow: 0 0 10px var(--ok); }
.conn-led.is-busy { background: var(--accent); box-shadow: 0 0 10px var(--accent); animation: blink .7s infinite alternate; }
.conn-led.is-off { background: #6b2a2a; }
@keyframes blink { to { opacity: .35; } }
.conn-text { color: var(--text-2); font-size: 13px; max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.refresh-bar { height: 2px; background: transparent; flex: none; }
.refresh-bar i { display: block; height: 100%; width: 0; background: var(--accent); opacity: 0; transition: width .1s, opacity .3s; }
.refresh-bar.is-active i { opacity: 1; }

/* ---------------------------------------------------------------- Buttons & inputs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 36px; padding: 0 14px;
  border-radius: 7px; border: 1px solid #000; cursor: pointer; white-space: nowrap;
  background: linear-gradient(#3a3c43, #2a2c31); color: var(--text);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.08), 0 1px 2px rgba(0,0,0,.5);
  font-family: var(--font-display); font-weight: 600; font-size: 14px; letter-spacing: .05em; text-transform: uppercase;
}
.btn:hover { background: linear-gradient(#45474f, #31333a); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: default; }
.btn-primary { background: linear-gradient(#ffa253, #f07a1f); color: #1a0f05; border-color: #6b3208; }
.btn-primary:hover { background: linear-gradient(#ffb06b, #f48a33); }
.btn-ghost { background: transparent; border-color: var(--line-2); box-shadow: none; }
.btn-ghost:hover { background: #24262b; }
.btn-danger { background: linear-gradient(#e8585c, #c73b40); border-color: #4d1214; }
.btn-icon { padding: 0 8px; background: transparent; border-color: transparent; box-shadow: none; color: var(--text-2); }
.btn-icon:hover { color: var(--text); background: #24262b; }
.btn-icon img { width: 26px; height: 26px; object-fit: contain; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

input[type=text], input[type=number], input[type=search], select {
  background: #0f1012; color: var(--text); border: 1px solid var(--line-2); border-radius: 6px; padding: 8px 10px; font: inherit; min-height: 36px;
}
input:focus, select:focus { border-color: var(--accent); outline: none; }
.search { min-width: 180px; }

/* ---------------------------------------------------------------- Pages */
#pages { flex: 1; min-height: 0; position: relative; }
.page {
  position: absolute; inset: 0; overflow: auto; padding: 16px 18px 28px; display: none;
  background: radial-gradient(1200px 500px at 50% -10%, #1b1c20 0%, transparent 60%), var(--bg);
}
.page.is-active { display: block; animation: pageIn .18s ease-out; }
@keyframes pageIn { from { opacity: 0; transform: translateY(4px); } }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 18px; margin-bottom: 14px; }
.tb-group { display: flex; gap: 6px; align-items: center; }
.tb-label { color: var(--text-3); font-family: var(--font-display); font-weight: 600; letter-spacing: .1em; text-transform: uppercase; font-size: 12px; }
.tb-title { font-family: var(--font-display); font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--text-2); }
.toolbar .search { margin-left: auto; }

.page-head { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 14px; margin: 0 0 14px; }
.ph-title { font-family: var(--font-display); font-weight: 700; font-size: 24px; letter-spacing: .04em; }
.ph-sub { color: var(--accent-2); font-weight: 500; }
.ph-hint { margin-left: auto; color: var(--text-3); font-size: 12px; }

.empty { display: grid; place-items: center; text-align: center; padding: 40px 16px; color: var(--text-2); gap: 10px; }
.empty-splash { width: min(520px, 90%); border-radius: 12px; opacity: .9; box-shadow: 0 20px 60px rgba(0,0,0,.6); }
.empty-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

/* Presets */
.preset-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px; }
.preset-card {
  display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; gap: 2px 8px; text-align: left;
  padding: 9px 10px; min-height: 62px; border-radius: 8px; cursor: pointer;
  background: linear-gradient(#26282d, #1d1e22); border: 1px solid #0a0a0b; box-shadow: inset 0 1px 0 rgba(255,255,255,.05);
}
.preset-card:hover { background: linear-gradient(#2e3036, #232529); }
.pc-num { grid-row: span 2; font-family: var(--font-lcd); font-size: 22px; color: var(--text-3); line-height: 1; padding-top: 2px; }
.pc-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pc-desc { font-size: 12px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preset-card.is-active { background: linear-gradient(#fbf7ef, #e6e0d3); color: #141414; border-color: #fff; box-shadow: 0 0 0 2px var(--accent), 0 0 18px rgba(255,143,58,.35); }
.preset-card.is-active .pc-num { color: var(--accent); }
.preset-card.is-active .pc-desc { color: #555; }

/* Sounds */
.sound-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; }
.sound-card {
  display: grid; grid-template-columns: 64px 1fr; grid-template-rows: auto auto; align-items: center; gap: 0 12px; text-align: left;
  padding: 8px; border-radius: 10px; cursor: pointer; background: linear-gradient(#25272c, #1b1c20); border: 1px solid #0a0a0b;
}
.sound-card img { grid-row: span 2; width: 64px; height: 64px; object-fit: contain; border-radius: 50%; background: #fff; padding: 5px; }
.sc-name { font-weight: 600; align-self: end; }
.sc-engine { font-size: 12px; color: var(--text-2); align-self: start; }
.sound-card:hover { background: linear-gradient(#2e3036, #232529); }
.sound-card.is-active { background: linear-gradient(#fbf7ef, #e6e0d3); color: #141414; box-shadow: 0 0 0 2px var(--accent), 0 0 18px rgba(255,143,58,.35); }
.sound-card.is-active .sc-engine { color: #555; }

/* Globals */
.globals { display: grid; grid-template-columns: minmax(320px, 1fr) minmax(360px, 1.1fr); gap: 16px; align-items: start; }
.globals-col { display: grid; gap: 14px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; display: grid; gap: 10px; }
.card h3 { margin: 0; font-family: var(--font-display); font-weight: 700; letter-spacing: .08em; text-transform: uppercase; font-size: 15px; color: var(--accent-2); }
.card label { display: grid; gap: 4px; color: var(--text-2); font-size: 13px; }
.card-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.card-head { display: flex; align-items: center; gap: 10px; justify-content: space-between; }
.inline { display: flex; align-items: center; gap: 8px; }
.inline input { width: 90px; }
.btn-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.hint { margin: 0; color: var(--text-3); font-size: 12px; }
.warn { margin: 0; color: #ffcf8a; background: #3a2a10; border: 1px solid #6a4a16; padding: 8px 10px; border-radius: 6px; }
label.check { display: flex !important; align-items: center; gap: 8px; color: var(--text); cursor: pointer; }
label.check input { width: 18px; height: 18px; accent-color: var(--accent); }
dl.info { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; margin: 0; }
dl.info dt { color: var(--text-3); }
dl.info dd { margin: 0; font-family: ui-monospace, monospace; font-size: 13px; }

.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 8px; max-height: 50vh; }
.table-wrap.tall { max-height: calc(100vh - 330px); min-height: 240px; }
.table { width: 100%; border-collapse: collapse; }
.table th { position: sticky; top: 0; background: #222328; text-align: left; padding: 8px 10px; font-family: var(--font-display); letter-spacing: .06em; text-transform: uppercase; font-size: 13px; color: var(--text-2); z-index: 1; }
.table td { padding: 5px 10px; border-top: 1px solid #222; }
.table tr:hover td { background: #1d1f23; }
.table tr.is-sel td { background: #3b2a18; }
.midimap td:last-child { width: 90px; }
.cc-input { width: 74px; min-height: 30px !important; padding: 4px 8px !important; }
.cc-input.is-off { color: var(--text-3); }

/* Help */
.help { max-width: 860px; margin: 0 auto; color: #d8d5ce; }
.help h1 { font-family: var(--font-display); font-size: 30px; margin: 0 0 8px; }
.help h1 small { font-size: 14px; color: var(--text-3); margin-left: 8px; }
.help h2 { font-family: var(--font-display); color: var(--accent-2); letter-spacing: .06em; text-transform: uppercase; font-size: 18px; margin: 26px 0 6px; }
.help h3 { margin: 16px 0 4px; }
.help .foot { margin-top: 30px; color: var(--text-3); font-size: 13px; }

/* ---------------------------------------------------------------- Bottom bar */
.bottombar {
  flex: none; height: var(--bottombar-h); display: flex; align-items: center; gap: 16px; padding: 0 16px;
  background: linear-gradient(#141518, #0d0e10); border-top: 1px solid #26282d;
}
.dsp-switch { display: flex; gap: 8px; }
.dsp-btn { width: 58px; height: 58px; padding: 0; border-radius: 10px; border: 1px solid #000; background: #1c1d21; cursor: pointer; opacity: .45; transition: opacity .15s, box-shadow .15s; }
.dsp-btn img { width: 100%; height: 100%; }
.dsp-btn:hover { opacity: .75; }
.dsp-btn.is-active { opacity: 1; box-shadow: 0 0 0 2px var(--accent), 0 0 18px rgba(255,143,58,.45); }
.now { flex: 1; min-width: 0; font-family: var(--font-lcd); background: #0b1410; border: 1px solid #000; border-radius: 6px; padding: 6px 12px; color: #9df0b5;
  box-shadow: inset 0 2px 8px rgba(0,0,0,.8); text-shadow: 0 0 6px rgba(120,255,160,.35); }
.now-preset { font-size: 22px; line-height: 1.05; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.now-sound { font-size: 17px; color: #6fbf88; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------------------------------------------------------------- Keyboard drawer */
.kbd-drawer { flex: none; background: #0e0f11; border-top: 1px solid #26282d; padding: 8px 12px 12px; }
.kbd-ctrl { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.kbd-oct { font-family: var(--font-lcd); font-size: 22px; min-width: 34px; text-align: center; color: var(--accent-2); }
.kbd-vel { display: flex; align-items: center; gap: 8px; color: var(--text-2); margin-left: 12px; }
.kbd-vel input { accent-color: var(--accent); }
.kbd-keys { display: flex; height: 120px; position: relative; user-select: none; touch-action: none; }
.kbd-key { position: relative; cursor: pointer; }
.kbd-key.is-white { flex: 1; background: linear-gradient(#f4f1ea, #dcd8cf); border: 1px solid #555; border-radius: 0 0 5px 5px; margin: 0 1px 0 0; }
.kbd-key.is-white span { position: absolute; bottom: 4px; left: 0; right: 0; text-align: center; font-size: 10px; color: #777; }
.kbd-key.is-black { width: 0; z-index: 2; }
.kbd-key.is-black::before { content: ''; position: absolute; left: -9px; width: 18px; height: 72px; background: linear-gradient(#333, #0b0b0b); border-radius: 0 0 3px 3px; box-shadow: 0 2px 3px rgba(0,0,0,.6); }
.kbd-key.is-white.is-down { background: linear-gradient(#ffcf9f, #ffb06b); }
.kbd-key.is-black.is-down::before { background: linear-gradient(#a85a1a, #6b3208); }

/* ---------------------------------------------------------------- Modals */
.scrim { position: fixed; inset: 0; background: rgba(5,5,6,.66); display: grid; place-items: center; padding: 16px; z-index: 100; opacity: 0; transition: opacity .15s; backdrop-filter: blur(3px); }
.scrim.is-open { opacity: 1; }
.modal { position: relative; width: min(520px, 100%); max-height: calc(100vh - 32px); overflow: auto; background: #1d1e22; border: 1px solid #34363d; border-radius: 14px; box-shadow: 0 30px 80px rgba(0,0,0,.7); transform: translateY(6px) scale(.985); transition: transform .15s; }
.scrim.is-open .modal { transform: none; }
.modal-title { padding: 14px 18px 0; font-family: var(--font-display); font-weight: 700; font-size: 19px; letter-spacing: .05em; text-transform: uppercase; }
.modal-body { padding: 12px 18px; }
.modal-buttons { display: flex; justify-content: flex-end; gap: 8px; padding: 0 18px 16px; align-items: center; }
.modal-body .modal-buttons { padding: 12px 0 0; }
.spacer { flex: 1; }
.dlg-msg p { margin: 0 0 6px; white-space: pre-wrap; }
.dlg-error { border-color: #7a2326; background: linear-gradient(#3a1416, #241012); }
.dlg-error .modal-title { color: #ff8d90; }
.dlg-autoclose { position: absolute; top: 0; left: 0; height: 3px; width: 100%; background: var(--accent); animation: autoclose 5s linear forwards; border-radius: 14px 14px 0 0; }
@keyframes autoclose { to { width: 0; } }
.dlg-wait .modal-body { display: flex; gap: 16px; align-items: center; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid #333; border-top-color: var(--accent); animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.prog-msg { margin-bottom: 10px; color: var(--text-2); }
.prog-bar { height: 8px; background: #0e0f11; border-radius: 4px; overflow: hidden; border: 1px solid #000; }
.prog-bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #f07a1f, #ffb26b); transition: width .1s; }

.form { display: grid; gap: 12px; }
.form label { display: grid; gap: 4px; color: var(--text-2); font-size: 13px; }
.form fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; display: grid; gap: 8px; }
.form legend { font-family: var(--font-display); font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--accent-2); padding: 0 4px; }
.setup-modal { width: min(640px, 100%); }
.midi-log { margin: 0; height: 160px; overflow: auto; background: #08090a; border: 1px solid #000; border-radius: 6px; padding: 8px; font-size: 11px; color: #8fd6a2; white-space: pre; }
.cloud-modal { width: min(760px, 100%); }
.cloud-modal .search { width: 100%; margin-bottom: 8px; }
.cloud-info { margin-top: 8px; color: var(--text-2); font-size: 13px; min-height: 20px; }
.files-modal { width: min(560px, 100%); }
.file-list { display: grid; gap: 6px; max-height: 60vh; overflow: auto; }
.file-item { text-align: left; padding: 12px 14px; border-radius: 8px; border: 1px solid var(--line); background: #24262b; cursor: pointer; font-size: 15px; }
.file-item:hover { background: #2e3036; border-color: var(--accent); }

.ctl-edit-pop { position: fixed; z-index: 200; background: #1d1e22; border: 1px solid var(--accent); border-radius: 8px; padding: 8px; display: grid; gap: 4px; width: 160px; box-shadow: 0 10px 30px rgba(0,0,0,.6); }
.ctl-edit-pop label { font-size: 12px; color: var(--text-2); }

/* ---------------------------------------------------------------- Responsive */
@media (max-width: 1100px) {
  .globals { grid-template-columns: 1fr; }
  .table-wrap.tall { max-height: 60vh; }
  .ph-hint { display: none; }
}
@media (max-width: 760px) {
  :root { --topbar-h: auto; }
  .topbar { flex-wrap: wrap; padding: 8px 12px; gap: 8px; }
  .tabs { order: 3; flex-basis: 100%; }
  .tabs button { padding: 8px 10px; font-size: 14px; }
  .conn { margin-left: auto; }
  .conn-text { display: none; }
  .card-row { grid-template-columns: 1fr; }
  .page { padding: 12px; }
  .toolbar .search { margin-left: 0; width: 100%; }
  .dsp-btn { width: 48px; height: 48px; }
  .kbd-keys { height: 96px; }
  #btnKeyboard { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
