:root {
  --bg: #ffffff;
  --ink: #050505;
  --muted: #6b7280;
  --line: #d7d7d7;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html,
body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Manrope, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
  touch-action: none;
  overscroll-behavior: none;
}

button {
  font: inherit;
  cursor: pointer;
}

.pattern-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px 20px;
}

.pattern-panel {
  width: min(100%, 460px);
  text-align: center;
}

.brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-bottom: 24px;
}

.brand-mark {
  width: 56px;
  height: 56px;
  border: 2px solid var(--ink);
  display: grid;
  place-items: center;
  font-size: 24px;
  font-weight: 800;
  line-height: 1;
}

.brand-mark span {
  color: var(--muted);
}

.brand-kicker {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.24em;
  text-transform: uppercase;
}

h1 {
  font-size: 38px;
  font-weight: 800;
  letter-spacing: 0;
  margin-bottom: 8px;
}

#patternHelp {
  color: var(--muted);
  font-size: 15px;
  min-height: 24px;
}

.pattern-board {
  position: relative;
  width: min(82vw, 360px);
  aspect-ratio: 1;
  margin: 34px auto 18px;
  user-select: none;
  touch-action: none;
}

#patternCanvas,
.pattern-grid {
  position: absolute;
  inset: 0;
}

#patternCanvas {
  width: 100%;
  height: 100%;
}

.pattern-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  align-items: center;
  justify-items: center;
  padding: 9%;
}

.pattern-dot {
  width: clamp(16px, 5.2vw, 28px);
  height: clamp(16px, 5.2vw, 28px);
  border-radius: 999px;
  background: var(--ink);
  border: 0;
  transform: scale(1);
  transition: transform 120ms ease, box-shadow 120ms ease;
}

.pattern-dot.active {
  transform: scale(1.26);
  box-shadow: 0 0 0 10px rgba(0, 0, 0, 0.08);
}

.pattern-message {
  min-height: 24px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
}

.pattern-message.error {
  color: #b91c1c;
}

.pattern-message.ok {
  color: #166534;
}

.pattern-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 22px;
}

.pattern-actions button {
  min-width: 118px;
  border: 1px solid var(--ink);
  background: var(--bg);
  color: var(--ink);
  padding: 12px 18px;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.pattern-actions button:last-child {
  background: var(--ink);
  color: var(--bg);
}

.hidden {
  display: none !important;
}

@media (max-width: 480px) {
  html,
  body {
    height: 100%;
    min-height: 100svh;
    overflow: hidden;
  }

  body {
    display: block;
  }

  .pattern-shell {
    display: flex;
    min-height: 100svh;
    padding: max(10px, env(safe-area-inset-top)) 16px max(10px, env(safe-area-inset-bottom));
  }

  .pattern-panel {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    width: 100%;
  }

  .brand {
    gap: 5px;
    margin-bottom: 8px;
  }

  .brand-mark {
    height: 42px;
    width: 42px;
    font-size: 18px;
  }

  .brand-kicker {
    font-size: 10px;
    letter-spacing: 0.18em;
  }

  h1 {
    font-size: clamp(26px, 8vw, 32px);
    line-height: 1;
    margin-bottom: 4px;
  }

  #patternHelp {
    font-size: 13px;
    line-height: 1.25;
    min-height: 18px;
  }

  .pattern-board {
    flex: 0 0 auto;
    margin: 12px auto 8px;
    width: min(86vw, calc(100svh - 210px), 350px);
  }

  .pattern-grid {
    padding: 8%;
  }

  .pattern-dot {
    height: clamp(15px, 4.8vw, 24px);
    width: clamp(15px, 4.8vw, 24px);
  }

  .pattern-dot.active {
    box-shadow: 0 0 0 8px rgba(0, 0, 0, 0.08);
  }

  .pattern-message {
    align-items: center;
    display: flex;
    font-size: 12px;
    justify-content: center;
    line-height: 1.2;
    min-height: 18px;
  }

  .pattern-actions {
    gap: 10px;
    margin-top: 8px;
    width: min(80%, 320px);
    margin-left: auto;
    margin-right: auto;
  }

  .pattern-actions button {
    flex: 1 1 0;
    border-radius: 18px;
    min-height: 52px;
    min-width: 0;
    padding: 12px 14px;
    letter-spacing: 0;
    text-transform: none;
  }

  .pattern-actions button:first-child {
    background: #f3f4f6;
    border-color: #e5e7eb;
    color: #111827;
  }

  .pattern-actions button:last-child {
    box-shadow: 0 12px 26px rgba(0, 0, 0, 0.16);
  }

  .pattern-actions button.hidden + button {
    flex-basis: 100%;
  }
}

@media (max-width: 480px) and (max-height: 700px) {
  .brand-mark {
    display: none;
  }

  .brand {
    margin-bottom: 4px;
  }

  .pattern-board {
    margin: 8px auto 6px;
    width: min(84vw, calc(100svh - 180px), 330px);
  }
}

@media (max-width: 480px) and (max-height: 600px) {
  .brand {
    display: none;
  }

  h1 {
    font-size: 25px;
  }

  #patternHelp {
    font-size: 12px;
  }

  .pattern-board {
    margin: 6px auto 4px;
    width: min(80vw, calc(100svh - 150px), 290px);
  }
}
