:root {
  color-scheme: dark;
  font-family: Inter, system-ui, sans-serif;
  line-height: 1.5;
  font-weight: 400;
  background: #0f1115;
  color: #f5f7fb;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    radial-gradient(circle at top, rgba(88, 141, 255, 0.2), transparent 28%),
    #0f1115;
}

button,
input,
select {
  font: inherit;
}

code {
  font-family: "SFMono-Regular", ui-monospace, monospace;
}

#app {
  width: 100%;
}

/* Layout */

.layout {
  width: min(700px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 1.5rem 0 4rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Card */

.card {
  padding: 1.25rem;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  background: rgba(18, 22, 31, 0.9);
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.2);
}

.card h2 {
  margin: 0 0 0.85rem;
  font-size: 0.95rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #90a6ff;
}

/* Source row */

.source-row {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.file-label {
  flex: 1;
  min-width: 0;
}

.file-label input[type="file"] {
  display: block;
  width: 100%;
  padding: 0.6rem 0.75rem;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: #111722;
  color: inherit;
  cursor: pointer;
}

#paste-btn {
  padding: 0.6rem 1.1rem;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(88, 141, 255, 0.15);
  color: inherit;
  cursor: pointer;
  white-space: nowrap;
}

#paste-btn:hover {
  background: rgba(88, 141, 255, 0.28);
}

/* Off-screen textarea used as a reliable paste-event sink on mobile.
   Kept in the tab order only when explicitly focused by the paste button. */
#paste-target {
  position: fixed;
  left: -9999px;
  top: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
}

#copy-btn {
  margin-top: 0.75rem;
  padding: 0.6rem 1.1rem;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(88, 141, 255, 0.15);
  color: inherit;
  cursor: pointer;
  white-space: nowrap;
  width: 100%;
}

#connect-btn,
#disconnect-btn,
#send-btn {
  padding: 0.6rem 1.1rem;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: inherit;
  cursor: pointer;
}

#connect-btn.primary,
#send-btn.primary {
  background: rgba(88, 141, 255, 0.15);
}

#disconnect-btn.secondary {
  background: rgba(255, 255, 255, 0.06);
}

#connect-btn:hover,
#send-btn:hover {
  background: rgba(88, 141, 255, 0.28);
}

#disconnect-btn:hover {
  background: rgba(255, 255, 255, 0.12);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

#copy-btn:hover {
  background: rgba(88, 141, 255, 0.28);
}

.status {
  margin: 0.75rem 0 0;
  font-size: 0.875rem;
  color: #c9d2e3;
}

/* Settings */

.settings-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
}

.settings-row input,
.settings-row select,
.settings-row button {
  height: 2.5rem;
  padding: 0 0.75rem;
  box-sizing: border-box;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: #111722;
  color: inherit;
}

.settings-row input[type="number"] {
  width: 6.5rem;
  flex-shrink: 0;
}

.settings-row select {
  flex: 1;
  min-width: 0;
}

.settings-row input[type="color"],
.settings-row button {
  width: 2.75rem;
  padding: 0.35rem;
  flex-shrink: 0;
  cursor: pointer;
}

.settings-row button {
  font-size: 1.1rem;
  line-height: 1;
}

.settings-row button.active {
  background: rgba(88, 141, 255, 0.28);
  border-color: rgba(88, 141, 255, 0.45);
}

.size-controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem 1rem;
  margin-top: 0.75rem;
}

.slider-control {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 0;
  font-size: 0.875rem;
  color: #c9d2e3;
}

.slider-control span {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
}

.slider-control output {
  color: #90a6ff;
  font-variant-numeric: tabular-nums;
}

.slider-control input[type="range"] {
  width: 100%;
  margin: 0;
  accent-color: #588dff;
  cursor: pointer;
}

/* Text blocks */

#text-blocks-container {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

#text-blocks-container:not(:empty) {
  margin-top: 0.75rem;
}

.text-block-entry {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0.6rem;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.03);
}

.text-block-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.text-block-row input,
.text-block-row select,
.text-block-row button {
  height: 2rem;
  padding: 0 0.5rem;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: #111722;
  color: inherit;
  font-size: 0.8rem;
  box-sizing: border-box;
}

.text-block-row .tb-text {
  flex: 1;
}

.text-block-row .tb-font {
  flex: 1;
  min-width: 0;
}

.text-block-row .tb-fontsize,
.text-block-row .tb-outline-width {
  width: 3.5rem;
  flex-shrink: 0;
}

.text-block-row input[type="range"] {
  flex: 1;
  accent-color: #588dff;
  cursor: pointer;
}

.text-block-row input[type="color"] {
  width: 2rem;
  padding: 0.2rem;
  flex-shrink: 0;
  cursor: pointer;
}

.text-block-row label {
  font-size: 0.8rem;
  color: #c9d2e3;
  flex-shrink: 0;
}

.text-block-row .tb-delete {
  width: 2rem;
  flex-shrink: 0;
  cursor: pointer;
  background: rgba(255, 80, 80, 0.15);
  border-color: rgba(255, 80, 80, 0.25);
  font-size: 0.85rem;
  line-height: 1;
}

.text-block-row .tb-delete:hover {
  background: rgba(255, 80, 80, 0.3);
}

/* Sliders */

.sliders {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.slider-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.slider-row label {
  width: 5.5rem;
  flex-shrink: 0;
  font-size: 0.875rem;
  color: #c9d2e3;
}

.slider-row input[type="range"] {
  flex: 1;
  accent-color: #588dff;
  cursor: pointer;
}

.preview-card {
  display: flex;
  flex-direction: column;
}

.canvas-frame {
  display: grid;
  place-items: center;
  min-height: 180px;
  padding: 0.75rem;
  border-radius: 12px;
  background:
    linear-gradient(45deg, rgba(255, 255, 255, 0.04) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(255, 255, 255, 0.04) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(255, 255, 255, 0.04) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(255, 255, 255, 0.04) 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
}

.canvas-frame canvas {
  width: 100%;
  max-width: 100%;
  image-rendering: pixelated;
  border-radius: 6px;
  background: #fff;
}

#output-canvas {
  cursor: pointer;
}

#output-canvas:hover {
  outline: 2px solid rgba(88, 141, 255, 0.6);
  outline-offset: 2px;
}

details.card > summary {
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  color: #c9d2e3;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

details.card > summary::-webkit-details-marker {
  display: none;
}

details.card > summary::before {
  content: "\25b8";
  font-size: 0.75em;
  color: #90a6ff;
}

details[open].card > summary::before {
  content: "\25be";
}

.meta {
  margin: 0.5rem 0 0;
  font-size: 0.8rem;
  color: #c9d2e3;
  word-break: break-all;
}

.detail-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.4rem 1rem;
  margin: 0.85rem 0 0;
}

.detail-list div {
  display: grid;
  gap: 0.1rem;
}

.detail-list dt {
  color: #90a6ff;
  font-size: 0.8rem;
}

.detail-list dd {
  margin: 0;
  font-size: 0.95rem;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.button-row button {
  flex: 1 1 180px;
}

#send-progress {
  width: 100%;
  height: 0.85rem;
  margin-top: 0.85rem;
  accent-color: #588dff;
}

@media (max-width: 480px) {
  .layout {
    width: calc(100% - 1.5rem);
    padding-top: 1rem;
  }

  .size-controls {
    grid-template-columns: 1fr;
  }
}
