/* ---------- modal ---------- */
/* Top-aligned (not vertically centered): centering made the box's top edge
   jump up/down between characters as content height varies (name length,
   block name wrapping, ...), which reads as jitter when stepping through
   with the prev/next buttons. A fixed top offset keeps the top edge stable;
   .modal-box's own max-height + overflow-y handles anything too tall. */
.modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 48px 12px;
  overflow-y: auto;
}

.modal[hidden] {
  display: none;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .55);
  backdrop-filter: blur(2px);
}

.modal-box {
  position: relative;
  z-index: 1;
  width: min(440px, calc(100vw - 24px));
  max-height: calc(100vh - 96px);
  overflow-y: auto;
  padding: 22px;
  border-radius: 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
}

/* Sticky positioning anchor for .modal-close: height:0 so it takes no flow
   space (doesn't push .modal-nav etc. down), but as a `position: sticky`
   element it still stays pinned to the top of .modal-box's scrollport while
   its content scrolls underneath -- the absolutely positioned close button
   inside hangs outside this 0-height box (nothing clips it) at a fixed
   corner offset, appearing to float above the content. */
.modal-close-anchor {
  position: sticky;
  top: 0;
  height: 0;
  z-index: 5;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--muted);
}

.modal-close:hover {
  color: var(--text);
}

.modal-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
  margin: 24px 0 36px;
}

.nav-prev,
.nav-next {
  width: 35px;
  height: 35px;
  flex: none;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--elevated);
  color: var(--text);
  font-size: 1.4rem;
  line-height: 1;
}

.modal-glyph {
  flex: 1;
  text-align: center;
  font-size: clamp(3.5rem, 22vw, 6rem);
  line-height: 1.1;
  min-width: 0;
  word-break: break-all;
  font-family: var(--font-glyph);
  /* tall enough that nav-prev/next (vertically centered alongside it) never
     sit as high as the close button in the corner -- otherwise small
     glyphs (esp. the small monospace text for control codes) shrink this
     row down to the nav buttons' own 44px and the two overlap. */
  min-height: 90px;
}

.modal-glyph.control {
  font-size: clamp(1.6rem, 8vw, 2.4rem);
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: -.02em;
}

.modal-name {
  text-align: center;
  font-weight: 600;
  margin-bottom: 24px;
  min-height: 1.4em;
}

.modal-info {
  margin: 0;
}

.info-row {
  display: grid;
  grid-template-columns: 7.5rem 1fr;
  gap: 8px;
  padding: 7px 0;
  border-top: 1px solid var(--border);
}

.info-row dt {
  color: var(--muted);
}

.info-row dd {
  margin: 0;
  font-variant-numeric: tabular-nums;
  word-break: break-word;
}

.info-row dd .swatch {
  margin-right: 6px;
  vertical-align: middle;
}

.modal-actions {
  display: flex;
  gap: 16px;
  margin: 8px;
  font-size: .8rem;
}

.art-edit-title {
  margin: 0 0 12px;
  font-size: 1rem;
  font-weight: 700;
}

.art-edit-textarea {
  width: 100%;
  min-height: 120px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel-2);
  color: var(--text);
  font-family: var(--font-glyph);
  font-size: 1.05rem;
  line-height: 1.5;
  resize: vertical;
}

.art-edit-textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

/* Deliberately not .modal-actions: that class's mobile rule turns every
   .btn inside it into a full-width square (sized for the character detail
   modal's row of 5 icon buttons), which would blow up this modal's single
   保存 button to occupy half the box. Plain ordinary button sizing instead. */
.art-edit-actions {
  display: flex;
  justify-content: flex-end;
  margin: 12px 8px 8px;
}

/* ---------- パターン工房 編集モーダル ---------- */
.pattern-field {
  display: block;
  margin-bottom: 10px;
}

.pattern-field-label {
  display: block;
  margin-bottom: 4px;
  font-size: .75rem;
  color: var(--muted);
}

.pattern-name-input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel-2);
  color: var(--text);
  font-size: .95rem;
}

.pattern-name-input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.pattern-mode-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.pattern-mode-row .pattern-field-label {
  display: inline;
  margin: 0 4px 0 0;
}

.pattern-mode-opt {
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--muted);
  font-size: .8rem;
}

.pattern-mode-opt.active {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
  font-weight: 600;
  box-shadow: none;
}

/* 適用単位/サンプルは技（{_} を含むパターン）にしか意味がないので、生成
   パターン編集中は行ごと薄くする（app.js の renderPatternEditPreview）。 */
.pattern-mode-row.disabled {
  opacity: .45;
  pointer-events: none;
}

.pattern-preview {
  margin-bottom: 10px;
  padding: 8px 10px;
  border: 1px dashed var(--border);
  border-radius: 10px;
}

.pattern-preview-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.pattern-preview-head .pattern-field-label {
  margin: 0;
}

.pattern-preview-sample {
  width: 7em;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--text);
  font-family: var(--font-glyph);
}

.pattern-preview-sample:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

/* white-space:pre + horizontal scroll: expansion samples are art fragments,
   so wrapping them would misalign multi-line results. */
.pattern-preview-out {
  min-height: 1.5em;
  font-family: var(--font-glyph);
  font-size: 1rem;
  line-height: 1.4;
  white-space: pre;
  overflow-x: auto;
}

