:root {
  /* GIGO CAT design system: stage-at-night dark, one golden accent */
  --bg: #120f0a; --paper: #1d1710; --card2: #261f15; --ink: #f5ecda; --muted: #a89a82; --line: #3c3120;
  --accent: #ffc62e; --accent-bg: rgba(255,198,46,.14); --on-accent: #1b1710; --danger: #ff6b6b; --ok: #59d98e;
  --radius: 20px; --font-ui: 'Kanit', 'Noto Sans Thai', system-ui, sans-serif;
}
* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0; color: var(--ink); background: transparent;
  font: 16px/1.6 var(--font-ui);
}
body::before { content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background: radial-gradient(ellipse 900px 480px at 50% -8%, rgba(255,198,46,.08), transparent 60%),
    var(--bg) url('assets/bg-iframe-mobile.png') center top / cover no-repeat; }
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 1.4rem; margin: .8rem 0; font-weight: 600; }
h2 { font-size: 1.15rem; margin: 0; font-weight: 600; }
.muted { color: var(--muted); }
.err { color: var(--danger); }
.sp { flex: 1; }

#nav {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: .9rem;
  padding: .55rem 1rem; background: var(--paper); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 600; color: var(--ink); font-size: 1.1rem; }
main { max-width: 960px; margin: 0 auto; padding: 0 1rem 4rem; }

button, .btn, select, input, textarea {
  font: inherit; color: inherit; background: var(--paper);
  border: 1px solid var(--line); border-radius: 8px; padding: .5rem .8rem; min-height: 44px;
}
button, .btn { cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: .3rem; }
button:hover, .btn:hover { border-color: var(--muted); }
button.on, .on { background: var(--accent-bg); border-color: var(--accent); color: var(--accent); }
button.primary { background: linear-gradient(175deg, #ffd666, var(--accent)); border-color: var(--accent); color: var(--on-accent); font-weight: 700;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.35), 0 4px 14px rgba(255,198,46,.25); }
button.danger, .danger { color: var(--danger); }
button:disabled { opacity: .4; cursor: default; }
button.mini { min-height: 36px; padding: .2rem .7rem; font-size: .9rem; }
input[type=search], .search { width: 100%; }
textarea { width: 100%; resize: vertical; }
label.fld { display: grid; gap: .2rem; margin: .5rem 0; font-size: .9rem; color: var(--muted); }
label.fld input, label.fld select, label.fld textarea { color: var(--ink); }
.row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin: .5rem 0; }
.form { max-width: 560px; margin: 1rem auto; }

.list { display: grid; gap: .5rem; margin-top: 1rem; }
.item {
  display: flex; gap: .8rem; align-items: center; padding: .7rem 1rem; color: var(--ink);
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
}
.item b { font-weight: 600; }
.item small { color: var(--muted); display: block; }
.tag { font-size: .8rem; padding: 0 .5rem; border-radius: 99px; background: var(--accent-bg); color: var(--accent); }

.paper {
  background: var(--paper); border: 1px solid var(--line); border-radius: 12px;
  padding: 1rem 1.1rem; margin: .8rem 0; overflow-x: auto;
}
.titlebar { display: flex; flex-wrap: wrap; align-items: baseline; gap: .3rem 1rem; margin-top: 1rem; }
.titlebar .by { color: var(--muted); }
.tools { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin: .6rem 0; }
.tools .keyname { font-weight: 600; min-width: 3.2rem; text-align: center; }
.source-picker-wrap { display: inline-flex; align-items: center; gap: .35rem; margin-right: .15rem; }
.source-picker-label { color: var(--muted); font-size: .86rem; white-space: nowrap; }
.source-picker { min-height: 36px; max-width: 10.5rem; }

.sheet { line-height: 1.5; }
.sec { margin: 1.2rem 0; }
.sh { font-weight: 600; margin: 0 0 .4rem; }
details.sh > summary { cursor: pointer; padding: .2rem 0; }
.shc { padding: .5rem; border: 1px dashed var(--line); border-radius: 8px; margin: .3rem 0 .6rem; font-weight: 400; }
.ly { display: flex; flex-wrap: nowrap; align-items: flex-end; margin-top: .2rem; }
.seg { display: inline-flex; flex-direction: column; flex: none; }
.cd { color: var(--accent); font-weight: 600; font-size: .88em; padding-right: 0; white-space: pre; min-height: 1.4em; line-height: 1.4; }
.tx { white-space: pre; }
.nochord .cd { display: none; }
.bl { color: var(--accent); font-weight: 600; padding: 0 .2em; }
.bars { display: flex; flex-wrap: wrap; gap: .1rem .5rem; align-items: center; color: var(--accent); font-weight: 600; margin: .2rem 0; }
.bar { display: inline-flex; gap: .5rem; min-width: 1.5rem; padding: .1rem .2rem; border-radius: 6px; }
.bsep { color: var(--muted); font-weight: 400; }
.imported-bars .bar { align-items: center; flex-wrap: nowrap; }
.imported-bars .cd { position: static; min-height: 0; padding: 0 !important; line-height: 1.5; }
.imported-bars .imported-repeat { color: var(--accent); white-space: nowrap; }
.ph { color: var(--muted); font-weight: 400; }

.editing .ch, .editing .cd, .editing .bc, .editing .bar { cursor: pointer; }
.editing .ch { padding: .45em 0; }
.editing .ch.bartext { visibility: hidden; }
.editing .ly { margin-top: .4rem; }
.editing .bar { min-height: 2.2rem; align-items: center; padding: .3rem .4rem; }
.ch.sel, .cd.sel, .bc.sel, .bar.sel { background: var(--accent-bg); outline: 1px solid var(--accent); border-radius: 4px; }
.lc { display: none; gap: .4rem; margin: .2rem 0 .4rem; flex-wrap: wrap; }
.cur > .lc { display: flex; }

.edit-grid { display: block; }
/* แผงคอร์ด = popup ล่างจอ: ซ่อนไว้จนแตะคอร์ดหรือเนื้อเพลง */
.palette {
  position: fixed; left: 50%; bottom: 0; z-index: 30; width: min(100%, 560px);
  transform: translate(-50%, 105%); transition: transform .2s ease, visibility .2s; visibility: hidden;
  background: var(--paper); border-top: 1px solid var(--line); border-radius: 16px 16px 0 0;
  padding: .5rem .8rem calc(.6rem + env(safe-area-inset-bottom));
  max-height: 55vh; overflow: auto; box-shadow: 0 -8px 24px rgba(0,0,0,.45);
}
.palette.open { transform: translate(-50%, 0); visibility: visible; }
.edit-grid.pal-open { padding-bottom: 56vh; }
.pinfo { display: flex; align-items: baseline; gap: .8rem; margin-bottom: .4rem; }
.pinfo .cur { font-size: 1.3rem; font-weight: 600; color: var(--accent); min-width: 4rem; }
.pinfo small { color: var(--muted); }
.chips { display: grid; grid-template-columns: repeat(auto-fill, minmax(58px, 1fr)); gap: 6px; margin-bottom: .5rem; }
.chips button { font-weight: 600; padding: .3rem; }
.mods { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: .5rem; }
.mods button { min-width: 48px; padding: .3rem .6rem; }
.palette details { margin: .3rem 0; }
.palette summary { cursor: pointer; padding: .3rem 0; color: var(--muted); }
.tens { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 6px; }
.tens label { display: flex; align-items: center; gap: .4rem; padding: .3rem .5rem; border: 1px solid var(--line); border-radius: 8px; min-height: 44px; }
.tens input { min-height: 0; width: 1.1rem; height: 1.1rem; }
.suggest { display: grid; gap: .3rem; margin: .3rem 0; }

#toast {
  position: fixed; left: 50%; bottom: 5rem; transform: translateX(-50%); z-index: 20;
  background: var(--ink); color: var(--bg); padding: .5rem 1rem; border-radius: 99px;
  opacity: 0; pointer-events: none; transition: opacity .2s; max-width: 90vw;
}
#toast.show { opacity: 1; }

@media print {
  #nav, .tools, .palette, #toast, .noprint { display: none !important; }
  body { background: #fff; color: #000; }
  .paper { border: 0; padding: 0; }
}

/* lyric line fitting step: a phone-width frame */
.phone { width: 100%; max-width: 390px; margin: .6rem auto; border: 6px solid var(--line); border-radius: 22px; background: var(--paper); padding: .3rem; box-sizing: border-box; }
.fit-ta { display: block; width: 100%; box-sizing: border-box; border: 0; outline: 0; resize: vertical; background: transparent;
  font: 16px/1.5 var(--font-ui); white-space: pre; overflow-x: auto; padding: .4rem .5rem; min-height: 55vh; }
.fit-info { text-align: center; color: var(--muted); font-size: .9rem; margin: .3rem 0; }
.fit-info.bad { color: var(--danger); }

/* ---- GIGO CAT look ---- */
button, .btn { border-radius: 999px; }
button.mini { border-radius: 999px; }
input, select, textarea { border-radius: 10px; background: var(--bg); }
input:focus, textarea:focus, select:focus { outline: 0; border-color: var(--accent); }
#nav { background: rgba(18,15,10,.92); backdrop-filter: blur(8px); }
.brand { display: inline-flex; align-items: center; gap: .5rem; }
.brand img { height: 34px; width: auto; display: block; }
.paper, .item, .palette, .phone { background: linear-gradient(175deg, var(--card2), var(--paper)); box-shadow: inset 0 1px 0 rgba(255,255,255,.05); }
.item { border-radius: 20px; }
.paper { border-radius: 20px; }
.tag { border-radius: 9px; }
.cd { font-weight: 700; }
@media print { body::before { display: none; } .paper, .item { background: #fff; box-shadow: none; } }

/* ---- home ---- */
.hero { display: flex; flex-direction: column; align-items: center; gap: .3rem; text-align: center; padding: 1.2rem 0 .4rem; }
.hero img { width: min(70vw, 280px); height: auto; border-radius: 50%; }
.hero p { margin: 0; color: var(--muted); }
.searchbar { display: flex; align-items: center; gap: .6rem; background: var(--paper); border: 1px solid var(--line);
  border-radius: 999px; padding: 0 1rem; height: 52px; margin: .8rem 0; }
.searchbar input { flex: 1; min-width: 0; border: 0; background: none; height: 100%; padding: 0; min-height: 0; }
.tabs { display: flex; gap: .5rem; overflow-x: auto; padding: .2rem 0 .5rem; scrollbar-width: none; }
.tab { padding: .3rem 1rem; min-height: 40px; border-radius: 9px; white-space: nowrap; font-size: .95rem; }
.tab.on { background: var(--accent); color: var(--on-accent); border-color: var(--accent); font-weight: 600; }
.sec-title { display: flex; align-items: baseline; justify-content: space-between; margin: 1rem 0 .3rem; }
.sec-title h2 { font-size: 1.15rem; }
.feed { display: grid; gap: .6rem; }
.chart-card { display: flex; gap: .8rem; align-items: center; padding: .7rem .9rem; color: var(--ink); }
.chart-card .info { flex: 1; min-width: 0; }
.chart-card .t1 { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chart-card .t2 { color: var(--muted); font-size: .88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chart-card .by { display: inline-flex; align-items: center; gap: .35rem; color: var(--muted); font-size: .85rem; margin-top: .15rem; }
.keybig { flex: none; min-width: 48px; height: 48px; display: grid; place-items: center; font-weight: 800; color: var(--on-accent);
  background: linear-gradient(175deg, #ffd666, var(--accent)); border-radius: 50% 50% 50% 6px; transform: rotate(-8deg); }
.keybig span { transform: rotate(8deg); }
.likebtn { flex: none; min-height: 40px; padding: .1rem .7rem; font-size: .9rem; gap: .3rem; color: var(--muted); }
.likebtn.on { color: var(--danger); border-color: var(--danger); background: rgba(255,107,107,.1); }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--card2); border: 1.5px solid var(--accent); color: var(--accent);
  display: inline-grid; place-items: center; font-size: .8rem; font-weight: 700; object-fit: cover; flex: none; overflow: hidden; }
.avatar.lg { width: 84px; height: 84px; font-size: 2rem; border-width: 2px; }
.empty { text-align: center; padding: 2rem 0; color: var(--muted); }
.empty img { width: 96px; height: auto; opacity: .9; }
.more { margin: 1rem auto; display: flex; }

/* ---- profile ---- */
.profile { padding-top: 1rem; }
.p-head { display: flex; gap: 1rem; align-items: center; }
.p-head h1 { margin: 0; }
.p-stats { display: flex; gap: 1.4rem; margin: 1rem 0; }
.p-stats div { text-align: center; }
.p-stats b { display: block; font-size: 1.25rem; color: var(--accent); }
.p-stats small { color: var(--muted); }
.p-bio { color: var(--ink); white-space: pre-wrap; margin: .3rem 0; }
.inst { display: flex; flex-wrap: wrap; gap: .4rem; margin: .4rem 0; }
.inst .tag { padding: .15rem .7rem; }

/* ---- layout fixes (phone width) ---- */
#nav { gap: .5rem; padding: .4rem .7rem; }
#nav a, #nav button { white-space: nowrap; font-size: .92rem; }
#nav .btn, #nav button { min-height: 36px; padding: .15rem .8rem; }
.brand { font-size: 1rem; flex: none; }
.brand img { height: 30px; }
.feed { grid-template-columns: minmax(0, 1fr); }
.chart-card { min-width: 0; }
.chart-card .likebtn { padding: .1rem .6rem; }

.brand img { border-radius: 50%; }

.brand .crown { color: var(--accent); margin-left: -.25rem; }

/* ปุ่มลบฉบับร่างบนการ์ด */
.chart-card .del-draft { flex: none; padding: .2rem .7rem; }

/* จำนวนรอบเล่นซ้ำท้ายแถวคอร์ด (เช่น ×2) */
.lw .rep { display: inline-block; margin-left: .6rem; font-weight: 600; color: var(--accent); font-size: .95em; }
.lw .ly .rep { flex: none; white-space: nowrap; }
.paper.wrapmode .lw .ly .rep { display: inline; }
.ly .repeat-cue { cursor: inherit; }

/* แสดงใน iframe ของ GIGO CAT (?embed=1): ซ่อนแถบเมนูด้านบน เหลือแต่ใบคอร์ด */
.embed #nav { display: none !important; }
.embed main, .embed #app { padding-top: .6rem; }
/* iframe หน้าคอร์ดใช้พื้นดำล้วน */
html.embed, html.embed body { background: #000 !important; }
html.embed body::before {
  display: none !important;
  background: none !important;
}
/* ให้พื้นของหน้าคอร์ดและแต่ละท่อนโปร่ง เพื่อเห็นพื้นดำล้วน */
html.embed main, html.embed #app, html.embed .paper, html.embed .sheet,
html.embed .sec { background: transparent !important; box-shadow: none !important; }
html.embed .sec.bg0, html.embed .sec.bg1, html.embed .sec.bg2,
html.embed .sec.bg3, html.embed .sec.bg4, html.embed .sec.bg5 {
  background: transparent !important;
}

@media (max-width:600px){.paper{padding:.8rem .6rem}}
.paper,.sheet,.sec,main,#app{min-width:0;max-width:100%}
.cd.pad{padding-right:.4em}
.sheet{width:max-content;min-width:100%}
.sheet:not(.editing) .lw{display:flex;align-items:flex-end}

/* ---- sheet: ฟอนต์/การวางคอร์ดเหมือน busk.town (Bai Jamjuree เนื้อ 500 คอร์ด 700, คอร์ดลอยเหนือเนื้อไม่ดันตัวอักษร) ---- */
.sheet { font-family: 'Bai Jamjuree', 'Kanit', system-ui, sans-serif; font-weight: 500; }
.ly { padding-top: 1.55em; margin-top: .1rem; }
.ly.nochord { padding-top: 0; }
.seg { position: relative; display: inline-block; flex: none; }
.cd { position: absolute; left: 0; top: -1.55em; font-family: 'Bai Jamjuree', sans-serif; font-weight: 700; font-size: 1em; padding: 0 !important; min-height: 0; line-height: 1.5; white-space: pre; }
.cd .bl { padding: 0; }
.bars, .bc, .bar { font-family: 'Bai Jamjuree', sans-serif; font-weight: 700; }
.editing .seg { min-width: 0; }

.cd .bl{padding:0 .27em 0 0 !important}
.bl, .cd .bl { color: #4fc3ff !important; }
.embed .titlebar, .embed .kc:not(.kt) { display: none !important; }
.keyname.kt { min-width: 2.6rem; text-align: center; }
.kc.nk { display: none !important; }
.embed .tools { margin-top: .2rem; }

/* สีหัวข้อท่อนตามชนิด */
.sec .sh { display: inline-block; padding: .05rem .6rem; border-radius: 6px; border-left: 4px solid currentColor; background: color-mix(in srgb, currentColor 14%, transparent); }
.sec.k-intro .sh, .sec.k-outro .sh { color: #9aa4b2; }
.sec.k-verse .sh { color: #6ea8fe; }
.sec.k-prechorus .sh { color: #c58cff; }
.sec.k-chorus .sh { color: #ff8a5c; }
.sec.k-bridge .sh { color: #4fd1a5; }
.sec.k-interlude .sh, .sec.k-solo .sh { color: #f2c94c; }
@media print { .sec .sh { color: #000 !important; background: none; border-left-color: #000; } }

/* ดอกจัน * ** *** **** ***** = เขียว ชมพู แดง ม่วง ส้ม (สว่าง) */
.ch.star { font-weight: 700; }
.ch.s1 { color: #4ade80; } .ch.s2 { color: #ff7ac8; } .ch.s3 { color: #ff5d5d; } .ch.s4 { color: #c58bff; } .ch.s5 { color: #ffa94d; }

/* ซ่อนชื่อท่อน (Verse/Hook ฯลฯ) ตอนอ่าน + บีบระยะห่างบรรทัด */
.sheet:not(.editing) .sec > .sh { margin: 0 0 .15rem; font-size: .9em; }
.sheet:not(.editing) .sec { margin: .55rem 0; }
.sheet { line-height: 1.3; }
.sheet:not(.editing) .ly { padding-top: 1.3em; margin-top: 0; }
.sheet:not(.editing) .ly.nochord { padding-top: 0; }
.sheet:not(.editing) .cd { top: -1.3em; line-height: 1.3; }

/* โหมดฝังใน GIGO CAT: คอร์ดเต็มจอ ไม่มีกรอบซ้าย-ขวา */
.embed main, .embed #app { padding-left: 0 !important; padding-right: 0 !important; max-width: none !important; margin: 0 !important; }
.embed .paper { border: 0 !important; border-radius: 0 !important; background: transparent !important; box-shadow: none !important; padding: .4rem .35rem !important; margin: .2rem 0 !important; }
.embed .tools { padding: 0 .35rem; }

/* เครื่องหมาย * ขยายให้ใหญ่เท่าตัวคอร์ด (ไม่ดันความสูงบรรทัด) */
.ch.star { font-size: 1.7em; line-height: 0; font-weight: 800; vertical-align: -.12em; }

/* โหมดฝัง: แสดงเฉพาะ dropdown เลือก source; ปุ่มควบคุมอื่นให้ GIGO CAT จัดการ */
.embed .tools { display: flex !important; }
.embed .tools > :not(.source-picker-wrap) { display: none !important; }
.embed .source-picker-wrap { display: inline-flex !important; }

/* เว้นช่องว่างระหว่างท่อนให้ชัด */
.sheet:not(.editing) .sec { margin: .55rem 0; }
/* ขีดยาวคั่นระหว่างท่อน (ช่องว่างเท่าเดิม) */
.sheet:not(.editing) .sec + .sec { border-top: 1px solid rgba(255,255,255,.3); padding-top: .55rem; margin-top: .8rem; }
@media print { .sheet:not(.editing) .sec + .sec { border-top-color: #888; } }

/* เส้นกั้นห้องในแถวคอร์ดล้วน (Instrumental/Solo ฯลฯ) = barline ฟ้าสว่าง */
.bsep { color: #4fc3ff !important; font-weight: 700; }

/* ซูมใบคอร์ดแบบจีบนิ้ว (transform) */
.zwrap { position: relative; }
.zwrap.zoomed { overflow: hidden; }
.zwrap.zoomed > .paper { overflow: visible !important; width: 100%; box-sizing: border-box; }

/* ปุ่ม "เนื้อร้องอย่างเดียว" */
.lyrbar { display: flex; justify-content: flex-end; margin: .2rem .35rem; }
.lyrbtn.on { background: var(--accent); color: var(--on-accent, #000); }
.paper.lyronly .cd, .paper.lyronly .bw, .paper.lyronly .sh.rep { display: none !important; }
.paper.lyronly .ly { padding-top: 0 !important; }

/* โหมดตัดบรรทัดอัตโนมัติ (แบบ Dochord): เนื้อร้องจัดกึ่งกลาง ตัดบรรทัดเอง คอร์ดลอยเหนือตำแหน่งตัวอักษร ไม่ต้องเลื่อนซ้าย-ขวา */
.sheet.wm, .paper.wrapmode .sheet:not(.editing) { width: auto !important; min-width: 0 !important; }
.paper.wrapmode .lw, .paper.wrapmode .ly { display: block !important; white-space: normal; text-align: center; line-height: 2.25; padding-top: 0 !important; margin-top: 0 !important; }
.paper.wrapmode .ly.nochord { line-height: 1.6; }
.paper.wrapmode .seg { display: inline !important; position: relative; min-width: 0 !important; }
.paper.wrapmode .tx { display: inline; white-space: pre-wrap !important; overflow-wrap: break-word; }
.paper.wrapmode .seg, .paper.wrapmode .sheet { max-width: 100%; }
.paper.wrapmode .cd { position: absolute; left: 0; top: -.95em; line-height: 1.2; }
.paper.wrapmode .bars { flex-wrap: wrap; justify-content: center; }
.paper.wrapmode .lw .rep { display: inline-block; }
.paper.wrapmode { overflow-x: hidden; }

/* โหมดตัดบรรทัด: เว้นขอบซ้าย-ขวา 1 ซม. (ทั้งใน iframe) */
.paper.wrapmode, .embed .paper.wrapmode { padding-left: 1mm !important; padding-right: 1mm !important; box-sizing: border-box; }

/* คอร์ดที่ต้องยกขึ้นอีกชั้นเพื่อไม่ให้ทับกัน (โหมดตัดบรรทัด) */
.paper.wrapmode .ly.tier2 { line-height: 3.6; }
.paper.wrapmode .cd.up { top: -2.05em; }

/* ตัดบรรทัด = ล็อกการเลื่อนซ้าย-ขวา */
html.nohx, html.nohx body { overflow-x: hidden; max-width: 100%; }

.paper.wrapmode .tx.nb::before { content: "\2060"; }

/* คอร์ดที่เกินท้ายเนื้อ (โหมดตัดบรรทัด) = แถวคอร์ดล้วนใต้บรรทัด */
.paper.wrapmode .tailrow { display: flex; flex-wrap: wrap; justify-content: center; gap: 0 .45em; color: var(--accent); font-weight: 700; line-height: 1.7; margin-top: .1em; }
.paper.wrapmode .tailrow .tc { white-space: pre; }
.paper.wrapmode .cd.tailout { display: none !important; }
.paper.lyronly .tailrow { display: none !important; }

.paper.wrapmode .tailrow { margin-top: -.35em; line-height: 1.5; margin-bottom: .7em; }

/* คอร์ดสูงกว่าเนื้อร้องอีกนิด */
.sheet:not(.editing) .ly { padding-top: 1.5em; }
.sheet:not(.editing) .ly.nochord { padding-top: 0; }
.sheet:not(.editing) .cd { top: -1.5em; }
.paper.wrapmode .lw, .paper.wrapmode .ly { line-height: 2.4; }
.paper.wrapmode .cd { top: -1.2em; }

/* เว้นระยะบรรทัดโหมดตัดบรรทัดเพิ่ม ไม่ให้คอร์ดชิดวรรณยุกต์/สระบนของบรรทัดบน */
.paper.wrapmode .lw, .paper.wrapmode .ly { line-height: 3.2; /* เพิ่มช่อง เนื้อ -> คอร์ดบรรทัดถัดไป ให้สมดุลกับ คอร์ด -> เนื้อ */ }
.paper.wrapmode .ly.nochord { line-height: 1.9; }
.paper.wrapmode .ly.tier2 { line-height: 4; }
.paper.wrapmode .cd { top: -1.3em; }
.paper.wrapmode .cd.up { top: -2.3em; }
.paper.wrapmode .ly:not(.nochord) .tx { position: relative; top: .28em; }

/* โหมดไม่ตัดบรรทัด: บรรทัดเนื้อร้องที่ไม่มีคอร์ด เว้นระยะจากบรรทัดบนให้เท่ากับบรรทัดที่มีคอร์ด (โหมดตัดบรรทัด/เนื้อร้องอย่างเดียวมี !important ของตัวเองอยู่แล้ว) */
.sheet:not(.editing) .ly.nochord { padding-top: .6em; }
.ch.sq { display: none; }

/* โหมดตัดบรรทัด: แยกแต่ละบรรทัดเนื้อเพลงออกจากกันเสมอ
   (ถ้า .ly เป็น inline คอร์ดของบรรทัดถัดไปจะไหลมาต่อกับบรรทัดก่อน
   และทำให้ดูเหมือนมีห้องคอร์ดเพิ่ม ทั้งที่ข้อมูลจริงไม่ได้เพิ่ม) */
.paper.wrapmode .lw { text-align: left; }
.paper.wrapmode .ly { display: block !important; }
.paper.wrapmode .lw .rep { display: inline-block; margin-left: .5rem; white-space: nowrap; }

/* wrap mode: ×N stays on the same line as chord-only (bars) rows */
.paper.wrapmode .lw.bw .bars { display: inline-flex !important; vertical-align: middle; }

/* แถวคอร์ดล้วน (ไม่มีเนื้อร้อง): ลดระยะรอบแถวและระหว่างท่อน ไม่ให้ว่างเกินไป */
.sheet:not(.editing) .sec { margin: .3rem 0; }
.sheet:not(.editing) .sec + .sec { margin-top: .45rem; padding-top: .45rem; }
.sheet:not(.editing) .lw.bw { line-height: 1.4; margin: 0; }
.sheet:not(.editing) .bars { margin: .05rem 0; }
.paper.wrapmode .lw.bw { line-height: 1.4; }
/* แยกแถวคอร์ดล้วนออกจากแถวที่มีเนื้อร้อง ไม่ให้สองแบบติดกันเกินไป */
.sheet:not(.editing) .lw.bw + .lw:not(.bw) { margin-top: .55rem; }

/* iframe บนคอม: เลือก 1 / 2 / 4 คอลัมน์ได้ (บนมือถือเป็นคอลัมน์เดียวเสมอ) */
html.deskframe .sheet:not(.editing) { width: auto; min-width: 0; max-width: 100%; }
html.deskframe.cols2 .sheet:not(.editing) { columns: 2; column-gap: 2.5rem; }
html.deskframe.cols4 .sheet:not(.editing) { columns: 4; column-gap: 1.5rem; }
html.deskframe .sheet:not(.editing) .sec { break-inside: avoid; }

/* คอร์ดที่ถูกไฮไลท์ (แตะเพื่อเปิด/ปิด ซิงค์กับทุกคนที่ดูใบนี้) */
.cd { cursor: pointer; }
.cd.hl { background: rgba(255, 200, 40, .28); box-shadow: 0 0 0 2px rgba(255, 200, 40, .85); border-radius: 4px; }
.bc { cursor: pointer; }
.bc.hl { background: rgba(255, 200, 40, .28); box-shadow: 0 0 0 2px rgba(255, 200, 40, .85); border-radius: 4px; }

/* แถวคอร์ดล้วน: เครื่องหมาย ×2 อยู่ระดับเดียวกับคอร์ด ไม่ตกลงบรรทัดใหม่ (โหมดไม่ตัดบรรทัด) */
.sheet:not(.editing) .lw.bw { display: block; }
.sheet:not(.editing) .lw.bw .bars { display: inline-flex; vertical-align: middle; max-width: 100%; }

/* ปุ่มเครื่องมือของบรรทัดในโหมดแก้ไข: เล็กลง (ปุ่ม +ห้อง / +แถว / ช่องซ้ำ ×n) */
.lc button.mini { min-height: 28px; padding: .1rem .55rem; font-size: .78rem; }
.lc label.fld { margin: 0; font-size: .78rem; gap: .1rem; }
.lc label.fld input { min-height: 28px; width: 3.6rem; padding: .1rem .35rem; font-size: .85rem; }

/* กดค้างที่เนื้อเพลง/คอร์ดแล้วไม่ให้เลือกคำ (ไม่ให้ขึ้นกรอบฟ้า/พจนานุกรม); ช่องกรอกยังพิมพ์ได้ */
.paper, .paper .sheet { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.paper input, .paper textarea { -webkit-user-select: text; user-select: text; }

/* ห้องคอร์ด: ไม่ให้คอร์ดในห้องเดียวกันบีบจนซ้อนทับกัน (ตัดบรรทัดได้ระหว่างห้อง/คอร์ด แทน) */
.bars, .bar { flex-wrap: wrap; }
.bar > .bc, .bar > .bhead, .bars > .bar { flex-shrink: 0; }
.bhead { display: inline-flex; flex-wrap: nowrap; align-items: center; gap: .5rem; }
.lw.bw .bar .rep { margin-left: 0; white-space: nowrap; }
.bc { white-space: nowrap; }

/* พื้นหลังแต่ละท่อนต่างสี (สลับ 6 สี วนซ้ำ) ให้เห็นขอบเขตท่อนชัด */
.sec { border-radius: 12px; padding: .45rem .6rem; }
.sec.bg0 { background: rgba(110,168,254,.12); }
.sec.bg1 { background: rgba(79,209,165,.12); }
.sec.bg2 { background: rgba(255,138,92,.12); }
.sec.bg3 { background: rgba(197,140,255,.12); }
.sec.bg4 { background: rgba(242,201,76,.12); }
.sec.bg5 { background: rgba(255,107,107,.12); }
.paper.wrapmode .sheet:not(.editing) .sec { padding-top: 1.1rem !important; padding-left: 0 !important; padding-right: 0 !important; }
@media print { .sec { background: none !important; } }

/* โหมดตัดบรรทัด: ชิดซ้ายแทนกึ่งกลาง */
.paper.wrapmode .lw, .paper.wrapmode .ly { text-align: left; }
.paper.wrapmode .bars { justify-content: flex-start; }
.paper.wrapmode .tailrow { justify-content: flex-start; }

/* ทุกโหมด: เนื้อเพลง คอร์ด และห้องคอร์ดชิดซ้ายเสมอ */
.sheet, .sheet .sec, .sheet .lw, .sheet .ly, .sheet .tailrow { text-align: left !important; }
.sheet .bars, .sheet .tailrow, .sheet .lw, .sheet .ly { justify-content: flex-start !important; }
.paper.wrapmode .lw, .paper.wrapmode .ly { text-align: left !important; }

/* แถบปุ่มด้านบนของหน้าดูคอร์ด: เตี้ยลง ตัวอักษรไม่ตัดขึ้นบรรทัดใหม่ */
.lyrbar { flex-wrap: wrap; gap: .3rem; }
.lyrbar button { min-height: 30px; padding: .1rem .55rem; font-size: .8rem; line-height: 1.2; white-space: nowrap; }

/* ---------- Shared visual polish for all GigoChord screens ---------- */
:root {
  --bg: #100f0c;
  --paper: #191815;
  --card2: #211f19;
  --ink: #f7f3e9;
  --muted: #aaa393;
  --line: #373329;
  --accent: #ffd04a;
  --accent-bg: rgba(255,208,74,.14);
  --radius: 18px;
  --ui-ease: cubic-bezier(.2,.7,.25,1);
}
body::before {
  background: radial-gradient(ellipse 760px 420px at 50% -12%,rgba(255,208,74,.11),transparent 68%),
    radial-gradient(ellipse 560px 360px at 100% 55%,rgba(255,106,61,.035),transparent 72%),
    var(--bg) url('assets/bg-iframe-mobile.png') center top / cover no-repeat;
}
#nav {
  background: rgba(16,15,12,.88);
  border-bottom-color: rgba(255,255,255,.1);
  box-shadow: 0 8px 24px rgba(0,0,0,.14);
  backdrop-filter: blur(14px);
}
main { padding-top: .4rem; }
.brand { letter-spacing: -.02em; }
h1,h2 { letter-spacing: -.02em; line-height: 1.25; }
.paper,.item,.palette,.phone {
  background: linear-gradient(155deg,rgba(255,255,255,.035),transparent 42%),var(--paper);
  border-color: rgba(255,255,255,.09);
  box-shadow: 0 8px 24px rgba(0,0,0,.16),inset 0 1px 0 rgba(255,255,255,.035);
}
.item { gap: .9rem; padding: .8rem 1rem; transition: transform .16s var(--ui-ease),border-color .16s var(--ui-ease),background .16s var(--ui-ease); }
.paper { border-radius: 18px; }
button,.btn,select,input,textarea {
  border-color: rgba(255,255,255,.13);
  transition: transform .16s var(--ui-ease),border-color .16s var(--ui-ease),box-shadow .16s var(--ui-ease),background .16s var(--ui-ease);
}
button.primary {
  background: linear-gradient(180deg,#ffdf82,var(--accent));
  box-shadow: 0 6px 18px rgba(255,198,46,.2),inset 0 1px 0 rgba(255,255,255,.5);
}
input,select,textarea { background: rgba(8,8,7,.58); }
input:focus,textarea:focus,select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255,208,74,.12);
}
.searchbar {
  height: 56px;
  background: rgba(255,255,255,.035);
  border-color: rgba(255,255,255,.12);
  box-shadow: inset 0 1px 2px rgba(0,0,0,.18);
}
.tab { transition: background .16s var(--ui-ease),color .16s var(--ui-ease),border-color .16s var(--ui-ease); }
.tab:not(.on) { background: rgba(255,255,255,.025); }
.chart-card {
  border-color: rgba(255,255,255,.085);
  box-shadow: 0 6px 18px rgba(0,0,0,.14),inset 0 1px 0 rgba(255,255,255,.025);
}
.keybig { box-shadow: 0 5px 14px rgba(255,198,46,.2); }
.tag { padding: .12rem .65rem; }
.palette {
  border-color: rgba(255,255,255,.1);
  box-shadow: 0 -14px 40px rgba(0,0,0,.32);
  padding-top: .8rem;
}
#toast { box-shadow: 0 8px 28px rgba(0,0,0,.35); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
@media (hover:hover) {
  button:not(:disabled):hover,.btn:not(:disabled):hover { transform: translateY(-1px); border-color: rgba(255,208,74,.42); }
  button.primary:not(:disabled):hover { box-shadow: 0 9px 24px rgba(255,198,46,.28),inset 0 1px 0 rgba(255,255,255,.5); }
  .item:hover { transform: translateY(-1px); border-color: rgba(255,208,74,.28); }
}
@media (max-width:600px) {
  #nav { gap: .35rem; padding: .45rem .55rem; }
  #nav a,#nav button { font-size: .88rem; }
  main { padding-left: .85rem; padding-right: .85rem; }
}
@media (prefers-reduced-motion:reduce) {
  *,*::before,*::after { scroll-behavior: auto!important; animation-duration: .01ms!important; animation-iteration-count: 1!important; transition-duration: .01ms!important; }
}

/* Responsive app shell: comfortable reading width on large screens and
   predictable, touch friendly layouts on tablets and phones. */
html { scroll-padding-top: 5rem; }
body { min-width: 320px; overflow-x: hidden; }
#nav {
  min-height: 58px;
  padding-inline: max(1rem, calc((100vw - 1180px) / 2));
  gap: .65rem;
}
#nav > a:not(.brand), #nav > button { flex: none; min-height: 42px; padding-inline: .9rem; }
#nav .sp { min-width: .25rem; }
main { width: min(100%, 1180px); padding: .8rem clamp(1rem, 3vw, 2rem) 5rem; }
.hero { padding: clamp(1.4rem, 4vw, 3rem) 0 1rem; }
.hero img { width: clamp(150px, 22vw, 250px); }
.hero h1 { font-size: clamp(1.6rem, 3.2vw, 2.4rem); }
.searchbar { width: min(100%, 760px); margin: 1rem auto; }
.tabs { border-bottom: 1px solid var(--line); }
.feed { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .85rem; }
.chart-card { min-height: 92px; }
.chart-card .t1, .chart-card .t2 { overflow-wrap: anywhere; }
.form { width: min(100%, 620px); }
.profile { max-width: 840px; margin-inline: auto; }
.paper { padding: clamp(1rem, 2.5vw, 1.6rem); }
.tools { align-items: center; }
button, .btn, select { touch-action: manipulation; }
img, video, canvas { max-width: 100%; }

@media (max-width: 760px) {
  #nav {
    position: sticky;
    gap: .4rem;
    padding: .4rem .65rem;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
  }
  #nav::-webkit-scrollbar, .tabs::-webkit-scrollbar { display: none; }
  #nav .brand { position: sticky; left: 0; z-index: 1; padding: .15rem .25rem .15rem 0; background: rgba(16,15,12,.96); }
  #nav > a:not(.brand), #nav > button { min-height: 42px; padding-inline: .75rem; }
  main { padding: .6rem 1rem calc(4rem + env(safe-area-inset-bottom)); }
  .feed { grid-template-columns: minmax(0, 1fr); }
  .chart-card { padding: .75rem; gap: .65rem; }
  .keybig { min-width: 44px; height: 44px; }
  .p-head { align-items: flex-start; }
  .p-stats { justify-content: space-around; gap: .5rem; }
  .titlebar { align-items: flex-start; flex-direction: column; gap: .15rem; }
  .tools { gap: .4rem; }
  .tools button, .tools .btn, .tools select { min-height: 42px; }
}

@media (max-width: 480px) {
  body { font-size: 15px; }
  #nav .brand { font-size: .95rem; }
  #nav .brand img { height: 28px; }
  #nav > a:not(.brand), #nav > button { font-size: .85rem; }
  main { padding-inline: .75rem; }
  h1 { font-size: 1.3rem; }
  .hero { padding-top: 1rem; }
  .hero img { width: 144px; }
  .searchbar { height: 50px; padding-inline: .85rem; }
  .tab { padding-inline: .8rem; }
  .chart-card .by { max-width: 100%; }
  .chart-card .likebtn { min-width: 42px; }
  .paper { padding: .8rem .65rem; border-radius: 15px; }
  .row > * { max-width: 100%; }
  .row > h1 { flex-basis: 100%; }
  .palette { max-height: 68dvh; }
  .edit-grid.pal-open { padding-bottom: 70dvh; }
  .fit-ta { min-height: 48vh; font-size: 16px; }
}

@media (min-width: 1200px) {
  .feed { gap: 1rem; }
  .chart-card { padding: .95rem 1.1rem; }
}

/* หน้าดูคอร์ด: เนื้อเพลงชิดขอบจอซ้ายขวา (ยกเลิกระยะขอบของกรอบและของหน้า) */
.paper.edge { margin: .4rem -1rem; padding: 0; border: 0; border-radius: 0; overflow-x: hidden; }
/* หน้าดูคอร์ด: ขยายกรอบเนื้อเพลงให้เต็มความกว้างจอพอดี ไม่ขึ้นกับระยะขอบของหน้าแม่ */
.paper.edge { width: 100vw; max-width: none; margin: .4rem calc(50% - 50vw); }
/* 100vw รวม scrollbar ใน Edge/Chrome ทำให้กรอบล้ำซ้ายประมาณครึ่ง scrollbar
   ชดเชยกรณี desktop เพื่อไม่ตัดคอร์ด/เนื้อร้องตัวแรก */
@media (min-width: 700px) {
  .paper.edge { width: calc(100vw - 15px); margin-left: calc(50% - 50vw + 8px); margin-right: 0; }
}

/* หน้าแรก: รายการเพลงแบบแถวเรียบ มีเส้นคั่น ค้นหาอยู่บนสุด (สไตล์เว็บคอร์ดทั่วไป) */
.feed { display: flex; flex-direction: column; border-top: 1px solid var(--line); }
.feed .chart-card { border: 0; border-bottom: 1px solid var(--line); border-radius: 0; background: transparent; box-shadow: none; padding: .7rem .2rem; gap: .75rem; }
.feed .chart-card .t1 { font-size: 1.02rem; font-weight: 600; }
.feed .chart-card .t2 { font-size: .9rem; color: var(--muted); }
.feed .chart-card:hover { background: var(--accent-bg); }
.feed .chart-card .keybig { width: 44px; height: 44px; min-width: 44px; border-radius: 6px; font-size: .95rem; }
.searchbar { margin-top: .6rem; }

/* หน้าแรก: หัวข้อแบบแถบสีข้าง, แท็บเป็นปุ่มเม็ด, รายการเลขลำดับ + ศิลปินอยู่บรรทัดบน */
.sechead { font-size: 1.05rem; font-weight: 500; margin: 1rem 0 .6rem; padding: .45rem .8rem; background: var(--paper); border-left: 4px solid var(--accent); border-radius: 0 6px 6px 0; }
.tabs { padding: .2rem 0 .6rem; }
.tabs .tab { border-radius: 8px; border: 1px solid var(--line); background: transparent; min-height: 40px; }
.tabs .tab.on { background: var(--accent); color: var(--on-accent); border-color: var(--accent); font-weight: 600; }
.feed { counter-reset: fnum; }
.feed .chart-card { counter-increment: fnum; }
.feed .chart-card::before { content: counter(fnum); flex: none; width: 1.4rem; text-align: center; font-weight: 700; color: var(--accent); }
.feed .chart-card .info { display: flex; flex-direction: column; }
.feed .chart-card .t2 { order: -1; color: var(--accent); font-weight: 700; font-size: .92rem; }
.feed .chart-card .t1 { font-size: 1rem; font-weight: 500; color: var(--ink); }
.feed .chart-card .by { order: 2; }

/* ชุดควบคุม Auto Scroll ลอยแนวตั้งอยู่มุมขวาบนของจอ */
.asfloat-panel { position: fixed; top: .6rem; right: .6rem; z-index: 50; display: flex; flex-direction: column; align-items: center; gap: .22rem; padding: 0; border-radius: 14px; background: transparent; box-shadow: none; backdrop-filter: none; }
.asfloat-panel.open { padding: 0; background: transparent; box-shadow: none; backdrop-filter: none; }
.asfloat-panel .as-menu-btn { width: 44px; height: 44px; min-height: 44px; padding: 0; margin: 0; font-size: 1.2rem; background: transparent !important; border-color: transparent !important; box-shadow: none !important; }
.asfloat-controls { display: none; flex-direction: column; align-items: center; gap: .22rem; }
.asfloat-panel.open .asfloat-controls { display: flex; padding: .25rem; border-radius: 14px; background: rgba(18,18,18,.78); box-shadow: 0 4px 14px rgba(0,0,0,.45); backdrop-filter: blur(5px); }
.asfloat-controls .mini { min-width: 40px; min-height: 34px; padding: .2rem .45rem; margin: 0; }

/* แถบปุ่มชิดซ้าย เว้นที่มุมขวาให้ปุ่มเล่นลอยอยู่ */
.lyrbar { justify-content: flex-start; padding-right: 3.6rem; }
.asfloat-panel .asicon { width: 44px; height: 44px; min-height: 44px; padding: 0; font-size: 1.05rem; margin-bottom: .18rem; }

/* ---- หน้าแรก: ล่าสุด / ยอดนิยม 7 วัน / สุ่ม ---- */
.home-sec{display:grid;gap:1.1rem;margin:.6rem 0 .4rem}
.home-sec[hidden]{display:none!important}
.home-block .sec-title{display:flex;justify-content:space-between;align-items:center;gap:.5rem}
.hscroll{display:grid;grid-auto-flow:column;grid-auto-columns:minmax(230px,82%);gap:.6rem;overflow-x:auto;padding-bottom:.4rem;scroll-snap-type:x mandatory}
.hscroll > .item{scroll-snap-align:start;min-width:0}
@media (min-width:900px){
  .hscroll{grid-auto-flow:row;grid-template-columns:repeat(auto-fill,minmax(260px,1fr));overflow:visible}
}

/* The local Stage pad keeps even the first and last chord in reach of center. */
.pad-follow-frame { padding-block: 50vh; }
.pad-follow .pad-current { color: #15120a; background: #ffd458; outline: 2px solid #ffd458; border-radius: 3px; }

.pad-follow [data-pad-chord] { cursor: pointer; }
/* Keep positioned chords above wrapped lyrics so the visible label receives the tap. */
.pad-follow .cd[data-pad-chord] { z-index: 1; }
.pad-follow .pad-queued { outline: 2px dashed #ffd458; outline-offset: 1px; border-radius: 3px; }
