﻿:root {
  --bg: #020617;
  --bg-soft: #030712;
  --card-bg: #020617;
  --card-border: rgba(148, 163, 184, 0.35);
  --accent: #38bdf8;
  --accent-soft: rgba(56, 189, 248, 0.16);
  --accent-strong: #0ea5e9;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --danger: #f97373;
  --radius-card: 18px;
  --radius-pill: 999px;
  --shadow-card: 0 18px 40px rgba(15, 23, 42, 0.85);
  --shadow-soft: 0 12px 24px rgba(15, 23, 42, 0.8);
  --tap-size: 44px;
  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  font-family: var(--font-sans);
  background: radial-gradient(circle at top, #1e293b, #020617 55%);
  color: var(--text);
  height: 100%;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
}

body.modal-open {
  overflow: hidden;
}

/* Root app shell */

.app-root {
  min-height: 100vh;
  min-height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

/* Status bar */

.status-bar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0.35rem 0.85rem 0.2rem;
  font-size: 0.78rem;
  color: var(--muted);
  gap: 0.3rem;
}

.status-left {
  justify-self: flex-start;
}

.status-center {
  justify-self: center;
}

.status-right {
  justify-self: flex-end;
}

.status-title {
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 0.7rem;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-pill);
  padding: 0.18rem 0.55rem;
  border: 1px solid rgba(148, 163, 184, 0.35);
  background: rgba(15, 23, 42, 0.85);
}

.pill-small {
  font-size: 0.7rem;
}

/* Views wrapper */

.views {
  flex: 1;
  position: relative;
  padding: 0.5rem 0.75rem 1.2rem;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.view {
  display: none;
  min-height: 0;
}

.view.is-active {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

/* HOME VIEW */

.home-top {
  padding: 0.7rem 0.2rem 0.2rem;
}

.home-greeting {
  margin: 0 0 0.1rem;
  font-size: 1.25rem;
}

.home-subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

/* App grid */

.app-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.8rem;
  margin-top: 1rem;
}

.app-icon {
  border: none;
  padding: 0;
  background: none;
  color: inherit;
  text-align: center;
  cursor: pointer;
}

.app-icon-inner {
  width: 64px;
  height: 64px;
  margin: 0 auto 0.35rem;
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  box-shadow: var(--shadow-soft);
  border: 1px solid rgba(148, 163, 184, 0.4);
  background: radial-gradient(circle at top left, rgba(56, 189, 248, 0.32), rgba(15, 23, 42, 0.98));
}

.app-icon-knitting {
  background: radial-gradient(circle at top left, rgba(56, 189, 248, 0.32), rgba(22, 163, 74, 0.95));
}

.app-icon-label {
  display: block;
  font-size: 0.82rem;
}

.app-icon-sub {
  display: block;
  font-size: 0.7rem;
  color: var(--muted);
}

.app-icon-disabled .app-icon-inner {
  opacity: 0.35;
}

.app-icon-disabled .app-icon-label,
.app-icon-disabled .app-icon-sub {
  opacity: 0.5;
}

/* Project icons inside knitting home */

.app-icon-project .app-icon-inner {
  background: radial-gradient(circle at top left, rgba(56, 189, 248, 0.28), rgba(22, 163, 74, 0.9));
}

.app-icon-add-project .app-icon-inner {
  background: radial-gradient(circle at top left, rgba(22, 163, 74, 0.4), rgba(15, 23, 42, 0.98));
}

/* KNITTING APP */

.app-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.2rem 0.1rem 0.7rem;
}

.back-button {
  border-radius: var(--radius-pill);
  border: 1px solid rgba(148, 163, 184, 0.4);
  background: rgba(15, 23, 42, 0.85);
  color: var(--text);
  padding: 0.25rem 0.7rem;
  font-size: 0.82rem;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}

.app-header-title {
  font-weight: 600;
  font-size: 0.98rem;
}

/* App content */

.app-content {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  padding-bottom: 1rem;
}

/* Cards */

.card {
  background: linear-gradient(to bottom right, rgba(15, 23, 42, 0.92), rgba(15, 23, 42, 0.98));
  border-radius: var(--radius-card);
  border: 1px solid var(--card-border);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

.card-tight .card-body {
  padding-top: 0.7rem;
}

.card-header {
  padding: 0.7rem 0.8rem 0.4rem;
  border-bottom: 1px solid rgba(148, 163, 184, 0.28);
}

.card-title {
  margin: 0;
  font-size: 0.98rem;
}

.card-subtitle {
  margin: 0.2rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.card-body {
  padding: 0.8rem 0.8rem 0.8rem;
}

/* Fields */

.field {
  display: block;
  margin-bottom: 0.6rem;
}

.field-label {
  display: block;
  font-size: 0.8rem;
  margin-bottom: 0.18rem;
}

.field-help {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 0.22rem;
}

.field-input,
.field-textarea,
select.field-input {
  width: 100%;
  border-radius: 10px;
  border: 1px solid rgba(148, 163, 184, 0.5);
  background: rgba(15, 23, 42, 0.95);
  color: var(--text);
  padding: 0.4rem 0.5rem;
  font-size: 0.88rem;
  outline: none;
}

.field-input:focus,
.field-textarea:focus,
select.field-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.5);
}

.field-textarea {
  resize: vertical;
}

/* Buttons */

.btn-primary,
.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 0.9rem;
  border-radius: var(--radius-pill);
  border: 1px solid transparent;
  font-size: 0.9rem;
  cursor: pointer;
}

.btn-primary {
  background: linear-gradient(135deg, #0ea5e9, #22c55e);
  color: white;
  box-shadow: 0 14px 30px rgba(8, 47, 73, 0.9);
}

.btn-primary:active {
  transform: translateY(1px);
  box-shadow: 0 8px 20px rgba(8, 47, 73, 0.8);
}

.btn-secondary {
  background: rgba(15, 23, 42, 0.9);
  color: var(--muted);
  border-color: rgba(148, 163, 184, 0.5);
}

.btn-secondary:active {
  transform: translateY(1px);
}

.btn-sm {
  padding: 0.3rem 0.7rem;
  font-size: 0.78rem;
}

.btn-danger {
  border-color: rgba(248, 113, 113, 0.5);
  color: #fecaca;
}

.btn-danger:hover {
  border-color: rgba(248, 113, 113, 0.8);
  color: #fee2e2;
}

/* Round buttons for counter */

.btn-round {
  min-width: var(--tap-size);
  min-height: var(--tap-size);
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.6);
  background: radial-gradient(circle at top left, rgba(56, 189, 248, 0.3), rgba(15, 23, 42, 0.98));
  color: var(--text);
  font-size: 1.6rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-soft);
}

/* Bigger, responsive buttons inside the main counter box */
.knitting-main-card .btn-round {
  width: clamp(3.5rem, 14vh, 7rem);
  height: clamp(3.5rem, 14vh, 7rem);
  font-size: clamp(2.5rem, 7vh, 4rem);
}

/* Row counter layout */
.row-counter-main {
  /* 2×2 grid:
     row 1: number (full width)
     row 2: minus (left), plus (right) */
  display: grid;
  grid-template-rows: 1fr 1fr;
  grid-template-columns: 1fr 1fr;
  align-items: center;
  justify-items: center;
  height: 100%;
  gap: 0.2rem; /* a bit tighter so more space goes to content */
}

.row-counter-display {
  grid-row: 1;
  grid-column: 1 / span 2;
  text-align: center;
}

.btn-round[data-action="row-decrement"] {
  grid-row: 2;
  grid-column: 1;
}

.btn-round[data-action="row-increment"] {
  grid-row: 2;
  grid-column: 2;
}

.row-counter-label {
  display: block;
  font-size: 1rem;
  color: var(--muted);
  margin-bottom: 0.3rem;
}

/* BIG, responsive number */
.row-counter-number {
  font-size: clamp(4rem, 18vh, 9rem);
  font-variant-numeric: tabular-nums;
  color: var(--text);
}


/* Color change when shaping is active on this row */
.row-counter-number--increase {
  color: #22c55e;
}

.row-counter-number--decrease {
  color: var(--danger);
}

.row-counter-actions {
  margin-top: 0.6rem;
  text-align: center;
}

.row-counter-meta {
  margin-top: 0.6rem;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem;
}

.meta-item {
  font-size: 0.8rem;
}

.meta-label {
  display: block;
  color: var(--muted);
  margin-bottom: 0.1rem;
}

.meta-value {
  font-variant-numeric: tabular-nums;
}

/* Project actions row */

.project-actions-row {
  display: flex;
  gap: 0.4rem;
  padding: 0 0.1rem;
}

.project-danger-row {
  margin-top: 0.8rem;
  text-align: right;
}

/* Rule form */

.rule-form {
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.8);
  padding: 0.6rem;
  margin-bottom: 0.2rem;
}

.rule-form-row {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.rule-form-row-two,
.rule-form-row-three {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.4rem;
}

.rule-form-row-three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.rule-form-actions {
  margin-top: 0.5rem;
  text-align: right;
}

/* Rules list */

.rules-list-wrapper {
  margin-top: 0.4rem;
}

.rules-heading {
  margin: 0 0 0.3rem;
  font-size: 0.9rem;
}

.rules-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.rule-item {
  border-radius: 10px;
  border: 1px solid rgba(148, 163, 184, 0.5);
  padding: 0.45rem 0.55rem;
  margin-bottom: 0.4rem;
  background: rgba(15, 23, 42, 0.85);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.3rem;
}

.rule-main {
  font-size: 0.8rem;
}

.rule-name {
  font-weight: 500;
}

.rule-summary {
  color: var(--muted);
  display: block;
  margin-top: 0.1rem;
}

.rule-delete-btn {
  border: none;
  background: none;
  color: var(--muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0.2rem 0.25rem;
}

.rule-delete-btn:hover {
  color: var(--danger);
}

/* This row actions */

.this-row-actions {
  font-size: 0.85rem;
}

.this-row-actions strong {
  color: var(--accent-strong);
}

.muted-text {
  color: var(--muted);
  font-size: 0.8rem;
}

/* Modals */

.modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 40;
}

.modal.is-open {
  display: flex;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.8);
  backdrop-filter: blur(4px);
}

.modal-dialog {
  position: relative;
  z-index: 41;
  width: 100%;
  max-width: 420px;
  margin: 0 1rem;
  background: linear-gradient(to bottom right, rgba(15, 23, 42, 0.98), rgba(15, 23, 42, 1));
  border-radius: 18px;
  border: 1px solid rgba(148, 163, 184, 0.4);
  box-shadow: var(--shadow-card);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}

.modal-header {
  padding: 0.7rem 0.9rem 0.5rem;
  border-bottom: 1px solid rgba(148, 163, 184, 0.35);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
}

.modal-title {
  margin: 0;
  font-size: 0.98rem;
}

.modal-close {
  border: none;
  background: none;
  color: var(--muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0.2rem;
}

.modal-body {
  padding: 0.8rem 0.9rem 0.4rem;
  overflow-y: auto;
}

.modal-footer {
  padding: 0.5rem 0.9rem 0.7rem;
  border-top: 1px solid rgba(148, 163, 184, 0.35);
  display: flex;
  justify-content: flex-end;
  gap: 0.4rem;
}

.modal-footer-inline {
  display: flex;
  justify-content: flex-end;
  gap: 0.4rem;
}

/* Responsive tweaks */

@media (max-width: 360px) {
  .app-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .row-counter-main {
    gap: 0.25rem;
  }
}

/* Flappy Bird layout */

.flappy-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
}

.flappy-wrapper canvas {
  max-width: 100%;
  border-radius: 16px;
  border: 1px solid rgba(148, 163, 184, 0.5);
  box-shadow: var(--shadow-soft);
  background: #0f172a;
}

.flappy-ui {
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  align-items: center;
}

.flappy-score-row {
  width: 100%;
  display: flex;
  justify-content: space-between;
  font-size: 0.86rem;
}

/* --- Full-height layout for knitting project using GRID --- */

.app-content-full {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-rows: 13fr 3fr 1fr; /* ≈ 75% / 20% / 5% */
  gap: 0.6rem;
}

/* Top 75%: counter card */
.knitting-main-card {
  min-height: 0;
  display: flex;
}

.knitting-main-card .card-body {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  height: 100%;
}

/* Middle 20%: text card */
.knitting-text-card {
  min-height: 0;
  display: flex;
}

.knitting-text-card .card-body {
  display: flex;
  align-items: flex-start;
}

/* This row area inside its own card now */
.knitting-this-row-block {
  margin: 0;
  padding: 0.4rem 0 0;
  border-top: none;
  width: 100%;
}

/* Bottom 5%: bottom bar with the three small buttons */
.knitting-bottom-bar {
  display: flex;
  gap: 0.4rem;
  padding: 0 0.1rem 0.1rem;
  justify-content: space-between;
  align-items: center;
}
