:root {
  --bg-color: #121212;
  --surface-color: #1e1e1e;
  --text-color: #e0e0e0;
  --primary: #bb86fc;
  --border: #333;
  --gap: 6px;
  --rowh: 100px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  background-color: var(--bg-color);
  color: var(--text-color);
  font-family: 'Inter', system-ui, sans-serif;
  margin: 0;
  padding: 20px;
}
#app-container { max-width: 1200px; margin: 0 auto; }
.top-links { margin: 6px 12px; }
.top-links a { color: #9ab; }
.phone-only { display: none; }

/* LOGIN */
#room-access-section { max-width: 400px; margin: 60px auto; text-align: center; background: var(--surface-color); padding: 30px; border-radius: 12px; }
.login-form input { display: block; width: 100%; padding: 10px; margin: 10px 0; background: #2c2c2c; border: 1px solid var(--border); color: white; border-radius: 4px; font: inherit; }

/* ROOM */
#chord-room-section { display: none; }
body.in-room #chord-room-section { display: flex; flex-direction: column; }
.room-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; gap: 10px; }
.room-header h2 { margin: 0; font-size: 1.2rem; }
.header-controls { display: flex; gap: 10px; align-items: center; }
.main-layout { display: flex; flex-direction: column; flex: 1; min-height: 0; }

.controls-bar { display: flex; gap: 16px; background: var(--surface-color); padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; flex-wrap: wrap; align-items: flex-end; }
.control-group { display: flex; flex-direction: column; min-width: 0; }
.control-group label { font-size: .7rem; color: #888; margin-bottom: 3px; letter-spacing: .06em; }
.inline-pair { display: flex; gap: 6px; }
select { padding: 7px 6px; background: #333; color: white; border: 1px solid #555; border-radius: 6px; min-width: 150px; font: inherit; font-size: .9rem; max-width: 100%; }
button { font: inherit; }
.chat-input-row button, .login-buttons button, .header-controls button, .icon-btn, #add-row-btn, .toggle-btn { padding: 8px 14px; background: #333; color: white; border: 1px solid #555; border-radius: 6px; cursor: pointer; }
.toggle-btn[aria-pressed="true"] { background: var(--primary); color: #000; border-color: var(--primary); font-weight: 700; }

/* mode switches */
.edit-only { display: none; }
body.mode-edit .edit-only { display: flex; }
body.mode-edit .perf-only { display: none; }

/* CHORD GRID: 4 x 4, rows are 4 measures each */
#chord-grid-wrapper {
  background: var(--surface-color);
  padding: 8px;
  border-radius: 10px;
  overflow-y: auto;
  scroll-snap-type: y mandatory;
  overscroll-behavior: contain;
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
}
#chord-grid-container { display: block; }
.chord-row {
  display: grid;
  grid-template-columns: 26px 1fr;
  gap: 4px;
  height: var(--rowh);
  margin-bottom: var(--gap);
  scroll-snap-align: start;
  border-radius: 8px;
}
.chord-row:last-child { margin-bottom: 0; }
.row-gutter { display: flex; align-items: center; justify-content: center; font: 700 11px/1 Inter, sans-serif; color: #6a6a78; }
.hl-badge { width: 22px; height: 22px; border-radius: 50%; background: var(--hl-color, #fff); color: #000; display: grid; place-items: center; font-weight: 800; font-size: 12px; }
.row-del { width: 26px; height: 34px; padding: 0; border: 1px solid #555; background: #2a2a2a; border-radius: 6px; font-size: 13px; cursor: pointer; }
.row-cells { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; height: 100%; }

.chord-cell {
  position: relative;
  display: grid;
  min-width: 0;
  background: #0b0b10;
  border: 1.5px solid #2b2b36;
  border-radius: 9px;
  overflow: hidden;
  color: #fff;
}
.chord-cell.n1 { grid-template-columns: 1fr; }
.chord-cell.n2 { grid-template-columns: 1fr 1fr; }
.chord-cell.n3, .chord-cell.n4 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.chord-cell.n3 .slot:first-child { grid-row: 1 / 3; }
.slot { display: flex; flex-direction: column; align-items: center; justify-content: center; min-width: 0; min-height: 0; line-height: 1; box-shadow: inset 0 0 0 .5px #33333f; }
.slot .nt { font-weight: 800; letter-spacing: -.02em; }
.slot .ty { font-weight: 600; color: #b9a6e8; margin-top: .12em; }
.slot.blank .nt { color: #3b3b48; font-weight: 400; }
.slot.blank .ty { display: none; }

body.mode-highlight .chord-row { cursor: pointer; }
body.mode-highlight .chord-row:hover .chord-cell { border-color: #44445a; }
body.mode-edit .chord-cell { cursor: pointer; border-style: dashed; border-color: #4b4b66; }
body.mode-edit .chord-cell:hover { background: #17172a; }
body.mode-edit .chord-cell:focus-visible { outline: 3px solid var(--primary); }

/* highlighted rows (the section of music in use) */
.chord-row.highlighted .chord-cell { border-color: var(--hl-color, #fff); border-style: solid; background: color-mix(in srgb, var(--hl-color, #fff) 16%, #0b0b10); box-shadow: 0 0 12px color-mix(in srgb, var(--hl-color, #fff) 55%, transparent); }

/* participants / chat */
.participant-tag { display: inline-block; padding: 4px 8px; margin: 2px; border-radius: 4px; font-size: .8rem; color: #000; font-weight: bold; }
.bottom-panel { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-top: 16px; }
#chat-messages { height: 180px; overflow-y: auto; background: var(--surface-color); border: 1px solid var(--border); border-radius: 6px; padding: 8px; font-size: .9rem; word-break: break-word; }
.chat-msg { margin-bottom: 4px; }
.chat-input-row { display: flex; gap: 8px; margin-top: 8px; }
.chat-input-row input { flex: 1; min-width: 0; padding: 8px; background: #2c2c2c; border: 1px solid var(--border); color: white; border-radius: 4px; font: inherit; }
.login-buttons { display: flex; gap: 10px; }
.login-buttons button { flex: 1; }
.error-message { color: #ff8a8a; min-height: 1.2em; }
#toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: #2a2a38; border: 1px solid #55558a; color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 80; font-size: .9rem; max-width: 90vw; }

/* chord editor sheet */
#sheet-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); z-index: 60; }
#chord-editor { position: fixed; left: 0; right: 0; bottom: 0; margin: 0 auto; max-width: 560px; z-index: 61; background: #1b1b24; border: 1px solid #44445a; border-bottom: 0; border-radius: 18px 18px 0 0; padding: 12px 14px calc(14px + env(safe-area-inset-bottom)); max-height: 88dvh; overflow-y: auto; box-shadow: 0 -10px 40px rgba(0, 0, 0, .6); }
.ed-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; font-size: 1.05rem; }
.ed-x { width: 36px; height: 36px; border-radius: 50%; border: 1px solid #55558a; background: #2a2a38; color: #fff; font-size: 20px; cursor: pointer; padding: 0; }
.ed-label { font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; color: #9a9ab8; margin: 10px 0 5px; }
.ed-hint { text-transform: none; letter-spacing: 0; color: #77778f; }
.ed-grid { display: grid; gap: 6px; }
.ed-grid.notes { grid-template-columns: repeat(7, 1fr); }
.ed-grid.types { grid-template-columns: repeat(5, 1fr); }
.ed-grid button, .ed-split button, .ed-parts button { min-height: 44px; border-radius: 9px; border: 1px solid #4b4b66; background: #2a2a38; color: #fff; font-weight: 600; cursor: pointer; padding: 0 4px; }
.ed-grid button.on, .ed-split button.on, .ed-parts button.on { background: var(--primary); color: #000; border-color: var(--primary); }
.ed-split, .ed-parts { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.ed-parts { margin: 4px 0 2px; }
.ed-done { width: 100%; margin-top: 14px; min-height: 48px; border-radius: 10px; border: 0; background: var(--primary); color: #000; font-weight: 800; font-size: 1rem; cursor: pointer; }

/* PHONES: the room screen is one full-height screen, the 4 x 4 grid fills what is left */
@media (max-width: 700px) {
  body { padding: 0; }
  body.in-room { height: 100dvh; overflow: hidden; }
  body.in-room .top-links { display: none; }
  body.in-room #app-container { height: 100dvh; max-width: none; }
  body.in-room #chord-room-section { height: 100dvh; padding: calc(6px + env(safe-area-inset-top)) 8px calc(8px + env(safe-area-inset-bottom)); }
  .phone-only { display: inline-block; }
  .room-header { margin-bottom: 6px; }
  .room-header h2 { font-size: 1rem; }
  #user-identity { display: none; }
  .controls-bar { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 8px; padding: 8px; margin-bottom: 8px; }
  .control-group label { font-size: .62rem; margin-bottom: 2px; }
  select { min-width: 0; width: 100%; font-size: .85rem; padding: 6px 4px; }
  .inline-pair select { flex: 1; }
  .toggle-btn, #add-row-btn { width: 100%; padding: 6px 8px; }
  body.mode-edit .edit-only { display: flex; }
  #chord-grid-wrapper { flex: 1 1 auto; min-height: 0; max-width: none; padding: 6px; }
  .chord-row { grid-template-columns: 22px 1fr; gap: 3px; }
  .row-cells { gap: 3px; }
  .bottom-panel { position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; display: none; grid-template-columns: 1fr; gap: 10px; margin: 0; max-height: 64dvh; overflow-y: auto; background: #17171c; border-top: 2px solid var(--primary); border-radius: 16px 16px 0 0; padding: 14px 12px calc(14px + env(safe-area-inset-bottom)); }
  body.show-chat .bottom-panel { display: grid; }
  .panel-x { position: absolute; top: 6px; right: 8px; width: 34px; height: 34px; border-radius: 50%; border: 1px solid #55558a; background: #2a2a38; color: #fff; font-size: 20px; padding: 0; }
  #chat-messages { height: 120px; }
}

/* split-measure layouts (chord changes on beats 2, 3 or 4) */
.slot .nt { font-size: calc(var(--rowh) * var(--fs, .36)); }
.slot .ty { font-size: max(8px, calc(var(--rowh) * var(--ts, .15))); }
.chord-cell.n3 .slot:first-child { grid-row: 1 / 3; }
.chord-cell.n3b .slot:nth-child(1) { grid-column: 1; grid-row: 1; }
.chord-cell.n3b .slot:nth-child(2) { grid-column: 1; grid-row: 2; }
.chord-cell.n3b .slot:nth-child(3) { grid-column: 2; grid-row: 1 / 3; }
.chord-cell.n3c { grid-template-columns: 1fr; grid-template-rows: 1.2fr 1.6fr 1.2fr; }
.chord-cell.n3c .slot { flex-direction: row; gap: .35em; align-items: baseline; padding-top: .25em; }
.chord-cell.n3c .slot .ty { margin: 0; }
.chord-cell.n3c .slot:first-child { grid-row: auto; }

/* import / export dialogs */
#modal-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .6); z-index: 70; }
.modal { position: fixed; z-index: 71; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(640px, calc(100vw - 20px)); max-height: calc(100dvh - 24px); overflow-y: auto; background: #1b1b24; border: 1px solid #44445a; border-radius: 16px; padding: 14px 16px calc(16px + env(safe-area-inset-bottom)); box-shadow: 0 20px 60px rgba(0, 0, 0, .7); }
.modal.readme { z-index: 72; }
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 8px; font-size: 1.1rem; }
.modal h3 { margin: 16px 0 4px; font-size: 1rem; color: #cbb8ff; }
.modal p { margin: 6px 0; line-height: 1.5; font-size: .95rem; }
.modal code { background: #2a2a38; border-radius: 4px; padding: 1px 5px; font-family: ui-monospace, Consolas, monospace; font-size: .92em; color: #fff; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; align-items: center; }
.tabs button { padding: 8px 16px; border-radius: 9px; border: 1px solid #4b4b66; background: #2a2a38; color: #fff; font-weight: 600; cursor: pointer; }
.tabs button.on { background: var(--primary); color: #000; border-color: var(--primary); }
.tabs .link-btn { margin-left: auto; background: none; border: 0; color: #9ab8ff; text-decoration: underline; font-weight: 400; padding: 8px 4px; }
.m-note { color: #b8b8d0; }
.m-warn { background: #3a2f12; border: 1px solid #8a6a1a; color: #ffe29a; padding: 10px 12px; border-radius: 10px; }
.m-warn button { margin-top: 6px; padding: 6px 12px; border-radius: 8px; border: 1px solid #c9a23a; background: #4a3c14; color: #fff; cursor: pointer; display: block; }
.m-row { display: flex; flex-direction: column; gap: 4px; margin: 10px 0; }
.m-row label { font-size: .78rem; letter-spacing: .05em; text-transform: uppercase; color: #9a9ab8; }
.modal select, .modal input[type="text"], .modal textarea, .modal input[type="file"] { width: 100%; max-width: none; min-width: 0; padding: 9px; background: #2a2a38; color: #fff; border: 1px solid #4b4b66; border-radius: 8px; font: inherit; }
.modal textarea { font-family: ui-monospace, Consolas, monospace; font-size: .85rem; resize: vertical; }
.modal fieldset { border: 1px solid #3a3a4c; border-radius: 10px; margin: 10px 0; padding: 8px 12px; }
.modal legend { font-size: .78rem; letter-spacing: .05em; text-transform: uppercase; color: #9a9ab8; padding: 0 6px; }
.opt { display: flex; gap: 8px; align-items: center; padding: 5px 0; cursor: pointer; }
.im-preview { background: #12121a; border: 1px solid #33334a; border-radius: 10px; padding: 10px 12px; font-size: .9rem; color: #c8c8dc; }
.im-sum { margin: 0 0 6px; color: #fff; }
.im-song { font-weight: 700; margin: 8px 0 4px; }
.im-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.im-grid div { background: #1d1d2a; border: 1px solid #33334a; border-radius: 6px; padding: 6px 4px; text-align: center; font-family: ui-monospace, Consolas, monospace; font-size: .8rem; overflow-wrap: anywhere; }
.im-grid div.empty { color: #55556a; }
.im-more { color: #8a8aa8; font-size: .8rem; margin-top: 4px; }
.im-warn { margin: 8px 0; padding-left: 20px; color: #ffcf8a; font-size: .85rem; }
.im-warn:empty { display: none; }
.ed-done:disabled { opacity: .4; cursor: not-allowed; }
.rd-table { width: 100%; border-collapse: collapse; margin: 6px 0 10px; font-size: .9rem; }
.rd-table th { text-align: left; color: #9a9ab8; font-size: .75rem; letter-spacing: .05em; text-transform: uppercase; border-bottom: 1px solid #3a3a4c; padding: 5px 6px; }
.rd-table td { border-bottom: 1px solid #2a2a38; padding: 6px; vertical-align: top; }
.rd-cells td { text-align: center; border: 1px solid #3a3a4c; min-width: 36px; height: 34px; font-family: ui-monospace, Consolas, monospace; }
.rd-cells td:nth-child(4n+1) { border-left: 3px solid var(--primary); }
.rd-btns { display: flex; flex-wrap: wrap; gap: 8px; }
.rd-btns button { padding: 9px 12px; border-radius: 9px; border: 1px solid #4b4b66; background: #2a2a38; color: #fff; cursor: pointer; }
.lbl-short { display: none; }
@media (max-width: 700px) {
  .lbl-long { display: none; }
  .lbl-short { display: inline; }
  .modal { top: auto; bottom: 0; transform: translateX(-50%); border-radius: 16px 16px 0 0; width: 100vw; max-height: 92dvh; }
}

.ed-split button { display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.15; }
.ed-split .mk { font: 800 1rem ui-monospace, Consolas, monospace; letter-spacing: .02em; }
.ed-split .bt { font-size: .72rem; font-weight: 600; opacity: .85; }

