/**
 * Size It: Sort It - Single-Screen Scale Timeline Stylesheet
 * Responsive 100dvh layout with drag-and-drop & tap-to-swap mechanics.
 */

html, body {
  min-height: 100%;
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

.sort-viewport {
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.sort-editorial-wrap {
  max-width: 720px;
  width: 100%;
  margin: 36px auto 48px;
  padding: 0 16px;
  box-sizing: border-box;
}

.sort-editorial-wrap .editorial-content {
  margin-top: 0;
}

/* Header */
.sort-header {
  height: 52px;
  min-height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 50;
  flex-shrink: 0;
  gap: 12px;
  box-sizing: border-box;
}

.sort-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.sort-header .brand-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--text);
  flex-shrink: 0;
}

.sort-header .brand-icon {
  width: 28px;
  height: 28px;
  display: block;
}

.sort-header .brand-text {
  display: flex;
  flex-direction: column;
}

.sort-header .brand-title {
  font-weight: 800;
  font-size: 15px;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.sort-header .brand-badge {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  line-height: 1.1;
}

.sort-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* Game Progress Tracking (Below Header) */
.sort-sub-hud {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 4px 16px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-dim);
  background: var(--surface-raise-2);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s ease;
}

.sort-sub-hud:hover {
  background: var(--surface-raise);
}

.sort-hud-stat {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-dim);
}

.sort-hud-stat strong {
  font-size: 15px;
  font-weight: 900;
  color: var(--siu-board);
  line-height: 1;
}

.sort-hud-stat.perfect strong {
  color: #16895e;
}

html.dark .sort-hud-stat.perfect strong {
  color: #34d399;
}

/* Main Viewport Container */
.sort-main {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
  padding: 10px 14px 12px;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
  box-sizing: border-box;
}

/* Prompt Banner */
.sort-prompt-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 8px 14px;
  margin-bottom: 10px;
  flex-shrink: 0;
}

.sort-prompt-text {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 6px;
}

.sort-scale-indicator {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Sort Area Grid (Desktop: 5 columns, Mobile: 5 rows) */
.sort-slots-container,
.sort-slots {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  position: relative;
  overflow-y: auto;
}

/* Individual Item Card */
.sort-card {
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 12px 10px;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  position: relative;
  min-height: 0;
  height: 100%;
  box-sizing: border-box;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  -webkit-touch-callout: none;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.sort-card:hover {
  border-color: var(--siu-board);
  transform: translateY(-2px);
}

.sort-card:active {
  cursor: grabbing;
}

/* Tap to select state (Mobile / Desktop) */
.sort-card.selected {
  border-color: var(--siu-board);
  box-shadow: 0 0 0 3px rgba(31, 79, 142, 0.35);
  background: rgba(31, 79, 142, 0.04);
  transform: scale(1.02);
}

.sort-card.dragging {
  opacity: 0.4;
  transform: scale(0.95);
}

.sort-card.touch-dragging {
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.3);
  border-color: var(--siu-board);
  background: var(--surface-raise-2);
  opacity: 0.95;
  transition: none !important;
  will-change: transform;
}

.sort-card.drag-over {
  border-color: var(--siu-board);
  border-style: dashed;
  background: rgba(31, 79, 142, 0.08);
}

/* Card Ranking Badge */
.sort-card-pos {
  position: absolute;
  top: 8px;
  left: 8px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--surface-raise-2);
  border: 1px solid var(--line);
  font-size: 11px;
  font-weight: 800;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Arrow controls for quick reordering */
.sort-card-controls {
  position: absolute;
  top: 6px;
  right: 6px;
  display: flex;
  gap: 3px;
}

.sort-btn-move {
  touch-action: manipulation;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--surface-raise-2);
  color: var(--text-dim);
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  transition: all 0.12s ease;
}

.sort-btn-move:hover {
  background: var(--surface-raise);
  color: var(--text);
}

/* Silhouette */
.sort-card-silhouette {
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 18px 0 6px 0;
  padding: 6px;
  box-sizing: border-box;
  overflow: hidden;
}

.sort-card-silhouette svg {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  display: block;
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.1));
}

.arrow-h {
  display: inline;
}

.arrow-v {
  display: none;
}

.sort-card-name {
  font-size: 14px;
  font-weight: 800;
  color: var(--text);
  margin: 0;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
}

.sort-card-cat {
  font-size: 10px;
  color: var(--text-dim);
  margin-top: 2px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
}

/* Revealed true measurement box */
.sort-card-truth {
  width: 100%;
  margin-top: 6px;
  padding: 5px 4px;
  border-radius: var(--radius-sm);
  background: var(--surface-raise);
  border: 1px solid var(--line);
  display: none;
}

.sort-card-truth .truth-val {
  font-size: 14px;
  font-weight: 900;
  color: var(--siu-board);
  line-height: 1.1;
}

.sort-card-truth .truth-dim {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-dim);
}

/* Card status after submission */
.sort-card.correct {
  border-color: #16895e;
  background: rgba(22, 137, 94, 0.05);
}
.sort-card.correct .sort-card-pos {
  background: #16895e;
  color: #fff;
  border-color: #16895e;
}
.sort-card.incorrect {
  border-color: var(--accent);
  background: rgba(200, 50, 37, 0.05);
}
.sort-card.incorrect .sort-card-pos {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* Bottom Action Bar */
.sort-action-bar {
  margin-top: 10px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-sizing: border-box;
}

.sort-btn-submit {
  background: var(--siu-board);
  color: #fff;
  font-size: 15px;
  font-weight: 800;
  padding: 12px 32px;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  letter-spacing: 0.03em;
  box-shadow: 0 4px 12px rgba(31, 79, 142, 0.25);
  transition: all 0.15s ease;
}

.sort-btn-submit:hover:not(:disabled) {
  background: #183f73;
  transform: translateY(-1px);
}

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

/* In-Flow Result Dock (Never overlaps the cards) */
.sort-result-dock {
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  padding: 12px 18px;
  box-shadow: var(--shadow-card);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  box-sizing: border-box;
  animation: slideUp 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.sort-result-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.sort-result-title {
  font-size: 16px;
  font-weight: 900;
  line-height: 1.2;
}

.sort-result-fact {
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.45;
  margin-top: 3px;
  white-space: normal;
}

.sort-result-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.sort-btn-share {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-raise-2);
  border: 1px solid var(--line-strong);
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  padding: 9px 14px;
  border-radius: var(--radius-md);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}

.sort-btn-share:hover {
  background: var(--surface-raise);
  border-color: var(--siu-board);
}

.sort-btn-next {
  background: var(--siu-board);
  color: #fff;
  font-size: 14px;
  font-weight: 800;
  padding: 10px 18px;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 0.15s ease, transform 0.12s ease;
}

.sort-btn-next:hover {
  background: #183f73;
}

/* =========================================================================
   MOBILE VIEWPORT ADAPTATION (< 720px)
   Vertical 5-row compact stack with zero scroll.
   ========================================================================= */
@media (max-width: 720px) {
  .sort-header {
    height: 48px;
    min-height: 48px;
    padding: 0 8px;
    gap: 6px;
  }

  .sort-header-left {
    gap: 6px;
  }

  .sort-header .brand-logo {
    gap: 6px;
  }

  .sort-header .brand-icon {
    width: 24px;
    height: 24px;
  }

  .sort-header .brand-title {
    font-size: 14px;
    white-space: nowrap;
  }

  .sort-header .brand-badge {
    display: none;
  }

  .sort-header-right {
    gap: 4px;
  }

  .sort-sub-hud {
    padding: 3px 8px;
    gap: 16px;
    font-size: 11px;
  }

  .sort-hud-stat strong {
    font-size: 14px;
  }

  .sort-main {
    padding: 6px 8px 8px;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  .sort-prompt-bar {
    padding: 5px 12px;
    margin-bottom: 6px;
    min-height: 28px;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .sort-prompt-text {
    display: none;
  }

  .sort-scale-indicator {
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-dim);
    white-space: nowrap;
  }

  .sort-slots-container,
  .sort-slots {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .sort-card {
    flex-direction: row;
    align-items: center;
    padding: 4px 8px;
    border-radius: var(--radius-md);
    flex: 1 1 0%;
    min-height: 0;
    height: 0;
    gap: 8px;
    box-sizing: border-box;
  }

  .sort-card-pos {
    position: static;
    width: 22px;
    height: 22px;
    font-size: 11px;
    flex: 0 0 22px;
    flex-shrink: 0;
  }

  .sort-card-silhouette {
    margin: 0;
    padding: 2px;
    width: 48px;
    height: 48px;
    max-height: 100%;
    flex: 0 0 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    box-sizing: border-box;
  }

  .sort-card-silhouette svg {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    display: block;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.12));
  }

  .sort-card-info {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    flex: 1;
    min-width: 0;
    text-align: left;
    overflow: hidden;
  }

  .sort-card-name {
    font-size: 13px;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
    margin: 0;
    font-weight: 800;
  }

  .sort-card-cat {
    font-size: 9px;
    margin-top: 1px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
  }

  .sort-card-truth {
    margin-top: 0;
    width: auto;
    padding: 2px 6px;
    flex-shrink: 0;
    text-align: right;
    border-radius: var(--radius-sm);
  }

  .sort-card-truth .truth-val {
    font-size: 12px;
    font-weight: 900;
    line-height: 1.1;
  }

  .sort-card-truth .truth-dim {
    font-size: 8px;
    font-weight: 700;
    line-height: 1;
  }

  .sort-card-controls {
    position: static;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
    order: 5;
    margin-left: auto;
  }

  .sort-btn-move {
    width: 26px;
    height: 18px;
    font-size: 9px;
    border-radius: 4px;
  }

  .arrow-h {
    display: none;
  }

  .arrow-v {
    display: inline;
  }

  .sort-action-bar,
  .sort-action-dock {
    margin-top: 6px;
    flex-shrink: 0;
    width: 100%;
  }

  .sort-btn-submit {
    padding: 9px 20px;
    font-size: 13px;
    width: 100%;
  }

  .sort-result-dock {
    padding: 6px 10px;
    gap: 8px;
    border-radius: var(--radius-md);
  }

  .sort-result-title {
    font-size: 13px;
  }

  .sort-result-fact {
    font-size: 11px;
    line-height: 1.3;
    margin-top: 1px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .sort-result-actions {
    gap: 6px;
  }

  .sort-btn-share {
    padding: 6px 10px;
    font-size: 11px;
  }

  .sort-btn-next {
    padding: 7px 12px;
    font-size: 12px;
  }
}

@media (max-width: 480px) {
  .sort-header {
    padding: 0 6px;
    gap: 4px;
  }
  .sort-header-left {
    gap: 4px;
  }
  .sort-header .brand-logo {
    gap: 4px;
  }
  .sort-header .brand-title {
    font-size: 13px;
  }
  .sort-header-right {
    gap: 3px;
  }
}

@media (max-width: 380px) {
  .sort-header .brand-text {
    display: none;
  }
}
