/* ===================================================================
   Text Tool – Context-Sensitive Controls
   Adapted from SchoolDrwFire icon presentation style
   =================================================================== */

/* ---- wrapper ---- */
.toolctx-text {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* ---- shared base for buttons / inputs / selects ---- */
.toolctx-text .btn,
.toolctx-text .input,
.toolctx-text .select {
  height: 2.8rem;
  min-height: 44px;
  border-radius: 10px;
  border: 1px solid var(--ui-border, #e5e7eb);
  background: var(--ui-bg, #fff);
  color: var(--ui-fg, #111827);
  padding: 0 .5rem;
  box-sizing: border-box;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* ---- buttons ---- */
.toolctx-text .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  min-width: 2.8rem;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease,
              box-shadow 120ms ease, transform 80ms ease;
  user-select: none;
  touch-action: manipulation;
}

.toolctx-text .btn:disabled {
  opacity: .6;
  cursor: not-allowed;
  pointer-events: none;
}

@media (hover: hover) and (pointer: fine) {
  .toolctx-text .btn:hover:not(:disabled) {
    background: var(--ui-hover, #f8fafc);
    border-color: var(--ui-border-strong, #cbd5e1);
  }
}

.toolctx-text .btn:active:not(:disabled) {
  transform: scale(.95);
  background: var(--ui-hover, #f0f0f0);
}

/* ---- labels ---- */
.toolctx-text .label {
  font: 500 0.875rem/1.1 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  color: var(--ui-muted, #475569);
}

/* ---- select (font-size preset) ---- */
.toolctx-text .sel {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
}

.toolctx-text .select {
  width: 10.5rem;
  padding-right: 2rem;
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
                    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 1.1rem) 1rem, calc(100% - .75rem) 1rem;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  font-size: 16px;
}

.toolctx-text .select option {
  font-size: .95rem;
}

/* ---- number input ---- */
.toolctx-text .num {
  width: 5rem;
  text-align: right;
  font-size: 16px;
}

/* ---- toggle button group (B, I, U, super, sub) ---- */
.toolctx-text .toggles {
  display: inline-flex;
  gap: .35rem;
}

.toolctx-text .toggle {
  width: 2.8rem;
  min-width: 44px;
}

/* active / pressed state */
.toolctx-text .btn.on,
.toolctx-text .btn[aria-pressed="true"],
.toolctx-text .toggle.on {
  background: var(--ui-accent, #dbeafe);
  border-color: var(--ui-accent-strong, #60a5fa);
  color: var(--ui-accent-text, #1d4ed8);
}

/* ---- text-style icons (italic, underline, strikethrough) ---- */
.toolctx-text .ico-b,
.toolctx-text .ico-i,
.toolctx-text .ico-u,
.toolctx-text .ico-s {
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-weight: 700;
  font-size: 1.1rem;
  line-height: 1;
  user-select: none;
  pointer-events: none;
}

.toolctx-text .ico-b::before { content: "B"; font-weight: 800; }
.toolctx-text .ico-i::before { content: "I"; font-style: italic; }
.toolctx-text .ico-u::before { content: "U"; text-decoration: underline; text-underline-offset: 2px; }
.toolctx-text .ico-s::before { content: "S"; text-decoration: line-through; text-decoration-thickness: 2px; }

/* ---- alignment controls ---- */
.toolctx-text .align-controls {
  display: inline-flex;
  gap: .6rem;
}

.toolctx-text .align-btn {
  min-width: 2.8rem;
  width: 2.8rem;
  height: 2.8rem;
  min-height: 44px;
  font-size: 1rem;
  transition: all .15s ease;
  padding: 0;
  touch-action: manipulation;
}

@media (hover: hover) and (pointer: fine) {
  .toolctx-text .align-btn:hover {
    background: var(--ui-hover, #f3f4f6);
    border-color: var(--ui-border-strong, #cbd5e1);
  }
}

.toolctx-text .align-btn:active {
  transform: scale(.95);
}

.toolctx-text .align-btn.on,
.toolctx-text .align-btn[aria-pressed="true"] {
  background: var(--ui-accent, #dbeafe);
  border-color: var(--ui-accent-strong, #60a5fa);
  color: var(--ui-accent-text, #1d4ed8);
  box-shadow: 0 2px 4px rgba(0, 0, 0, .1);
}

.toolctx-text .align-btn:focus-visible {
  outline: 3px solid var(--ui-focus, #3b82f6);
  outline-offset: 2px;
}

/* ---- alignment glyph (visual line indicators) ---- */
.toolctx-text .align-glyph {
  width: 2.2rem;
  height: 2.2rem;
  border: 1.5px solid var(--ui-border, #cbd5e1);
  border-radius: 10px;
  background: #fff;
  display: inline-flex;
  flex-direction: column;
  justify-content: center;
  gap: .24rem;
  padding: .14rem .18rem;
  box-sizing: border-box;
  pointer-events: none;
  color: currentColor;
}

.toolctx-text .align-glyph .line {
  height: 3.5px;
  background: currentColor;
  border-radius: 3px;
  display: block;
}

/* left-aligned lines */
.toolctx-text .align-glyph.left .line { margin-left: 0; margin-right: auto; }
.toolctx-text .align-glyph.left .line:first-child  { width: 90%; }
.toolctx-text .align-glyph.left .line:nth-child(2)  { width: 75%; }
.toolctx-text .align-glyph.left .line:nth-child(3)  { width: 85%; }

/* centre-aligned lines */
.toolctx-text .align-glyph.center .line { margin-left: auto; margin-right: auto; }
.toolctx-text .align-glyph.center .line:first-child  { width: 85%; }
.toolctx-text .align-glyph.center .line:nth-child(2)  { width: 70%; }
.toolctx-text .align-glyph.center .line:nth-child(3)  { width: 90%; }

/* right-aligned lines */
.toolctx-text .align-glyph.right .line { margin-left: auto; margin-right: 0; }
.toolctx-text .align-glyph.right .line:first-child  { width: 85%; }
.toolctx-text .align-glyph.right .line:nth-child(2)  { width: 70%; }
.toolctx-text .align-glyph.right .line:nth-child(3)  { width: 90%; }

/* glyph inherits active colour when button is pressed */
.toolctx-text .align-btn.on .align-glyph,
.toolctx-text .align-btn[aria-pressed="true"] .align-glyph {
  border-color: var(--ui-accent-strong, #60a5fa);
  background: var(--ui-accent, #dbeafe);
}

/* ---- decoration-controls group (super / sub) ---- */
.toolctx-text .dec-controls {
  display: inline-flex;
  gap: .6rem;
}

.toolctx-text .dec-controls .btn {
  width: 2.8rem;
  min-width: 2.8rem;
  min-height: 44px;
}

/* ---- dot separator ---- */
.toolctx-text .dot {
  width: 4px;
  height: 4px;
  background: #cbd5e1;
  border-radius: 999px;
  display: inline-block;
}

/* ---- screen-reader only ---- */
.toolctx-text .sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* ==============================================================
   Responsive breakpoints
   ============================================================== */

@media (max-width: 980px) {
  .toolctx-text { gap: .6rem; }
  .toolctx-text .label { display: none; }
  .toolctx-text .select { width: 9.5rem; }
  .toolctx-text .input  { width: 6.5rem; }
  .toolctx-text .align-controls { gap: .5rem; }
}

@media (max-width: 720px) {
  .toolctx-text { gap: .5rem; }
  .toolctx-text .select { width: 8.5rem; }
  .toolctx-text .input  { width: 5.5rem; }
  .toolctx-text .btn,
  .toolctx-text .input,
  .toolctx-text .select {
    height: 2.6rem;
    min-height: 44px;
    border-radius: 9px;
    font-size: 16px;
  }
  .toolctx-text .align-btn {
    width: 2.6rem; min-width: 2.6rem;
    height: 2.6rem; min-height: 44px;
  }
  .toolctx-text .align-glyph { width: 2rem; height: 2rem; }
  .toolctx-text .align-controls { gap: .4rem; }
}

@media (max-width: 560px) {
  .toolctx-text { gap: .45rem; }
  .toolctx-text .select { width: 7.5rem; }
  .toolctx-text .input  { width: 5rem; }
  .toolctx-text .btn,
  .toolctx-text .input,
  .toolctx-text .select {
    height: 2.5rem;
    min-height: 44px;
    border-radius: 8px;
    font-size: 16px;
  }
  .toolctx-text .align-btn {
    width: 2.5rem; min-width: 2.5rem;
    height: 2.5rem; min-height: 44px;
    font-size: .95rem;
  }
  .toolctx-text .align-glyph { width: 1.9rem; height: 1.9rem; }
  .toolctx-text .align-controls { gap: .35rem; }
}

@media (max-width: 400px) {
  .toolctx-text .btn,
  .toolctx-text .input,
  .toolctx-text .select { min-height: 48px; }
  .toolctx-text .align-btn {
    min-height: 48px;
    width: 2.8rem;
    min-width: 2.8rem;
  }
}

/* ---- accessibility ---- */
@media (forced-colors: active) {
  .toolctx-text .btn,
  .toolctx-text .input,
  .toolctx-text .select {
    border: 1px solid ButtonText;
    background: Canvas;
    color: ButtonText;
  }
  .toolctx-text .btn:hover {
    background: CanvasText;
    color: Canvas;
  }
  .toolctx-text .align-btn.on,
  .toolctx-text .align-btn[aria-pressed="true"] {
    border-width: 3px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .toolctx-text .align-btn { transition: none; }
  .toolctx-text .btn       { transition: none; }
}
