/* Liryc — minimal stylesheet */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  /* Prevent iOS from auto-scaling text in landscape. */
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  background: #1a1a1a;
  color: #e0e0e0;
  min-height: 100vh;
}

/* ── App shell ──────────────────────────────────────────────────────────── */
.app {
  display: flex;
  flex-direction: column;
  /* dvh tracks the *visible* viewport, so the mobile URL bar can't clip the app. */
  height: 100vh;
  height: 100dvh;
}

.app__main {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 2rem;
  /* Respect notch / home-indicator safe areas on phones. */
  padding-left: max(2rem, env(safe-area-inset-left));
  padding-right: max(2rem, env(safe-area-inset-right));
  padding-bottom: max(1rem, env(safe-area-inset-bottom));
}

/* ── Toolbar ────────────────────────────────────────────────────────────── */
.toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  padding: 0.5rem 1rem;
  padding-top: max(0.5rem, env(safe-area-inset-top));
  background: #111;
  border-bottom: 1px solid #333;
  position: sticky;
  top: 0;
  z-index: 50;
}

.toolbar__title {
  font-weight: 600;
  font-size: 1rem;
  flex: 1 1 100%;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toolbar__modes,
.toolbar__actions {
  display: flex;
  gap: 0.4rem;
}

.toolbar__mode-btn {
  padding: 0.25rem 0.75rem;
  border: 1px solid #555;
  background: transparent;
  color: #ccc;
  border-radius: 4px;
  cursor: pointer;
}

.toolbar__mode-btn.active {
  background: #444;
  color: #fff;
  border-color: #888;
}

button {
  padding: 0.25rem 0.6rem;
  background: #2a2a2a;
  border: 1px solid #444;
  color: #ccc;
  border-radius: 4px;
  cursor: pointer;
}

button:hover {
  background: #383838;
}

/* ── Song / Movement / Section ──────────────────────────────────────────── */
.song-editor {
  margin-bottom: 2rem;
}

.song-editor__title {
  font-size: 1.2rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: #f0f0f0;
}

.movement-editor {
  margin-bottom: 1.5rem;
}

.movement-editor__title {
  font-size: 1rem;
  color: #aaa;
  margin-bottom: 0.5rem;
}

.movement-editor__add-section {
  margin-top: 0.5rem;
}

.section-editor {
  background: #222;
  border: 1px solid #333;
  border-radius: 6px;
  margin-bottom: 1rem;
  padding: 0.75rem;
}

.section-editor__header {
  margin-bottom: 0.5rem;
}

.section-editor__label {
  background: transparent;
  border: none;
  border-bottom: 1px solid #444;
  color: #ccc;
  /* 16px: avoid iOS focus-zoom on the section name field too. */
  font-size: 16px;
  font-weight: 600;
  padding: 0.3rem 0;
  width: 100%;
}

.section-editor__label:focus {
  outline: none;
  border-bottom-color: #888;
}

.section-editor__add-stanza {
  margin-top: 0.5rem;
  font-size: 0.8rem;
}

/* ── Stanza ─────────────────────────────────────────────────────────────── */
.stanza-editor {
  background: #1e1e1e;
  border: 1px solid #2a2a2a;
  border-radius: 4px;
  margin-bottom: 0.75rem;
  padding: 0.5rem;
}

.stanza-editor__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.4rem;
}

.stanza-editor__label {
  font-size: 0.75rem;
  color: #666;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stanza-editor__delete {
  font-size: 0.75rem;
}

.stanza-editor__add-line {
  margin-top: 0.4rem;
  font-size: 0.8rem;
}

/* ── Line editor ────────────────────────────────────────────────────────── */
.line-editor {
  margin-bottom: 0.25rem;
}

.line-editor__row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.line-editor__input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  border-bottom: 1px solid #333;
  color: #e0e0e0;
  font-family: "Courier New", monospace;
  /* 16px keeps iOS from zooming the viewport when the field gains focus. */
  font-size: 16px;
  resize: none;
  line-height: 1.5;
  padding: 0.3rem 0;
  /* Progressive enhancement: auto-grow to fit wrapped lines where supported
     (Chromium/Android). Elsewhere it falls back to the single row below. */
  field-sizing: content;
  overflow: hidden;
}

.line-editor__input:focus {
  outline: none;
  border-bottom-color: #666;
}

.line-editor__delete {
  font-size: 1rem;
  padding: 0 0.3rem;
  color: #666;
  background: transparent;
  border: none;
}

.line-editor__delete:hover {
  color: #cc4444;
}

/* ── Rhyme label ────────────────────────────────────────────────────────── */
.rhyme-label {
  display: inline-block;
  width: 1.4rem;
  text-align: center;
  font-weight: 700;
  font-size: 0.8rem;
  color: #7aadff;
  cursor: default;
}

.rhyme-label--none {
  color: #444;
}

/* ── Scansion ───────────────────────────────────────────────────────────── */
.scansion {
  display: flex;
  align-items: center;
  gap: 0.15rem;
  padding-left: 1.8rem;
  font-size: 0.8rem;
  font-family: monospace;
  color: #888;
  min-height: 1.2em;
}

.scansion--empty {
  height: 0;
}

.scansion__mark--primary {
  color: #e0b040;
}

.scansion__mark--secondary {
  color: #b09040;
}

.scansion__mark--unstressed {
  color: #555;
}

.scansion__count {
  margin-left: 0.3rem;
  color: #555;
  font-size: 0.75rem;
}

/* ── Observation chips ──────────────────────────────────────────────────── */
.observation-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  padding-left: 1.8rem;
  margin-top: 0.2rem;
}

.chip {
  display: inline-block;
  padding: 0.1rem 0.4rem;
  border-radius: 3px;
  font-size: 0.7rem;
  cursor: default;
  border: 1px solid transparent;
}

.chip--adjacent-stress {
  background: #3a2a00;
  border-color: #8a6000;
  color: #ffc060;
}

.chip--stop-cluster {
  background: #2a1a2a;
  border-color: #6a3a6a;
  color: #cc88cc;
}

.chip--line-ending {
  background: #1a2a1a;
  border-color: #3a5a3a;
  color: #80c080;
}

.chip--intra-rep {
  background: #1a2a3a;
  border-color: #3a5a7a;
  color: #80b0e0;
}

.chip--cross-rep {
  background: #1e2835;
  border-color: #3a5060;
  color: #70a8c8;
}

.chip--containment {
  background: #2a1e1e;
  border-color: #6a3a3a;
  color: #c89090;
}

.chip--shape-distance {
  background: #251e10;
  border-color: #6a5010;
  color: #c0a050;
}

/* ── Suggestions panel ──────────────────────────────────────────────────── */
.suggest-panel {
  position: fixed;
  right: 0;
  top: 0;
  bottom: 0;
  width: 260px;
  background: #1e1e2a;
  border-left: 1px solid #383860;
  display: flex;
  flex-direction: column;
  z-index: 100;
  box-shadow: -4px 0 16px rgba(0,0,0,0.4);
}

.suggest-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0.8rem;
  background: #15152a;
  border-bottom: 1px solid #383860;
}

.suggest-panel__title {
  font-size: 0.8rem;
  color: #aab;
  font-family: monospace;
}

.suggest-panel__close {
  background: transparent;
  border: none;
  color: #888;
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0 0.2rem;
}

.suggest-panel__close:hover { color: #ccc; }

.suggest-panel__list {
  flex: 1;
  overflow-y: auto;
  list-style: none;
  padding: 0.4rem 0;
}

.suggest-panel__item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem 0.8rem;
  font-size: 0.85rem;
  border-bottom: 1px solid #252535;
}

.suggest-panel__item:hover {
  background: #252535;
}

.suggest-panel__rhyme-type {
  font-size: 0.7rem;
  color: #667;
  width: 1rem;
  text-align: center;
}

.suggest-panel__word {
  flex: 1;
  color: #d0d0e8;
  font-family: monospace;
}

.suggest-panel__syl {
  font-size: 0.7rem;
  color: #667;
}

/* ── Mobile / touch ─────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .app__main {
    padding: 0.75rem;
    padding-left: max(0.75rem, env(safe-area-inset-left));
    padding-right: max(0.75rem, env(safe-area-inset-right));
    padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
  }

  /* Roomier tap targets — aim for ~44px touch height. */
  button,
  .toolbar__mode-btn {
    padding: 0.5rem 0.75rem;
    min-height: 40px;
  }

  .toolbar__actions {
    flex-wrap: wrap;
  }

  /* Section/stanza chrome can shed horizontal padding on a phone. */
  .section-editor {
    padding: 0.6rem;
  }

  .line-editor__delete {
    min-width: 2rem;
    min-height: 2rem;
    font-size: 1.3rem;
  }

  .stanza-editor__delete,
  .stanza-editor__add-line,
  .section-editor__add-stanza {
    min-height: 36px;
  }

  /* Suggestions become a bottom sheet rather than a narrow side rail. */
  .suggest-panel {
    width: 100%;
    left: 0;
    right: 0;
    top: auto;
    height: 55dvh;
    border-left: none;
    border-top: 1px solid #383860;
    border-radius: 12px 12px 0 0;
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.5);
    padding-bottom: env(safe-area-inset-bottom);
  }

  .suggest-panel__item {
    padding: 0.6rem 0.9rem;
    font-size: 1rem;
  }
}

/* Respect users who prefer reduced motion (no transitions to disable yet,
   but set the expectation for future animated panels). */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
