/*
 * Melon Tools: shared base for the small single-purpose tools (one problem, one page).
 * Load after /melon-shell.css. Tokens (--m-*) live there; this file only adds components.
 */
:root,
[data-theme="dark"] {
  /* Aliases read by /melon-support.js so the bottom bar matches. */
  --surface: color-mix(in srgb, var(--m-card) 88%, transparent);
  --border: var(--m-border);
  --text: var(--m-fg);
  --muted: var(--m-muted-fg);
  --accent: var(--m-fg);
  --ok: #007a55;
  --warn-bg: #fffbeb;
  --warn-fg: #92400e;
  --sheet: #ffffff;
}

[data-theme="dark"] {
  --ok: #5ee9b5;
  --warn-bg: rgba(245, 158, 11, 0.12);
  --warn-fg: #fcd34d;
}

*, *::before, *::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding-bottom: 72px;
  background: var(--m-page);
  color: var(--m-fg);
  font-family: var(--m-font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

[hidden] {
  display: none !important;
}

.page {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 24px;
}

@media (max-width: 560px) {
  .page {
    padding: 0 16px;
  }
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 36px;
  padding: 0 16px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--m-fg);
  font: inherit;
  font-weight: 500;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, opacity 0.15s;
}

.btn svg {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn:focus-visible,
.input:focus-visible,
.seg input:focus-visible + span,
.check input:focus-visible,
.dropzone:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--m-focus);
}

.btn-primary {
  background: var(--m-primary);
  color: var(--m-primary-fg);
}

.btn-primary:hover:not(:disabled) {
  background: var(--m-primary-hover);
}

.btn-outline {
  background: var(--m-input-bg);
  box-shadow: inset 0 0 0 1px var(--m-border);
}

.btn-outline:hover:not(:disabled),
.btn-ghost:hover:not(:disabled) {
  background: var(--m-muted);
}

.btn-danger {
  color: var(--m-danger);
}

.btn-sm {
  height: 32px;
  padding: 0 12px;
  font-size: 13px;
}

.btn-icon {
  width: 32px;
  padding: 0;
}

.btn-block {
  width: 100%;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

/* ---------- Cards ---------- */
.card {
  background: var(--m-card);
  border-radius: var(--m-radius-card);
  box-shadow: 0 0 0 1px var(--m-ring-line), 0 1px 2px rgba(0, 0, 0, 0.04);
  padding: 20px;
}

.card + .card {
  margin-top: 16px;
}

.card-title {
  margin: 0 0 4px;
  font-family: var(--m-font-heading);
  font-size: 16px;
  font-weight: 600;
  line-height: 1.3;
}

.card-desc {
  margin: 0 0 14px;
  color: var(--m-muted-fg);
  font-size: 13px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 20px;
  align-items: start;
}

.layout > aside {
  position: sticky;
  top: 72px;
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .layout > aside {
    position: static;
  }
}

/* ---------- Form controls ---------- */
.field {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
}

.label {
  font-size: 13px;
  font-weight: 500;
}

.input {
  width: 100%;
  min-height: 36px;
  padding: 7px 12px;
  border: 1px solid var(--m-border);
  border-radius: var(--m-radius);
  background: var(--m-input-bg);
  color: var(--m-fg);
  font: inherit;
}

textarea.input {
  min-height: 120px;
  resize: vertical;
  line-height: 1.5;
}

select.input {
  appearance: none;
  padding-right: 32px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2379716b' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}

select.input option {
  background: var(--m-card);
  color: var(--m-fg);
}

.check {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 8px 0;
  font-size: 13px;
  cursor: pointer;
}

.check input {
  width: 16px;
  height: 16px;
  margin: 2px 0 0;
  accent-color: var(--m-primary);
}

/* Segmented control: <div class="seg"><label><input type="radio"><span>…</span></label>…</div> */
.seg {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 3px;
  border-radius: 999px;
  background: var(--m-muted);
}

.seg label {
  flex: 1 1 auto;
  cursor: pointer;
}

.seg input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.seg span {
  display: block;
  padding: 5px 12px;
  border-radius: 999px;
  color: var(--m-muted-fg);
  font-size: 13px;
  font-weight: 500;
  text-align: center;
  white-space: nowrap;
}

.seg input:checked + span {
  background: var(--m-card);
  color: var(--m-fg);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08), 0 0 0 1px var(--m-ring-line);
}

.hint {
  color: var(--m-muted-fg);
  font-size: 12px;
}

.note {
  padding: 10px 12px;
  border-radius: var(--m-radius);
  background: var(--warn-bg);
  color: var(--warn-fg);
  font-size: 13px;
}

.note-ok {
  background: var(--m-primary-soft);
  color: var(--m-primary-soft-fg);
}

/* ---------- Drop zone ---------- */
.dropzone {
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: 48px 20px;
  border: 1.5px dashed var(--m-border);
  border-radius: var(--m-radius-card);
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.dropzone:hover,
.dropzone.is-over {
  border-color: var(--m-primary);
  background: var(--m-primary-soft);
}

.dropzone strong {
  font-size: 16px;
}

.icon-circle {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--m-muted);
}

.icon-circle svg {
  width: 22px;
  height: 22px;
}

.steps {
  margin: 18px 0 0;
  padding-left: 20px;
  color: var(--m-muted-fg);
  font-size: 13px;
}

.steps li + li {
  margin-top: 4px;
}

.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  place-items: center;
  background: color-mix(in srgb, var(--m-page) 80%, transparent);
  font-size: 18px;
  font-weight: 600;
  pointer-events: none;
}

body.is-dragging .drop-overlay {
  display: grid;
}

.drop-overlay > div {
  padding: 24px 32px;
  border: 2px dashed var(--m-primary);
  border-radius: var(--m-radius-card);
  background: var(--m-card);
}

/* ---------- File line, status ---------- */
.file-line {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.file-line .name {
  overflow: hidden;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-line .meta {
  color: var(--m-muted-fg);
  font-size: 12px;
  white-space: nowrap;
}

.status {
  min-height: 20px;
  margin-top: 10px;
  color: var(--m-muted-fg);
  font-size: 13px;
}

.status.is-error {
  color: var(--m-danger);
}

.status.is-ok {
  color: var(--ok);
}

/* ---------- Info section below the tool ---------- */
.info {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
  margin: 32px 0 16px;
}

.info h2 {
  margin: 0 0 6px;
  font-family: var(--m-font-heading);
  font-size: 15px;
  font-weight: 600;
}

.info p,
.info li {
  margin: 0;
  color: var(--m-muted-fg);
  font-size: 13px;
}

.info ul {
  margin: 0;
  padding-left: 18px;
}

.info p + p {
  margin-top: 6px;
}

.related {
  margin: 0 0 24px;
  color: var(--m-muted-fg);
  font-size: 13px;
}

.related a {
  color: var(--m-fg);
}
