/* Distraction-free lines writing — full-screen WritingView */
.w-shell--embedded {
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 1rem 1.25rem calc(1.25rem + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  min-height: 100%;
  height: 100%;
  box-sizing: border-box;
  background: transparent;
}

.w-shell {
  width: min(100%, 640px);
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.w-header {
  text-align: center;
  flex-shrink: 0;
}

.w-close {
  position: absolute;
  top: 0;
  right: 0;
  border: none;
  background: transparent;
  color: #6b6b88;
  font-size: 1.75rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
}

.w-close:disabled {
  opacity: 0.4;
  cursor: wait;
}

.w-eyebrow {
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #6b6b88;
  margin: 0 0 0.35rem;
}

.w-title {
  font-family: "Playfair Display", Georgia, serif;
  font-size: clamp(1.35rem, 4vw, 1.75rem);
  font-weight: 600;
  color: #f4f4fa;
  margin: 0;
  line-height: 1.25;
}

.w-reps {
  margin: 0.5rem 0 0;
  font-size: 0.85rem;
  color: #9898b8;
}

.w-target {
  background: linear-gradient(
    135deg,
    color-mix(in srgb, var(--view-primary, #a88938) 6%, transparent),
    rgba(255, 255, 255, 0.015)
  );
  border: 1px solid color-mix(in srgb, var(--view-primary, #a88938) 14%, transparent);
  border-radius: 14px;
  padding: 1.25rem 1.35rem;
  text-align: center;
}

.w-target-label {
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #6b6b88;
  margin: 0 0 0.75rem;
}

.w-target-phrase {
  margin: 0;
  font-family: "Playfair Display", Georgia, serif;
  font-size: clamp(1.1rem, 3.5vw, 1.45rem);
  font-weight: 600;
  color: #ffffff;
  line-height: 1.45;
  quotes: none;
  user-select: none;
  -webkit-user-select: none;
}

/* Step-by-step build guide */
.w-guide {
  background: linear-gradient(
    135deg,
    color-mix(in srgb, var(--view-primary, #c9a86c) 14%, transparent),
    rgba(255, 255, 255, 0.02)
  );
  border: 1px solid color-mix(in srgb, var(--view-primary, #c9a86c) 28%, transparent);
  border-radius: 16px;
  padding: 1rem 1.1rem;
  text-align: center;
}

.w-guide-kicker {
  margin: 0 0 0.35rem;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--view-primary, #c9a86c);
}

.w-guide-title {
  margin: 0 0 0.5rem;
  font-family: "DM Sans", system-ui, sans-serif;
  font-size: clamp(1.05rem, 4.5vw, 1.25rem);
  font-weight: 700;
  color: #f8f8ff;
  line-height: 1.35;
}

.w-guide-next {
  margin: 0 0 0.35rem;
  font-size: 1rem;
  color: #d8d8ec;
}

.w-guide-next strong {
  color: #fff;
  font-size: 1.15em;
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--view-primary, #c9a86c) 55%, transparent);
  text-underline-offset: 0.15em;
}

.w-guide-reps {
  margin: 0;
  font-size: 0.82rem;
  color: #9898b8;
}

.w-phrase-ref {
  border: 1px solid #252540;
  border-radius: 12px;
  background: #0e0e18;
  padding: 0.35rem 0.85rem 0.85rem;
}

.w-phrase-ref summary {
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 600;
  color: #9898b8;
  padding: 0.45rem 0;
  list-style: none;
}

.w-phrase-ref summary::-webkit-details-marker {
  display: none;
}

.w-phrase-ref .w-target-phrase {
  font-size: clamp(0.95rem, 3.8vw, 1.15rem);
  text-align: center;
}

.w-progress-compact {
  flex-shrink: 0;
}

.w-build-tiles-label {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--view-primary, #c9a86c);
  text-align: center;
}

.w-build-slot--next {
  border-color: var(--view-primary, #c9a86c);
  border-style: solid;
  color: var(--view-primary, #c9a86c);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--view-primary, #c9a86c) 25%, transparent);
}

.w-build-tile--next {
  border-color: var(--view-primary, #c9a86c);
  background: color-mix(in srgb, var(--view-primary, #c9a86c) 22%, #141422);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--view-primary, #c9a86c) 35%, transparent),
    0 4px 14px color-mix(in srgb, var(--view-primary, #c9a86c) 18%, transparent);
  transform: scale(1.02);
}

.w-performance--desktop {
  display: block;
}

/* Mobile-first build layout — fixed viewport, tiles scroll inside stage only */
.w-shell--build {
  box-sizing: border-box;
}

.w-build-header {
  flex-shrink: 0;
  background: linear-gradient(
    135deg,
    color-mix(in srgb, var(--view-primary, #c9a86c) 12%, transparent),
    rgba(255, 255, 255, 0.02)
  );
  border: 1px solid color-mix(in srgb, var(--view-primary, #c9a86c) 22%, transparent);
  border-radius: 14px;
  padding: 0.65rem 0.75rem;
}

.w-build-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.35rem;
}

.w-build-header-progress {
  flex: 1;
  min-width: 0;
}

.w-build-header-progress .w-progress-wrap {
  margin-bottom: 0.2rem;
}

.w-build-header-progress .w-progress-text {
  margin: 0;
  font-size: 0.75rem;
}

.w-build-header-reps {
  margin: 0;
  flex-shrink: 0;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--view-primary, #c9a86c);
}

.w-build-header-title,
.w-build-header-phase {
  margin: 0.15rem 0 0;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--view-primary, #c9a86c);
}

.w-build-header-hint {
  margin: 0 0 0.2rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: #d8d8ec;
}

.w-build-header-next {
  margin: 0;
  font-size: 1.05rem;
  color: #f4f4fa;
}

.w-build-header-next strong {
  color: #fff;
  font-size: 1.15em;
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--view-primary, #c9a86c) 55%, transparent);
  text-underline-offset: 0.12em;
}

.w-build-header-memory {
  margin: 0 0 0.2rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: #d8d8ec;
}

.w-build-header--guided-collapsed .w-build-header-phase,
.w-build-header--guided-collapsed .w-build-header-hint {
  display: none;
}

.w-build-header--guided-collapsed {
  padding-bottom: 0.45rem;
}

.w-build-stage {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  overflow: hidden;
}

.w-build-stage.w-build-shake {
  animation: w-build-shake 0.45s ease;
}

.w-build-dock {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding-top: 0.15rem;
}

.w-dock-hint {
  margin: 0;
  font-size: 0.78rem;
  color: #9898b8;
  text-align: center;
}

.w-build-dock .w-phrase-ref {
  padding: 0.25rem 0.55rem 0.45rem;
}

.w-build-dock .w-completed-count {
  text-align: center;
}

.w-build-dock .w-btn {
  width: 100%;
  min-height: 48px;
  margin-top: 0.15rem;
}

.w-build-dock .w-btn:not(.w-btn--ready) {
  display: none;
}

.writing-lines-card-action {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--view-primary, #c4a055);
  margin-top: 0.15rem;
}

/* Word-tile build mode */
.w-build-section {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  flex: 1;
  min-height: 0;
}

.w-build-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: #c9c9e0;
  margin: 0;
}

.w-build-slots {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  min-height: 2rem;
}

.w-build-slot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2rem;
  min-height: 2rem;
  padding: 0.25rem 0.5rem;
  border-radius: 8px;
  border: 1px dashed #3a3a5c;
  color: #6b6b88;
  font-size: 0.75rem;
  font-weight: 600;
}

.w-build-slot--filled {
  border-style: solid;
  border-color: color-mix(in srgb, var(--view-primary, #c9a86c) 40%, transparent);
  background: color-mix(in srgb, var(--view-primary, #c9a86c) 12%, transparent);
  color: #f0f0f8;
  font-size: 0.85rem;
  font-weight: 600;
}

.w-build-tiles {
  display: grid;
  grid-template-columns: repeat(var(--w-tile-cols, 2), minmax(0, 1fr));
  grid-auto-rows: minmax(0, 1fr);
  gap: 0.5rem;
  justify-content: center;
  padding: 0.25rem 0;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

.w-build-tile {
  min-height: 0;
  height: 100%;
  width: 100%;
  padding: 0.5rem 0.55rem;
  border-radius: 12px;
  border: 1px solid color-mix(in srgb, var(--view-primary, #c9a86c) 35%, transparent);
  background: #141422;
  color: #f4f4fa;
  font-size: clamp(0.95rem, 4.2vw, 1.28rem);
  font-weight: 600;
  line-height: 1.25;
  cursor: pointer;
  transition: transform 0.1s, background 0.15s, border-color 0.15s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
  text-overflow: ellipsis;
}

.writing-host {
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
}

.writing-idle {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  min-height: 40vh;
  text-align: center;
  color: var(--text-muted, #9898b8);
  padding: 1.5rem 1rem;
}

.writing-idle h2 {
  font-family: "Playfair Display", Georgia, serif;
  color: var(--view-primary, #c4a055);
  font-size: 1.2rem;
  margin: 0;
}

.writing-idle p {
  margin: 0;
  font-size: 0.92rem;
  line-height: 1.45;
  max-width: 22rem;
}

.w-build-tile:hover:not(:disabled),
.w-build-tile:focus-visible:not(:disabled) {
  background: color-mix(in srgb, var(--view-primary, #c9a86c) 18%, #141422);
  border-color: var(--view-primary, #c9a86c);
}

.w-build-tile:active:not(:disabled) {
  transform: scale(0.96);
}

.w-build-tile:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.w-build-shake {
  animation: w-build-shake 0.45s ease;
}

@keyframes w-build-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

.w-section-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: #c9c9e0;
  margin: 0 0 0.75rem;
}

.w-performance {
  background: #0e0e18;
  border-radius: 14px;
  padding: 1rem 1.1rem;
  border: 1px solid #1e1e32;
}

.w-progress-wrap {
  height: 6px;
  background: #1a1a2e;
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 0.4rem;
}

.w-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, #8a7348, #c9a86c);
  border-radius: 3px;
  transition: width 0.15s ease;
}

.w-progress-text {
  font-size: 0.78rem;
  color: #9898b8;
  margin: 0 0 1rem;
}

.w-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.65rem;
}

@media (min-width: 480px) {
  .w-stats { grid-template-columns: repeat(4, 1fr); }
}

.w-stat {
  background: #141422;
  border: 1px solid #252540;
  border-radius: 10px;
  padding: 0.65rem 0.5rem;
  text-align: center;
}

.w-stat-val {
  display: block;
  font-size: 1.35rem;
  font-weight: 600;
  color: #f0f0f8;
  line-height: 1.2;
}

.w-stat-label {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  color: #b8b8d0;
  margin-top: 0.15rem;
}

.w-stat-sub {
  display: block;
  font-size: 0.62rem;
  color: #6b6b88;
  margin-top: 0.1rem;
}

.w-input-section {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.w-input-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: #c9c9e0;
}

.w-completed-count {
  font-size: 0.78rem;
  color: #7ec99a;
  margin: 0;
}

.w-input {
  width: 100%;
  min-height: 0;
  padding: 1rem 1.1rem;
  background: #11111c;
  border: 2px solid #2a2a42;
  border-radius: 12px;
  color: #f4f4fa;
  font-family: "DM Sans", ui-monospace, monospace;
  font-size: clamp(1.05rem, 3.8vw, 1.25rem);
  line-height: 1.55;
  outline: none;
  transition: border-color 0.15s;
  box-sizing: border-box;
}

.w-input:focus {
  border-color: #c9a86c;
}

.w-input:disabled {
  opacity: 0.6;
}

.w-footer {
  display: flex;
  justify-content: center;
  flex-shrink: 0;
  padding: 0.75rem 0 calc(0.5rem + env(safe-area-inset-bottom, 0px));
}

@media (max-width: 480px) {
  .w-shell--embedded {
    flex: 1;
    min-height: 0;
    height: 100%;
    max-height: 100%;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    padding: 0.15rem 0.1rem 0.2rem;
    touch-action: manipulation;
  }

  .w-shell--embedded.w-shell--build {
    padding-bottom: 0.15rem;
  }

  .w-guide,
  .w-progress-compact,
  .w-footer {
    display: none;
  }

  .w-build-header {
    padding: 0.5rem 0.65rem;
    border-radius: 12px;
  }

  .w-build-header-phase,
  .w-build-header-hint,
  .w-build-header-memory {
    display: none;
  }

  .w-build-header--guided-collapsed {
    padding: 0.4rem 0.55rem;
  }

  .w-build-header-row {
    margin-bottom: 0.2rem;
  }

  .w-build-header-progress .w-progress-text {
    font-size: 0.85rem;
  }

  .w-build-header-reps {
    font-size: 0.9rem;
  }

  .w-build-header-next {
    font-size: clamp(1.2rem, 5vw, 1.45rem);
    margin-top: 0.15rem;
    line-height: 1.3;
  }

  .w-build-slots {
    display: none;
  }

  .w-build-stage {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    gap: 0.35rem;
  }

  .w-build-tiles {
    gap: 0.5rem;
    overflow: hidden;
    overscroll-behavior: none;
  }

  .w-build-tile {
    min-height: 0;
    border-radius: 12px;
    font-size: clamp(1rem, 4.6vw, 1.32rem);
    line-height: 1.28;
    padding: 0.55rem 0.5rem;
  }

  .w-build-tile--next {
    transform: none;
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--view-primary, #c9a86c) 45%, transparent);
  }

  .w-build-dock {
    gap: 0.25rem;
    padding-top: 0;
  }

  .w-dock-hint {
    display: none;
  }

  /* Progress lives in the header — drop dock status text on phones */
  .w-build-dock .w-completed-count {
    display: none;
  }

  /* Guided already shows the next word — hide phrase chrome. Keep peek for unguided. */
  .w-shell--guided .w-build-dock .w-phrase-ref {
    display: none;
  }

  .w-shell--unguided .w-build-dock .w-phrase-ref {
    padding: 0.2rem 0.5rem 0.35rem;
  }

  .w-shell--unguided .w-build-dock .w-phrase-ref summary {
    font-size: 0.8rem;
    padding: 0.3rem 0;
  }

  .w-build-dock .w-btn--ready {
    display: block;
    min-height: 52px;
    font-size: 1.05rem;
  }

  .w-performance--desktop {
    display: none;
  }
}

/* Active Lines session (Games host): keep phrase peek for unguided only via header */
body.lines-build-active .w-performance--desktop {
  display: none;
}

@media (min-width: 481px) {
  .w-build-dock .w-btn:not(.w-btn--ready) {
    display: inline-flex;
    opacity: 0.55;
  }

  .w-build-stage {
    min-height: 220px;
  }

  .w-build-tiles {
    max-height: min(42vh, 360px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    grid-auto-rows: auto;
  }

  .w-build-tile {
    min-height: 52px;
    height: auto;
    font-size: clamp(1rem, 2.2vw, 1.2rem);
  }

  /* When Lines fills the Games view, let tiles use the full stage */
  body.lines-build-active .w-build-tiles,
  #view-games.lines-stage-open .w-build-tiles {
    max-height: none;
    flex: 1;
    overflow: hidden;
    grid-auto-rows: minmax(0, 1fr);
  }

  body.lines-build-active .w-build-tile,
  #view-games.lines-stage-open .w-build-tile {
    height: 100%;
    min-height: 0;
  }

  body.lines-build-active .w-shell--guided .w-build-dock .w-phrase-ref,
  #view-games.lines-stage-open .w-shell--guided .w-build-dock .w-phrase-ref {
    display: none;
  }

  body.lines-build-active .w-dock-hint,
  #view-games.lines-stage-open .w-dock-hint {
    display: none;
  }

  body.lines-build-active .w-build-dock .w-completed-count,
  #view-games.lines-stage-open .w-build-dock .w-completed-count {
    display: none;
  }
}

.w-btn {
  padding: 0.8rem 2.5rem;
  border-radius: 999px;
  border: 1px solid #3a3a5c;
  background: #1a1a2e;
  color: #9898b8;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: not-allowed;
  opacity: 0.55;
}

.w-btn--primary:not([disabled]) {
  background: #c9a86c;
  border-color: #c9a86c;
  color: #0f0f1a;
  cursor: pointer;
  opacity: 1;
}

.w-btn--primary:not([disabled]):hover {
  background: #d4b87a;
}

.w-error {
  color: #e07070;
  text-align: center;
  font-size: 0.88rem;
  margin: 0;
}

/* Task card entry point */
.action-lines-open-btn {
  width: 100%;
  padding: 0.75rem 1rem;
  border-radius: 10px;
  border: 1px solid #c9a86c;
  background: rgba(201, 168, 108, 0.12);
  color: #c9a86c;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.action-lines-open-btn:hover {
  background: rgba(201, 168, 108, 0.2);
}

.action-lines-meta {
  font-size: 0.82rem;
  color: var(--text-muted, #9898b8);
  margin: 0 0 0.65rem;
  line-height: 1.4;
}

/* Writing tab — lines assignment list */
.writing-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 0.5rem 0 1.5rem;
  min-height: 100%;
  box-sizing: border-box;
}

.writing-list-header {
  text-align: center;
  padding: 0.5rem 0.75rem 0;
}

.writing-list-header h2 {
  font-family: "Playfair Display", Georgia, serif;
  color: var(--view-primary, #c4a055);
  font-size: 1.25rem;
  margin: 0 0 0.35rem;
}

.writing-list-header p {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-muted, #9898b8);
}

.writing-lines-cards {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.writing-lines-card {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.45rem;
  width: 100%;
  padding: 1rem 1.1rem;
  border-radius: 14px;
  border: 1px solid color-mix(in srgb, var(--view-primary, #c4a055) 18%, transparent);
  background: linear-gradient(
    135deg,
    color-mix(in srgb, var(--view-primary, #c4a055) 5%, transparent),
    rgba(255, 255, 255, 0.02)
  );
  color: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}

.writing-lines-card:hover,
.writing-lines-card:focus-visible {
  border-color: color-mix(in srgb, var(--view-primary, #c4a055) 45%, transparent);
  box-shadow: 0 0 14px color-mix(in srgb, var(--view-primary, #c4a055) 12%, transparent);
}

.writing-lines-card--draft {
  border-color: color-mix(in srgb, #7ec99a 45%, transparent);
}

.writing-lines-card--active {
  border-color: color-mix(in srgb, var(--view-primary, #c4a055) 55%, transparent);
}

.writing-lines-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}

.writing-lines-card-title {
  font-weight: 600;
  font-size: 0.95rem;
  color: #f0f0f8;
  line-height: 1.3;
}

.writing-lines-card-progress {
  flex-shrink: 0;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--view-primary, #c4a055);
  letter-spacing: 0.02em;
}

.writing-lines-card-phrase {
  font-family: "Playfair Display", Georgia, serif;
  font-size: 0.92rem;
  color: #c9c9e0;
  line-height: 1.45;
  font-style: italic;
}

.writing-lines-card-action {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--view-primary, #c4a055);
  margin-top: 0.15rem;
}
