/* ==========================================================================
   components.css: the shared component set.
   Buttons, form controls, tags, workspace sections, tables, meters,
   notices, dialogs, toasts and skeletons. Page CSS only arranges these.
   ========================================================================== */

/* ----- Buttons ----- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: var(--control-h);
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  background: linear-gradient(180deg, #2c2821, #1f1c17);
  box-shadow: inset 0 1px 0 rgba(255, 236, 190, 0.07), 0 1px 0 rgba(0, 0, 0, 0.45);
  color: var(--text);
  font-family: var(--font-display);
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: 0.06em;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color var(--t), border-color var(--t), color var(--t), transform var(--t);
}
.btn:hover { background: linear-gradient(180deg, #363128, #26221c); border-color: #5a5142; color: var(--text); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary { background: linear-gradient(180deg, #dcb873, #a88340); border-color: #e3c486; box-shadow: inset 0 1px 0 rgba(255, 248, 225, 0.45), 0 1px 0 rgba(0, 0, 0, 0.5); color: var(--accent-ink); font-weight: 700; }
.btn-primary:hover { background: linear-gradient(180deg, #e8c886, #b78f4a); border-color: #f0d69c; color: var(--accent-ink); }
.btn-quiet { background: transparent; border-color: transparent; box-shadow: none; color: var(--text-2); }
.btn-quiet:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { color: var(--bad); }
.btn-danger:hover { border-color: var(--bad); background: var(--bad-tint); color: var(--bad); }
.btn-sm { height: var(--control-h-sm); padding: 0 8px; font-size: var(--fs-xs); }
.btn-lg { height: 40px; padding: 0 18px; font-size: var(--fs-md); }

/* ----- Form controls ----- */
.field { display: grid; gap: 4px; min-width: 0; }
.field-label { font-size: var(--fs-xs); font-weight: 500; color: var(--text-2); }
.field-hint { font-size: var(--fs-xs); color: var(--text-3); }
.input, .select, .textarea {
  width: 100%;
  height: var(--control-h);
  padding: 0 8px;
  background: var(--bg-sunken);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  color: var(--text);
  font-size: var(--fs-sm);
  transition: border-color var(--t);
}
.textarea { height: auto; min-height: 64px; padding: 6px 8px; resize: vertical; line-height: 1.5; }
.select {
  appearance: none;
  padding-right: 26px;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-3) 50%), linear-gradient(135deg, var(--text-3) 50%, transparent 50%);
  background-position: calc(100% - 13px) 52%, calc(100% - 9px) 52%;
  background-size: 4px 4px;
  background-repeat: no-repeat;
}
.input:hover, .select:hover, .textarea:hover { border-color: #4a453f; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--accent); }
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-3); }

/* Segmented control (radio group styled as joined buttons) */
.segmented { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--r-sm); overflow: hidden; }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.segmented span {
  display: flex; align-items: center; height: calc(var(--control-h) - 2px); padding: 0 10px;
  font-size: var(--fs-sm); color: var(--text-2); background: var(--bg-sunken);
}
.segmented label + label span { border-left: 1px solid var(--line-strong); }
.segmented input:checked + span { background: var(--surface-3); color: var(--text); }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -2px; }

/* Switch */
.switch { position: relative; display: inline-flex; flex-shrink: 0; width: 34px; height: 18px; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.switch-track { width: 100%; height: 100%; background: var(--surface-3); border: 1px solid var(--line-strong); border-radius: 2px; pointer-events: none; }
.switch-track::after { content: ''; position: absolute; top: 3px; left: 3px; width: 12px; height: 12px; background: var(--text-3); border-radius: 1px; }
.switch input:checked + .switch-track { background: var(--accent-tint); border-color: var(--accent); }
.switch input:checked + .switch-track::after { left: 19px; background: var(--accent); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Stepper: [−][ 12 ][+] joined into one control */
.stepper { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--r-sm); overflow: hidden; }
.stepper button {
  width: 26px; height: 26px; border: 0; background: var(--surface-2); color: var(--text-2);
  font-family: var(--font-mono); font-size: 14px; line-height: 1; cursor: pointer;
}
.stepper button:hover:not(:disabled) { background: var(--surface-3); color: var(--text); }
.stepper button:disabled { color: var(--line-strong); cursor: not-allowed; }
.stepper input {
  width: 42px; height: 26px; border: 0; border-inline: 1px solid var(--line-strong); background: var(--bg-sunken);
  text-align: center; font-family: var(--font-mono); font-size: var(--fs-sm); -moz-appearance: textfield;
}
.stepper input:focus { outline: none; background: var(--surface); box-shadow: inset 0 0 0 1px var(--accent); }
.stepper input::-webkit-outer-spin-button, .stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* ----- Tags: small carved plaques with chamfered corners ----- */
.tag {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 9px;
  clip-path: polygon(5px 0, calc(100% - 5px) 0, 100% 5px, 100% calc(100% - 5px), calc(100% - 5px) 100%, 5px 100%, 0 calc(100% - 5px), 0 5px);
  background: linear-gradient(180deg, #332e26, #26221c);
  box-shadow: inset 0 1px 0 rgba(255, 236, 190, 0.08), inset 0 -1px 0 rgba(0, 0, 0, 0.5);
  font-family: var(--font-display);
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-2);
  white-space: nowrap;
}
.tag-warn { color: #f0c27e; background: linear-gradient(180deg, #4a3619, #33250f); }
.tag-good { color: #b7d38a; background: linear-gradient(180deg, #2f3d1f, #222c16); }
.tag-quiet { color: var(--text-3); background: linear-gradient(180deg, #24211b, #1c1a15); }
.tag-live { color: #f2d595; background: linear-gradient(180deg, #4d3d1c, #352a12); }
.tag-dev { color: var(--text-2); background: linear-gradient(180deg, #2a3326, #1f261c); }

/* ----- Workspace: a framed tool surface divided by 1px rules ----- */
.workspace { border: 1px solid var(--line-strong); border-radius: var(--r); background: var(--surface); box-shadow: inset 0 1px 0 rgba(255, 236, 190, 0.04), 0 10px 30px rgba(0, 0, 0, 0.25); min-width: 0; }
.ws-section + .ws-section { border-top: 1px solid var(--line); }
.ws-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  min-height: 38px;
  padding: 6px var(--sec-pad);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.ws-head h2, .ws-head h3 { font-size: var(--fs-xs); font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent); }
.ws-head-meta { display: flex; align-items: center; gap: var(--s-2); font-size: var(--fs-xs); color: var(--text-3); }
.ws-body { padding: var(--sec-pad); }
.ws-body > * + * { margin-top: var(--s-4); }
.sub-head { font-family: var(--font-display); font-size: var(--fs-xs); font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-3); margin-bottom: var(--s-2); }

/* ----- Data tables / row lists ----- */
.data-table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.data-table th {
  text-align: left; font-family: var(--font-display); font-size: var(--fs-xs); font-weight: 600;
  letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-3);
  padding: 6px 10px; border-bottom: 1px solid var(--line-strong);
}
.data-table td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: 0; }
.data-table .num { text-align: right; }

/* ----- Meters ----- */
.meter { position: relative; height: 3px; background: var(--surface-3); }
.meter-fill { position: absolute; inset: 0 auto 0 0; background: var(--text-3); }
.meter[data-tone='good'] .meter-fill { background: var(--good); }
.meter[data-tone='bad'] .meter-fill { background: var(--bad); }
.meter[data-tone='mid'] .meter-fill { background: var(--text-2); }
.meter-none { opacity: 0.35; }

/* ----- Notices: full border, tinted background, no side stripe ----- */
.notice { padding: 10px 12px; border: 1px solid var(--line-strong); border-radius: var(--r); background: var(--surface); font-size: var(--fs-sm); color: var(--text-2); }
.notice-warning { border-color: rgba(212, 178, 92, 0.4); background: var(--warn-tint); color: var(--text); }
.notice-error { border-color: rgba(212, 121, 94, 0.5); background: var(--bad-tint); color: var(--text); }

.empty { padding: var(--s-5); border: 1px solid var(--line); background: rgba(0, 0, 0, 0.18); border-radius: var(--r); text-align: center; color: var(--text-3); font-size: var(--fs-sm); }

/* ----- Skeleton (static, used only while a module is actually loading) ----- */
.skeleton { background: var(--surface-2); border-radius: 2px; }
.skeleton-line { height: 10px; margin-block: 8px; }

/* ----- Toasts ----- */
.toast-region { position: fixed; z-index: 100; right: var(--s-4); bottom: var(--s-4); display: grid; gap: var(--s-2); pointer-events: none; }
.toast {
  max-width: 360px;
  padding: 9px 12px;
  background: var(--surface-3);
  border: 1px solid var(--line-strong);
  border-radius: var(--r);
  font-size: var(--fs-sm);
  pointer-events: auto;
}
.toast-success { border-color: rgba(156, 185, 111, 0.5); }
.toast-warning { border-color: rgba(212, 178, 92, 0.5); }
.toast-error { border-color: rgba(212, 121, 94, 0.6); }
@media (max-width: 640px) { .toast-region { left: var(--s-4); } .toast { max-width: none; } }

/* ----- Dialog ----- */
.modal {
  width: min(560px, calc(100vw - 32px));
  max-height: min(720px, calc(100vh - 48px));
  padding: 0;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line-strong);
  border-radius: var(--r);
}
.modal-sm { width: min(420px, calc(100vw - 32px)); }
.modal::backdrop { background: rgba(6, 5, 4, 0.78); }
.modal-header { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); padding: 10px 16px; border-bottom: 1px solid var(--line); }
.modal-title { font-size: var(--fs-md); }
.modal-body { padding: 16px; }
.modal-body > .modal-title + p { margin-top: var(--s-2); }
.modal-actions { display: flex; justify-content: flex-end; gap: var(--s-2); margin-top: var(--s-5); }

/* ----- Game library rows (games page + homepage) ----- */
.game-list { list-style: none; border-top: 1px solid var(--line-strong); }
.game-row {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr) auto;
  gap: var(--s-4);
  align-items: center;
  padding-block: var(--s-3);
  border-bottom: 1px solid var(--line);
}
.game-cover { width: 96px; height: 54px; overflow: hidden; border: 1px solid var(--line-strong); border-radius: 2px; background: var(--surface-2); }
.game-cover > img, .game-cover > svg { width: 100%; height: 100%; object-fit: cover; }
.game-row.is-compact { grid-template-columns: 64px minmax(0, 1fr) auto; }
.game-row.is-compact .game-cover { width: 64px; height: 36px; }
.game-info { min-width: 0; }
.game-title { font-size: var(--fs-md); }
.game-title a { color: var(--text); }
.game-title a:hover { color: var(--game); }
.game-meta { margin-top: 2px; color: var(--game); }
.game-tagline { margin-top: 4px; max-width: 70ch; }
.game-features { margin-top: 4px; }
.game-side { display: flex; align-items: center; gap: var(--s-3); }
@media (max-width: 640px) {
  .game-row { grid-template-columns: 72px minmax(0, 1fr); align-items: start; }
  .game-row .game-cover { width: 72px; height: 40px; }
  .game-side { grid-column: 2; flex-wrap: wrap; gap: var(--s-2); }
}
