/*
 * mejiro-editor.css — optional editor chrome shared by
 * @libraz/mejiro-vue and @libraz/mejiro-react editor components.
 *
 * Import with the reader chrome:
 *   import '@libraz/mejiro/render/mejiro-reader.css';
 *   import '@libraz/mejiro/render/mejiro-editor.css';
 *
 * Wrapped in the shared `mejiro.chrome` cascade layer.
 */

@layer mejiro.base, mejiro.chrome, mejiro.print;

@layer mejiro.chrome {
  .mejiro-editor {
    --mejiro-editor-panel: #f5f0e4;
    --mejiro-editor-line: #d8d0c4;
    --mejiro-editor-ink: #2a2521;
    /* Width of the side panel (manuscript controls). Override on the host to
     * tighten or widen the editing column, or set to 100% on small screens. */
    --mejiro-editor-panel-width: 360px;

    height: 100%;
    display: grid;
    grid-template-columns: minmax(0, 1fr) var(--mejiro-editor-panel-width);
    background: var(--mejiro-bg-deep, #1c1915);
    color: var(--mejiro-editor-ink);
    font-family: var(--mejiro-font-ui, "Helvetica Neue", system-ui, sans-serif);
  }

  .mejiro-editor-preview {
    min-width: 0;
    min-height: 0;
    position: relative;
  }

  .mejiro-editor-preview > .mejiro-reader,
  .mejiro-editor-preview > .mejiro-reader-drop-zone {
    height: 100%;
  }

  .mejiro-editor-panel {
    min-width: 0;
    padding: 18px;
    background: var(--mejiro-editor-panel);
    border-left: 1px solid rgba(42, 37, 33, 0.16);
    box-sizing: border-box;
    overflow: auto;
  }

  /* Mirrored layout: the panel moves to the left and the preview to the right.
   * Set `data-panel-side` on the editor root — the shipped editor components
   * write it from their `panelSide` prop. */
  .mejiro-editor[data-panel-side="left"] {
    grid-template-columns: var(--mejiro-editor-panel-width) minmax(0, 1fr);
  }

  .mejiro-editor[data-panel-side="left"] .mejiro-editor-preview {
    order: 2;
  }

  .mejiro-editor[data-panel-side="left"] .mejiro-editor-panel {
    order: 1;
    border-left: 0;
    border-right: 1px solid rgba(42, 37, 33, 0.16);
  }

  .mejiro-editor-head {
    display: flex;
    flex-direction: column;
    gap: 3px;
    margin-bottom: 16px;
  }

  .mejiro-editor-head span,
  .mejiro-editor-label {
    color: var(--mejiro-accent, #8b3a3a);
    font-size: 0.62rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
  }

  .mejiro-editor-head strong {
    font-family: var(--mejiro-font-body, serif);
    font-size: 1.05rem;
    line-height: 1.35;
  }

  .mejiro-editor-head small {
    color: var(--mejiro-ink-light, #6b6156);
    font-size: 0.72rem;
  }

  .mejiro-editor-section {
    padding: 14px 0;
    border-top: 1px solid var(--mejiro-editor-line);
    display: flex;
    flex-direction: column;
    gap: 9px;
  }

  .mejiro-editor-paragraphs {
    max-height: 210px;
    overflow: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
  }

  .mejiro-editor-paragraphs button {
    padding: 9px 10px;
    border: 1px solid transparent;
    background: #fff;
    color: inherit;
    text-align: left;
    cursor: pointer;
    font-family: inherit;
  }

  .mejiro-editor-paragraphs button[draggable="true"] {
    cursor: grab;
  }

  .mejiro-editor-paragraphs button[draggable="true"]:active {
    cursor: grabbing;
  }

  .mejiro-editor-paragraphs button[data-dragging] {
    opacity: 0.5;
  }

  .mejiro-editor-paragraphs button.is-active {
    border-color: rgba(139, 58, 58, 0.45);
    box-shadow: inset 3px 0 0 var(--mejiro-accent, #8b3a3a);
  }

  .mejiro-editor-paragraphs span,
  .mejiro-editor-paragraphs strong {
    display: block;
  }

  .mejiro-editor-paragraphs span {
    color: var(--mejiro-ink-light, #6b6156);
    font-size: 0.62rem;
    margin-bottom: 3px;
  }

  .mejiro-editor-paragraphs strong {
    font-size: 0.76rem;
    line-height: 1.45;
    font-weight: 500;
  }

  .mejiro-editor textarea,
  .mejiro-editor input {
    width: 100%;
    box-sizing: border-box;
    border: 1px solid var(--mejiro-control-border, #ccc5b8);
    background: #fff;
    color: inherit;
    font: inherit;
    font-size: 0.78rem;
    padding: 8px;
  }

  .mejiro-editor textarea {
    min-height: 110px;
    resize: vertical;
    line-height: 1.7;
  }

  /* Notation highlighter — overlay that tints the background of manuscript
   * notation tokens behind the editing textarea. */
  .mejiro-notation-highlighter {
    position: relative;
    display: block;
    min-height: 110px;
  }

  .mejiro-notation-overlay,
  .mejiro-notation-textarea {
    margin: 0;
    border: 1px solid var(--mejiro-control-border, #ccc5b8);
    padding: 8px;
    font: inherit;
    font-size: 0.78rem;
    line-height: 1.7;
    box-sizing: border-box;
    white-space: pre-wrap;
    overflow-wrap: break-word;
    word-break: normal;
  }

  .mejiro-notation-overlay {
    position: absolute;
    inset: 0;
    background: #fff;
    color: transparent;
    overflow: hidden;
    pointer-events: none;
  }

  .mejiro-notation-textarea {
    position: relative;
    width: 100%;
    background: transparent;
    color: inherit;
    resize: vertical;
  }

  .mejiro-notation-token {
    border-radius: 2px;
  }

  .mejiro-notation-token[data-token="ruby"] {
    background: rgba(255, 200, 200, 0.55);
  }

  .mejiro-notation-token[data-token="emphasis"] {
    background: rgba(255, 230, 130, 0.55);
  }

  .mejiro-notation-token[data-token="tcy"] {
    background: rgba(170, 230, 230, 0.6);
  }

  .mejiro-notation-token[data-token="em"] {
    background: rgba(170, 200, 255, 0.5);
  }

  .mejiro-notation-token[data-token="strong"] {
    background: rgba(255, 180, 200, 0.65);
  }

  .mejiro-notation-token[data-token="link"] {
    background: rgba(180, 230, 255, 0.55);
  }

  .mejiro-notation-token[data-token="footnote"] {
    background: rgba(220, 220, 220, 0.7);
  }

  .mejiro-editor textarea.mejiro-editor-manuscript {
    min-height: 260px;
    font-family: var(--mejiro-font-body, serif);
  }

  .mejiro-editor-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .mejiro-editor button {
    border: 1px solid var(--mejiro-control-border, #ccc5b8);
    background: #fff;
    color: inherit;
    font: inherit;
    font-size: 0.74rem;
    padding: 8px 10px;
    cursor: pointer;
  }

  .mejiro-editor button.mejiro-editor-primary,
  .mejiro-editor button.mejiro-editor-export {
    background: var(--mejiro-accent, #8b3a3a);
    border-color: var(--mejiro-accent, #8b3a3a);
    color: #fff;
  }

  .mejiro-editor-export {
    width: 100%;
    margin-top: 14px;
  }

  .mejiro-editor-loading,
  .mejiro-editor-error {
    position: absolute;
    left: 18px;
    bottom: 18px;
    padding: 8px 10px;
    background: rgba(245, 240, 228, 0.95);
    color: var(--mejiro-editor-ink);
    font-size: 0.74rem;
  }

  @media (max-width: 900px) {
    .mejiro-editor,
    .mejiro-editor[data-panel-side="left"] {
      height: auto;
      min-height: 100%;
      grid-template-columns: 1fr;
      grid-template-rows: minmax(640px, 100vh) auto;
    }

    .mejiro-editor-panel,
    .mejiro-editor[data-panel-side="left"] .mejiro-editor-panel {
      border-left: 0;
      border-right: 0;
      border-top: 1px solid rgba(42, 37, 33, 0.16);
    }

    .mejiro-editor[data-panel-side="left"] .mejiro-editor-preview,
    .mejiro-editor[data-panel-side="left"] .mejiro-editor-panel {
      order: initial;
    }
  }
} /* end @layer mejiro.chrome */
