*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Lock screen ── */

#lock-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: #0f0f13;
}

.lock-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 48px 40px;
  background: #16161e;
  border: 1px solid #2a2a35;
  border-radius: 16px;
  width: 320px;
}

.lock-icon {
  width: 36px;
  height: 36px;
  color: #666;
  margin-bottom: 4px;
}

.lock-box input {
  width: 100%;
  padding: 12px 16px;
  background: #1e1e28;
  border: 1px solid #2a2a35;
  border-radius: 8px;
  color: #e0e0e6;
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s;
}

.lock-box input:focus {
  border-color: #888;
}

.lock-box input::placeholder {
  color: #555;
}

.lock-box button {
  width: 100%;
  padding: 12px;
  background: #e0e0e6;
  border: none;
  border-radius: 8px;
  color: #0f0f13;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.lock-box button:hover {
  background: #fff;
}

.lock-box button:active {
  background: #ccc;
}

#lock-error {
  font-size: 13px;
  color: #f87171;
  min-height: 18px;
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: #0f0f13;
  color: #e0e0e6;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-bottom: env(safe-area-inset-bottom);
}

header {
  padding: 16px 24px;
  border-bottom: 1px solid #2a2a35;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

header h1 {
  font-size: 24px;
  font-weight: 600;
  color: #f0f0f5;
}

#status {
  font-size: 13px;
  color: #888;
}

.toggle-btn {
  font-size: 13px;
  padding: 5px 12px;
  background: #1e1e28;
  border: 1px solid #2a2a35;
  border-radius: 6px;
  color: #999;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.toggle-btn:hover {
  background: #252535;
  color: #ccc;
}

.danger-btn {
  border-color: #8b3a3a;
  color: #e07070;
}

.danger-btn:hover {
  background: #2a1a1a;
  border-color: #c05050;
  color: #f09090;
}

.toggle-btn.active {
  background: #2a2a35;
  border-color: #e0e0e6;
  color: #e0e0e6;
}

.main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.lyrics-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.resize-handle {
  width: 5px;
  flex-shrink: 0;
  cursor: col-resize;
  background: #2a2a35;
  transition: background 0.15s;
}

.resize-handle:hover,
.resize-handle.active {
  background: #e0e0e6;
}

.lyrics-area {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

.syllable-gutter {
  display: none;
  flex-direction: column;
  padding: 20px 0;
  width: 44px;
  flex-shrink: 0;
  border-right: 1px solid #1e1e28;
  overflow-y: hidden;
  user-select: none;
}

.syllable-gutter.visible {
  display: flex;
}

.syllable-gutter .syl-line {
  font-family: -apple-system, 'SF Pro Text', 'Helvetica Neue', 'Segoe UI', system-ui, sans-serif;
  font-size: 24px;
  line-height: 1.7;
  text-align: center;
  color: #e0e0e6;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

.syllable-gutter .syl-line.empty-line {
  color: transparent;
}

.rhyme-scheme-gutter {
  display: none;
  flex-direction: column;
  padding: 20px 0;
  width: 44px;
  flex-shrink: 0;
  border-left: 1px solid #1e1e28;
  overflow-y: hidden;
  user-select: none;
}

.rhyme-scheme-gutter.visible {
  display: flex;
}

.rhyme-scheme-gutter .scheme-line {
  font-family: -apple-system, 'SF Pro Text', 'Helvetica Neue', 'Segoe UI', system-ui, sans-serif;
  font-size: 24px;
  line-height: 1.7;
  text-align: center;
  font-weight: 600;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

.rhyme-scheme-gutter .scheme-line.empty-line {
  color: transparent;
}

.panel-header {
  padding: 12px 20px;
  font-size: 13px;
  font-weight: 600;
  color: #999;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid #1e1e28;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

#lyrics-panel-title {
  cursor: text;
  border-radius: 3px;
  padding: 1px 4px;
  outline: none;
  min-width: 40px;
}

#lyrics-panel-title:hover {
  background: #1e1e28;
}

#lyrics-panel-title:focus {
  background: #1e1e28;
  box-shadow: 0 0 0 1px #2a2a35;
}

.lyrics-wrapper {
  position: relative;
  flex: 1;
  min-width: 0;
}

#lyrics-highlight {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  padding: 20px;
  font-family: -apple-system, 'SF Pro Text', 'Helvetica Neue', 'Segoe UI', system-ui, sans-serif;
  font-size: 24px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-wrap: break-word;
  color: transparent;
  pointer-events: none;
  overflow: hidden;
}

#line-measure {
  position: absolute;
  visibility: hidden;
  pointer-events: none;
  white-space: pre-wrap;
  word-wrap: break-word;
  font-family: -apple-system, 'SF Pro Text', 'Helvetica Neue', 'Segoe UI', system-ui, sans-serif;
  font-size: 24px;
  line-height: 1.7;
  padding: 0 20px;
}

#lyrics-highlight .highlight-word {
  background: rgba(224, 224, 230, 0.2);
  border-radius: 4px;
}

#lyrics {
  position: relative;
  width: 100%;
  height: 100%;
  padding: 20px;
  background: transparent;
  border: none;
  color: #e0e0e6;
  font-family: -apple-system, 'SF Pro Text', 'Helvetica Neue', 'Segoe UI', system-ui, sans-serif;
  font-size: 24px;
  line-height: 1.7;
  resize: none;
  outline: none;
}

#lyrics::-webkit-scrollbar {
  display: none;
}

#lyrics {
  scrollbar-width: none;
}

#lyrics::placeholder {
  color: #555;
}

.rhymes-panel {
  width: 380px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.selected-word-bar {
  padding: 12px 20px;
  border-bottom: 1px solid #1e1e28;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.context-line {
  width: 100%;
  font-size: 13px;
  color: #666;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 2px;
}

.context-line:empty {
  display: none;
}

@keyframes word-flash {
  0% { background: rgba(224, 224, 230, 0.15); }
  100% { background: transparent; }
}

.selected-word-bar.flash {
  animation: word-flash 0.4s ease-out;
}

.selected-word-bar .label {
  font-size: 13px;
  color: #999;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}

.selected-word-bar .word {
  font-size: 16px;
  font-weight: 700;
  color: #e0e0e6;
}

#rhyme-results {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

#rhyme-results::-webkit-scrollbar {
  width: 6px;
}

#rhyme-results::-webkit-scrollbar-track {
  background: transparent;
}

#rhyme-results::-webkit-scrollbar-thumb {
  background: #333;
  border-radius: 3px;
}

.rhyme-group {
  margin-bottom: 4px;
}

.rhyme-group-header {
  padding: 10px 20px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  user-select: none;
  transition: background 0.15s;
}

.rhyme-group-header:hover {
  background: #1a1a24;
}

.rhyme-group-header .name {
  display: flex;
  align-items: center;
  gap: 8px;
}

.rhyme-group-header .count {
  font-size: 11px;
  color: #666;
  background: #1e1e28;
  padding: 2px 8px;
  border-radius: 10px;
}

.rhyme-group-header .chevron {
  font-size: 10px;
  color: #666;
  transition: transform 0.2s;
}

.rhyme-group.open .chevron {
  transform: rotate(90deg);
}

.rhyme-group-body {
  display: none;
  padding: 4px 20px 12px;
  flex-wrap: wrap;
  gap: 6px;
}

.rhyme-group.open .rhyme-group-body {
  display: flex;
}

.rhyme-word {
  font-size: 13px;
  padding: 4px 10px;
  background: #1a1a24;
  border-radius: 4px;
  cursor: default;
  transition: background 0.15s;
}

.rhyme-word {
  cursor: pointer;
}

.rhyme-word:hover {
  background: #252535;
}

/* ── Definition popup (desktop) ── */

.def-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
}

.def-popup {
  position: fixed;
  z-index: 101;
  width: 320px;
  max-height: 280px;
  overflow-y: auto;
  background: #1a1a24;
  border: 1px solid #2a2a35;
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.def-popup::-webkit-scrollbar {
  width: 5px;
}

.def-popup::-webkit-scrollbar-thumb {
  background: #333;
  border-radius: 3px;
}

.def-word {
  font-size: 18px;
  font-weight: 700;
  color: #f0f0f5;
  margin-bottom: 4px;
}

.def-phonetic {
  font-size: 13px;
  color: #888;
  margin-bottom: 12px;
}

.def-pos {
  font-size: 12px;
  font-weight: 600;
  color: #e0e0e6;
  text-transform: italic;
  margin-top: 10px;
  margin-bottom: 4px;
}

.def-meaning {
  font-size: 13px;
  color: #ccc;
  line-height: 1.5;
  margin-bottom: 4px;
  padding-left: 10px;
  border-left: 2px solid #2a2a35;
}

.def-example {
  font-size: 12px;
  color: #777;
  font-style: italic;
  padding-left: 10px;
  margin-bottom: 8px;
}

.def-loading {
  font-size: 13px;
  color: #888;
  text-align: center;
  padding: 20px 0;
}

.def-error {
  font-size: 13px;
  color: #666;
  text-align: center;
  padding: 20px 0;
}

/* ── Definition bottom sheet (mobile) ── */

@media (max-width: 768px) {
  .def-overlay {
    background: rgba(0, 0, 0, 0.5);
  }

  .def-popup {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-height: 50vh;
    border-radius: 16px 16px 0 0;
    border: none;
    border-top: 1px solid #2a2a35;
    padding: 20px 16px;
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
  }

  .def-popup::before {
    content: '';
    display: block;
    width: 36px;
    height: 4px;
    background: #444;
    border-radius: 2px;
    margin: 0 auto 14px;
  }
}

.color-perfect { color: #4ade80; }
.color-family { color: #60a5fa; }
.color-additive { color: #facc15; }
.color-subtractive { color: #fb923c; }
.color-assonance { color: #f472b6; }
.color-consonance { color: #a78bfa; }

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.dot-perfect { background: #4ade80; }
.dot-family { background: #60a5fa; }
.dot-additive { background: #facc15; }
.dot-subtractive { background: #fb923c; }
.dot-assonance { background: #f472b6; }
.dot-consonance { background: #a78bfa; }

.show-more-btn {
  width: 100%;
  padding: 10px;
  margin-top: 8px;
  background: #1e1e28;
  border: 1px solid #2a2a35;
  border-radius: 6px;
  color: #e0e0e6;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s;
}

.show-more-btn:hover {
  background: #252535;
}

.no-rhymes {
  display: block;
  padding: 8px 0;
  color: #555;
  font-size: 13px;
  font-style: italic;
}

.empty-state {
  padding: 40px 20px;
  text-align: center;
  color: #555;
  font-size: 14px;
  line-height: 1.6;
}

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: #666;
  font-size: 14px;
}

.description {
  font-size: 11px;
  color: #666;
  padding: 2px 20px 8px;
  font-style: italic;
  display: none;
}

.rhyme-group.open .description {
  display: block;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

#user-area {
  display: flex;
  align-items: center;
  gap: 8px;
}

#user-email {
  font-size: 13px;
  color: #888;
}

/* ── Lyrics list overlay ── */

#lyrics-list-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 100;
  align-items: flex-start;
  justify-content: flex-start;
}

#lyrics-list-overlay.open {
  display: flex;
}

#lyrics-list-panel {
  background: #13131a;
  border-right: 1px solid #2a2a35;
  width: 320px;
  max-width: 90vw;
  height: 100%;
  display: flex;
  flex-direction: column;
}

#lyrics-list-panel-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px;
  border-bottom: 1px solid #2a2a35;
  font-size: 15px;
  font-weight: 600;
  color: #f0f0f5;
}

#lyrics-list-panel-header span {
  flex: 1;
}

#lyrics-list-items {
  flex: 1;
  overflow-y: auto;
}

.lyrics-list-item {
  padding: 12px 16px;
  border-bottom: 1px solid #1e1e28;
  cursor: pointer;
  transition: background 0.1s;
}

.lyrics-list-item:hover {
  background: #1a1a24;
}

.lyrics-list-item.active {
  background: #1e1e2e;
  border-left: 2px solid #e0e0e6;
}

.lyrics-list-item-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 6px;
}

.lyrics-list-title {
  font-size: 14px;
  color: #e0e0e6;
}

.lyrics-list-date {
  font-size: 12px;
  color: #666;
}

.lyrics-list-actions {
  display: flex;
  gap: 6px;
}

.lyrics-action-btn {
  font-size: 11px;
  padding: 3px 8px;
  background: #1e1e28;
  border: 1px solid #2a2a35;
  border-radius: 4px;
  color: #888;
  cursor: pointer;
}

.lyrics-action-btn:hover {
  background: #252535;
  color: #ccc;
}

.lyrics-delete-btn:hover {
  border-color: #8b3a3a;
  color: #e07070;
}

.lyrics-list-empty {
  padding: 32px 16px;
  color: #666;
  font-size: 14px;
  text-align: center;
}

.icon-btn {
  background: none;
  border: none;
  color: #888;
  font-size: 18px;
  cursor: pointer;
  padding: 2px 6px;
  line-height: 1;
}

.icon-btn:hover {
  color: #ccc;
}

#save-indicator {
  font-size: 12px;
  color: #666;
  margin-left: 8px;
  font-weight: 400;
}

/* ── Mobile tabs (hidden on desktop) ── */

.mobile-tabs {
  display: none;
}

/* ── Mobile layout ── */

@media (max-width: 768px) {
  header {
    padding: 10px 16px;
    gap: 6px;
    flex-wrap: wrap;
    padding-top: calc(10px + env(safe-area-inset-top));
  }

  header h1 {
    font-size: 17px;
    width: 100%;
  }

  .toggle-btn {
    font-size: 12px;
    padding: 6px 10px;
  }

  #status {
    display: none;
  }

  .mobile-tabs {
    display: flex;
    border-bottom: 1px solid #2a2a35;
    flex-shrink: 0;
  }

  .mobile-tab {
    flex: 1;
    padding: 10px;
    font-size: 14px;
    font-weight: 600;
    text-align: center;
    background: transparent;
    border: none;
    color: #666;
    cursor: pointer;
    transition: all 0.2s;
    border-bottom: 2px solid transparent;
    min-height: 44px;
  }

  .mobile-tab.active {
    color: #e0e0e6;
    border-bottom-color: #e0e0e6;
  }

  .main {
    flex-direction: column;
  }

  .lyrics-panel,
  .rhymes-panel {
    transition: opacity 0.15s ease;
  }

  .lyrics-panel {
    flex: 1;
    min-height: 0;
  }

  .panel-header {
    display: none;
  }

  .resize-handle {
    display: none;
  }

  .rhymes-panel {
    width: 100% !important;
    flex: 1;
    min-height: 0;
  }

  /* Tab switching */
  .main.show-lyrics .lyrics-panel {
    display: flex;
    flex: 1;
  }

  .main.show-lyrics .rhymes-panel {
    display: none;
  }

  .main.show-rhymes .lyrics-panel {
    display: none;
  }

  .main.show-rhymes .rhymes-panel {
    display: flex;
    flex: 1;
  }

  /* Textarea adjustments */
  #lyrics {
    font-size: 18px;
    padding: 16px;
  }

  #lyrics-highlight {
    font-size: 18px;
    padding: 16px;
  }

  .syllable-gutter .syl-line {
    font-size: 18px;
  }

  .rhyme-scheme-gutter .scheme-line {
    font-size: 18px;
  }

  #line-measure {
    font-size: 18px;
    padding: 0 16px;
  }

  /* Rhyme results adjustments */
  .selected-word-bar {
    padding: 14px 16px;
    background: #16161e;
  }

  .selected-word-bar .word {
    font-size: 20px;
  }

  .rhyme-group-header {
    padding: 10px 16px;
    min-height: 44px;
    display: flex;
    align-items: center;
  }

  .rhyme-group-body {
    padding: 4px 16px 12px;
    gap: 8px;
  }

  .rhyme-word {
    font-size: 15px;
    padding: 10px 14px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }

  .description {
    padding: 2px 16px 8px;
  }

  .empty-state {
    padding: 30px 16px;
  }

  .lock-box input {
    font-size: 16px;
  }
}
