.tm {
  --tm-bg: #f6f8fb;
  --tm-card: #ffffff;
  --tm-text: #0f172a;
  --tm-muted: #475569;
  --tm-primary: #2563eb;
  --tm-primary-dark: #1d4ed8;
  --tm-accent: #14b8a6;
  --tm-danger: #dc2626;
  --tm-border: #dbe2ec;
  --tm-line: #e2e8f0;
  --tm-zone: #f6f8fb;
  --tm-item: #ffffff;
  --tm-input: #ffffff;
  --tm-btn: #ffffff;
  --tm-focus: #2563eb;
  --tm-toast-bg: #0f172a;
  --tm-toast-text: #ffffff;
  --tm-radius: 10px;
  --tm-shadow-1: 0 1px 2px rgba(0, 0, 0, 0.06);
  --tm-shadow-2: 0 8px 24px rgba(0, 0, 0, 0.08);
  box-sizing: border-box;
  max-width: 100%;
  padding: 16px;
  border-radius: var(--tm-radius);
  background: var(--tm-bg);
  color: var(--tm-text);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.5;
}

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

.tm :focus-visible {
  outline: 2px solid var(--tm-focus);
  outline-offset: 2px;
}

.tm .tm-sheet {
  position: relative;
  padding: 12px;
  border-radius: var(--tm-radius);
  background: var(--tm-card);
  box-shadow: var(--tm-shadow-1);
}

.tm .tm-title-input {
  display: block;
  width: 100%;
  margin: 0 0 12px;
  padding: 4px 0;
  border: 0;
  border-bottom: 1px dashed transparent;
  background: transparent;
  color: var(--tm-text);
  font-family: inherit;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.4;
}

.tm .tm-title-input:hover {
  border-bottom-color: var(--tm-muted);
}

.tm .tm-title-input:focus {
  border-bottom-style: solid;
  border-bottom-color: var(--tm-primary);
}

.tm .tm-row {
  position: relative;
  display: flex;
  align-items: stretch;
  border-top: 1px solid var(--tm-line);
}

.tm .tm-row:first-child {
  border-top: 0;
}

.tm .tm-cell {
  flex: 0 0 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  color: #0f172a;
}

.tm .tm-tier-label {
  width: 100%;
  min-height: 44px;
  padding: 4px;
  border: 0;
  border-radius: var(--tm-radius);
  background: transparent;
  color: #0f172a;
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  overflow-wrap: anywhere;
}

.tm .tm-tier-label:hover {
  background: rgba(255, 255, 255, 0.55);
}

.tm .tm-tier-panel {
  position: absolute;
  z-index: 6;
  top: 0;
  right: 8px;
  left: 64px;
  display: flex;
  flex-direction: column;
  max-width: 320px;
  gap: 8px;
  padding: 8px;
  border-radius: var(--tm-radius);
  background: var(--tm-card);
  box-shadow: var(--tm-shadow-2);
}

.tm .tm-tier-label-input {
  width: 100%;
  min-height: 32px;
  padding: 4px 8px;
  border: 1px solid var(--tm-primary);
  border-radius: var(--tm-radius);
  background: var(--tm-input);
  color: var(--tm-text);
  font-family: inherit;
  font-size: 14px;
  text-align: center;
}

.tm .tm-palette {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
}

.tm .tm-palette-color {
  height: 24px;
  border: 1px solid rgba(15, 23, 42, 0.2);
  border-radius: var(--tm-radius);
  cursor: pointer;
}

.tm .tm-panel-actions {
  display: flex;
  gap: 4px;
}

.tm .tm-panel-actions .tm-btn {
  flex: 1 1 0;
  min-width: 0;
  min-height: 40px;
  padding: 8px 4px;
  font-size: 13px;
}

.tm .tm-zone {
  display: flex;
  flex: 1 1 auto;
  flex-wrap: wrap;
  align-items: flex-start;
  align-content: flex-start;
  gap: 8px;
  min-width: 0;
  min-height: 56px;
  padding: 4px;
  border-radius: var(--tm-radius);
  background: var(--tm-zone);
}

.tm .tm-sheet .tm-zone {
  border-radius: 0;
}

.tm .tm-zone.tm-drop-active {
  outline: 2px dashed var(--tm-primary);
  outline-offset: -4px;
}

.tm .tm-item {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  padding: 4px;
  border: 1px solid var(--tm-line);
  border-radius: var(--tm-radius);
  background: var(--tm-item);
  box-shadow: var(--tm-shadow-1);
  cursor: grab;
  overflow: hidden;
  touch-action: manipulation;
}

.tm .tm-item.tm-selected {
  outline: 3px solid var(--tm-accent);
  outline-offset: 1px;
}

.tm .tm-item-text {
  display: -webkit-box;
  overflow: hidden;
  color: var(--tm-text);
  font-size: 12px;
  line-height: 1.25;
  line-break: strict;
  max-height: 3.75em;
  text-align: center;
  word-break: break-word;
  overflow-wrap: anywhere;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.tm .tm-item-image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.tm .tm-item-name {
  display: none;
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  padding: 1px 3px;
  background: rgba(15, 23, 42, 0.72);
  color: #ffffff;
  font-size: 10px;
  line-height: 1.35;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}

.tm.tm-show-names .tm-item-name:not([hidden]) {
  display: block;
}

.tm .tm-undo,
.tm .tm-redo {
  min-width: 44px;
  padding-right: 0;
  padding-left: 0;
  font-size: 18px;
}

.tm .tm-selection-name {
  flex: 1 1 160px;
  min-width: 0;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--tm-border);
  border-radius: var(--tm-radius);
  background: var(--tm-input);
  color: var(--tm-text);
  font: inherit;
}

.tm .tm-pool-block {
  margin-top: 16px;
}

.tm .tm-pool-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.tm .tm-pool-title {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
}

.tm .tm-pool-count,
.tm .tm-pool-empty,
.tm .tm-note,
.tm .tm-export-status,
.tm .tm-export-note {
  margin: 0;
  color: var(--tm-muted);
  font-size: 12px;
}

.tm .tm-pool-empty {
  margin-top: 8px;
}

.tm .tm-move-hint {
  margin: 0 0 8px;
  color: var(--tm-muted);
  font-size: 12px;
}

.tm .tm-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
}

.tm .tm-reset-choices {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.tm .tm-reset-prompt {
  flex-basis: 100%;
  margin: 0;
  font-size: 14px;
  color: var(--tm-muted);
}

.tm .tm-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 8px 16px;
  border: 1px solid transparent;
  border-radius: var(--tm-radius);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.tm .tm-btn-primary {
  background: var(--tm-primary);
  color: #ffffff;
}

.tm .tm-btn-primary:hover {
  background: var(--tm-primary-dark);
}

.tm .tm-btn-ghost {
  border-color: var(--tm-border);
  background: var(--tm-btn);
  color: var(--tm-text);
}

.tm .tm-btn-ghost:hover {
  border-color: var(--tm-primary);
}

.tm .tm-btn-danger {
  border-color: var(--tm-danger);
  background: var(--tm-btn);
  color: var(--tm-danger);
}

.tm .tm-btn-danger:hover {
  background: var(--tm-danger);
  color: #ffffff;
}

.tm .tm-section {
  margin-top: 16px;
  padding: 16px;
  border-radius: var(--tm-radius);
  background: var(--tm-card);
  box-shadow: var(--tm-shadow-1);
}

.tm .tm-add-images {
  margin-bottom: 12px;
}

.tm .tm-file {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  border: 0;
  white-space: nowrap;
}

.tm .tm-file-label {
  position: relative;
}

.tm .tm-file:focus-visible + .tm-file-text,
.tm .tm-file-label:focus-within {
  outline: 2px solid var(--tm-primary);
  outline-offset: 2px;
}

.tm .tm-note {
  margin-top: 8px;
}

.tm .tm-add-text {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tm .tm-textarea {
  width: 100%;
  min-height: 88px;
  padding: 8px 12px;
  border: 1px solid var(--tm-border);
  border-radius: var(--tm-radius);
  background: var(--tm-input);
  color: var(--tm-text);
  font-family: inherit;
  font-size: 16px;
  resize: vertical;
}

.tm .tm-pool-count {
  margin-left: auto;
}

.tm .tm-add-toggle {
  min-height: 36px;
  padding: 4px 12px;
}

.tm .tm-pool-block .tm-add {
  margin-top: 12px;
}

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

.tm .tm-add-text-btn {
  align-self: flex-start;
}

.tm .tm-export-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.tm .tm-watermark-toggle,
.tm .tm-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 4px 8px;
  border-radius: var(--tm-radius);
  color: var(--tm-muted);
  font-size: 12px;
  cursor: pointer;
}

.tm .tm-check input,
.tm .tm-watermark-check {
  width: 20px;
  height: 20px;
  margin: 0;
  accent-color: var(--tm-primary);
}

.tm .tm-watermark {
  display: none;
  position: absolute;
  right: 12px;
  bottom: 4px;
  margin: 0;
  color: var(--tm-muted);
  font-size: 12px;
}

.tm .tm-export-preview {
  display: block;
  width: 100%;
  max-width: 100%;
  margin-top: 12px;
  border-radius: var(--tm-radius);
  box-shadow: var(--tm-shadow-1);
}

.tm .tm-export-note {
  margin-top: 8px;
}

.tm .tm-selection {
  position: sticky;
  bottom: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
  padding: 12px;
  border-radius: var(--tm-radius);
  background: var(--tm-card);
  box-shadow: var(--tm-shadow-2);
}

.tm .tm-selection-label {
  flex: 1 1 auto;
  min-width: 0;
  color: var(--tm-muted);
  font-size: 12px;
}

.tm .tm-toast {
  margin: 12px 0 0;
  padding: 8px 12px;
  border-radius: var(--tm-radius);
  background: var(--tm-toast-bg);
  color: var(--tm-toast-text);
  font-size: 12px;
}

.tm .tm-sheet.tm-capturing .tm-tier-panel {
  display: none;
}

.tm .tm-sheet.tm-capturing .tm-item.tm-selected {
  outline: 0;
}

.tm .tm-sheet.tm-capturing .tm-title-input {
  border-bottom-color: transparent;
}

.tm .tm-sheet.tm-capturing.tm-mark {
  padding-bottom: 24px;
}

.tm .tm-sheet.tm-capturing.tm-mark .tm-watermark {
  display: block;
}

.tm [hidden] {
  display: none;
}

@media (min-width: 641px) {
  .tm {
    padding: 24px;
  }

  .tm .tm-cell {
    flex-basis: 88px;
  }

  .tm .tm-tier-panel {
    left: 88px;
  }

  .tm .tm-zone {
    min-height: 72px;
    padding: 8px;
  }

  .tm .tm-item {
    width: 72px;
    height: 72px;
  }

  .tm .tm-item-text {
    font-size: 14px;
  }

  .tm .tm-title-input {
    font-size: 20px;
  }
}

@media (prefers-color-scheme: dark) {
  .tm {
    --tm-bg: #0b1220;
    --tm-card: #131c2b;
    --tm-text: #e8eef7;
    --tm-muted: #94a3b8;
    --tm-border: #2c3a4f;
    --tm-line: #26313f;
    --tm-zone: #0f1728;
    --tm-item: #1b2637;
    --tm-input: #16202f;
    --tm-btn: #1b2637;
    --tm-focus: #60a5fa;
    --tm-toast-bg: #e8eef7;
    --tm-toast-text: #0b1220;
  }
}

.tm .tm-size {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}

.tm .tm-size-label {
  margin-right: 4px;
  color: var(--tm-muted);
  font-size: 12px;
}

.tm .tm-size-btn {
  min-width: 36px;
  min-height: 36px;
  padding: 4px 8px;
}

.tm .tm-size-btn[aria-pressed="true"] {
  border-color: var(--tm-primary);
  color: var(--tm-primary);
}

.tm .tm-paste-note {
  display: none;
  margin-top: 4px;
}

.tm .tm-xpanel {
  margin-top: 12px;
  padding: 16px;
  border: 1px solid var(--tm-line);
  border-radius: var(--tm-radius);
  background: var(--tm-card);
  box-shadow: var(--tm-shadow-2, 0 8px 24px rgba(0, 0, 0, 0.08));
}

.tm .tm-xpanel-head {
  display: flex;
  align-items: center;
  gap: 12px;
}

.tm .tm-xpanel-thumb {
  width: 64px;
  height: 48px;
  object-fit: cover;
  border: 1px solid var(--tm-line);
  border-radius: 4px;
}

.tm .tm-xpanel-photo .tm-xpanel-head {
  flex-direction: column;
  align-items: flex-start;
}

.tm .tm-xpanel-photo .tm-xpanel-thumb {
  order: 2;
  width: 100%;
  height: auto;
  -webkit-touch-callout: default;
}

.tm .tm-xpanel-title {
  margin: 0;
  color: var(--tm-text);
  font-size: 16px;
  font-weight: 700;
}

.tm .tm-xpanel-steps {
  margin: 12px 0;
  padding-left: 24px;
  color: var(--tm-text);
  font-size: 14px;
  line-height: 1.7;
}

.tm .tm-xpanel-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.tm.tm-size-s .tm-item {
  width: 44px;
  height: 44px;
  padding: 2px;
}

.tm.tm-size-s .tm-item-text {
  font-size: 10px;
}

.tm.tm-size-s .tm-zone {
  min-height: 44px;
}

.tm.tm-size-l .tm-item {
  width: 72px;
  height: 72px;
}

.tm.tm-size-l .tm-zone {
  min-height: 72px;
}

@media (hover: hover) and (pointer: fine) {
  .tm .tm-paste-note {
    display: block;
  }
}

@media (min-width: 641px) {
  .tm.tm-size-s .tm-item {
    width: 56px;
    height: 56px;
  }

  .tm.tm-size-s .tm-item-text {
    font-size: 12px;
  }

  .tm.tm-size-s .tm-zone {
    min-height: 56px;
  }

  .tm.tm-size-l .tm-item {
    width: 96px;
    height: 96px;
  }

  .tm.tm-size-l .tm-item-text {
    font-size: 16px;
  }

  .tm.tm-size-l .tm-zone {
    min-height: 96px;
  }
}
