/* Pattern Lock Tracker */
.plock {
  --pl-bg: #E4E9EE;
  --pl-surface: #F6F8FA;
  --pl-ink: #1B2733;
  --pl-muted: #5A6A79;
  --pl-line: #C9D3DC;
  --pl-screen: #1F2D3B;
  --pl-screen-edge: #2E4153;
  --pl-dot: #A9BCCD;
  --pl-draw: #E8EFF5;
  --pl-new: #2FB896;
  --pl-tried: #E85C4A;
  --pl-start: #E3A92F;
  --pl-focus: #3C85C9;
  --pl-radius: 14px;
  color: var(--pl-ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}
@media (prefers-color-scheme: dark) {
  .plock {
    --pl-bg: #111920;
    --pl-surface: #19232D;
    --pl-ink: #E3EAF0;
    --pl-muted: #93A3B1;
    --pl-line: #2D3B48;
    --pl-screen-edge: #3A4F63;
  }
}
.plock *, .plock *::before, .plock *::after { box-sizing: border-box; }

body.plock-standalone {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: #E4E9EE;
}
@media (prefers-color-scheme: dark) { body.plock-standalone { background: #111920; } }
.plock-standalone .plock { background: var(--pl-bg); min-height: 100dvh; }
.plock-embedded { background: var(--pl-bg); border-radius: 20px; }

.pl-shell {
  max-width: 1100px;
  margin: 0 auto;
  padding: calc(20px + env(safe-area-inset-top, 0px)) calc(16px + env(safe-area-inset-right, 0px)) calc(40px + env(safe-area-inset-bottom, 0px)) calc(16px + env(safe-area-inset-left, 0px));
}

/* Header */
.pl-top { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.pl-title h1 { margin: 0; font-size: 1.6rem; line-height: 1.15; letter-spacing: -0.02em; font-weight: 750; }
.pl-title p { margin: 6px 0 0; color: var(--pl-muted); max-width: 46ch; font-size: .95rem; }
.pl-count { display: flex; flex-direction: column; align-items: flex-end; flex-shrink: 0; }
.pl-count strong { font-size: 2.2rem; line-height: 1; font-weight: 750; font-variant-numeric: tabular-nums; letter-spacing: -0.03em; }
.pl-count span { color: var(--pl-muted); font-size: .85rem; }

/* Layout */
.pl-main { display: grid; gap: 28px; }
@media (min-width: 860px) {
  .pl-main { grid-template-columns: minmax(340px, 420px) 1fr; align-items: start; gap: 36px; }
  .pl-work { position: sticky; top: 20px; }
}

/* Pad */
.pl-screen {
  background: var(--pl-screen);
  border: 1px solid var(--pl-screen-edge);
  border-radius: 30px;
  padding: 18px;
  max-width: 420px;
  margin: 0 auto;
}
.pl-pad {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: crosshair;
  --stroke: var(--pl-draw);
}
.pl-pad[data-state="new"], .pl-pad[data-state="saved"] { --stroke: var(--pl-new); }
.pl-pad[data-state="tried"] { --stroke: var(--pl-tried); }
.pl-pad[data-state="short"] { --stroke: #7D90A2; }
.pl-line { fill: none; stroke: var(--stroke); stroke-width: 9; stroke-linecap: round; stroke-linejoin: round; transition: stroke .18s; }
.pl-trail { stroke: var(--stroke); stroke-width: 9; stroke-linecap: round; opacity: .4; }
.pl-arrows { fill: none; stroke: var(--pl-screen); stroke-width: 3.5; stroke-linecap: round; stroke-linejoin: round; }
.pl-pad[data-state="drawing"] .pl-arrows { display: none; }
.pl-ring { fill: transparent; stroke: transparent; stroke-width: 2.5; transition: fill .15s, stroke .15s; }
.pl-core { fill: var(--pl-dot); transform-box: fill-box; transform-origin: center; transition: transform .15s, fill .15s; }
.pl-num { font-size: 13px; fill: #6F8498; font-family: inherit; pointer-events: none; }
.pl-dot.is-on .pl-core { fill: var(--stroke); transform: scale(1.45); }
.pl-dot.is-on .pl-ring { fill: rgba(255,255,255,.06); stroke: var(--stroke); stroke-opacity: .5; }
.pl-dot.is-start .pl-ring { stroke: var(--pl-start); stroke-opacity: 1; stroke-width: 3.5; }

/* Status */
.pl-status {
  margin: 18px auto 0;
  max-width: 420px;
  padding: 12px 14px 12px 16px;
  border-radius: var(--pl-radius);
  background: var(--pl-surface);
  border: 1px solid var(--pl-line);
  border-left: 5px solid var(--pl-line);
  min-height: 72px;
}
.pl-status-title { display: block; font-weight: 700; font-size: 1.05rem; }
.pl-status-text { display: block; color: var(--pl-muted); font-size: .92rem; }
.pl-status[data-state="new"], .pl-status[data-state="saved"] { border-left-color: var(--pl-new); }
.pl-status[data-state="new"] .pl-status-title, .pl-status[data-state="saved"] .pl-status-title { color: var(--pl-new); }
.pl-status[data-state="tried"], .pl-status[data-state="view"] { border-left-color: var(--pl-tried); }
.pl-status[data-state="tried"] .pl-status-title { color: var(--pl-tried); }
.pl-status[data-state="error"] { border-left-color: var(--pl-start); }
.pl-status[data-state="checking"] .pl-status-title::after { content: ""; display: inline-block; width: 10px; height: 10px; margin-left: 8px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: pl-spin .7s linear infinite; vertical-align: 1px; }

.pl-seq { max-width: 420px; margin: 10px auto 0; min-height: 1.4em; text-align: center; color: var(--pl-muted); font-variant-numeric: tabular-nums; letter-spacing: .02em; }

/* Buttons */
.pl-actions { display: flex; gap: 10px; max-width: 420px; margin: 12px auto 0; }
.pl-actions .pl-btn { flex: 1; }
.pl-btn {
  appearance: none;
  font: inherit;
  font-weight: 600;
  min-height: 48px;
  padding: 0 18px;
  border-radius: 12px;
  border: 1px solid var(--pl-line);
  background: var(--pl-surface);
  color: var(--pl-ink);
  cursor: pointer;
  touch-action: manipulation;
  transition: background .15s, opacity .15s, transform .1s;
}
.pl-btn:active:not(:disabled) { transform: scale(.98); }
.pl-btn:disabled { opacity: .45; cursor: not-allowed; }
.pl-btn[hidden] { display: none; }
.pl-btn-main { background: var(--pl-ink); color: var(--pl-surface); border-color: var(--pl-ink); }
.pl-btn-danger { color: var(--pl-tried); border-color: var(--pl-tried); background: transparent; }
.plock button:focus-visible, .plock input:focus-visible + .pl-switch-ui { outline: 3px solid var(--pl-focus); outline-offset: 2px; }

/* Switch */
.pl-switch { display: flex; gap: 12px; align-items: flex-start; max-width: 420px; margin: 16px auto 0; cursor: pointer; }
.pl-switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.pl-switch-ui { flex-shrink: 0; width: 46px; height: 28px; border-radius: 14px; background: var(--pl-line); position: relative; transition: background .18s; margin-top: 1px; }
.pl-switch-ui::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform .18s; }
.pl-switch input:checked + .pl-switch-ui { background: var(--pl-new); }
.pl-switch input:checked + .pl-switch-ui::after { transform: translateX(18px); }
.pl-switch-text { font-weight: 600; font-size: .95rem; }
.pl-switch-text small { display: block; font-weight: 400; color: var(--pl-muted); font-size: .85rem; }

/* History */
.pl-history-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.pl-history-head h2 { margin: 0; font-size: 1.15rem; font-weight: 700; }
.pl-history-meta { color: var(--pl-muted); font-size: .9rem; }
.pl-filters { display: flex; flex-wrap: wrap; gap: 14px 28px; align-items: center; margin: 14px 0 18px; }
.pl-filter { display: flex; align-items: center; gap: 12px; }
.pl-filter-label { color: var(--pl-muted); font-size: .9rem; }
.pl-mini { display: grid; grid-template-columns: repeat(3, 26px); gap: 4px; padding: 6px; border-radius: 12px; background: var(--pl-screen); }
.pl-mini button { appearance: none; border: 0; background: transparent; width: 26px; height: 26px; border-radius: 8px; cursor: pointer; display: grid; place-items: center; padding: 0; }
.pl-mini i { width: 8px; height: 8px; border-radius: 50%; background: var(--pl-dot); transition: transform .15s, background .15s; }
.pl-mini button[aria-pressed="true"] { background: rgba(227,169,47,.18); }
.pl-mini button[aria-pressed="true"] i { background: var(--pl-start); transform: scale(1.5); }
.pl-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.pl-chips button { appearance: none; font: inherit; font-size: .88rem; font-weight: 600; min-width: 40px; height: 36px; padding: 0 10px; border-radius: 18px; border: 1px solid var(--pl-line); background: var(--pl-surface); color: var(--pl-ink); cursor: pointer; font-variant-numeric: tabular-nums; }
.pl-chips button[aria-pressed="true"] { background: var(--pl-ink); color: var(--pl-surface); border-color: var(--pl-ink); }

.pl-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 12px; transition: opacity .15s; }
.is-loading .pl-list { opacity: .5; }
.pl-item {
  appearance: none;
  font: inherit;
  color: inherit;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 10px 9px;
  border-radius: var(--pl-radius);
  border: 1px solid var(--pl-line);
  background: var(--pl-surface);
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s;
}
.pl-item:hover { border-color: var(--pl-muted); }
.pl-item.is-active { border-color: var(--pl-ink); box-shadow: 0 0 0 2px var(--pl-ink); }
.pl-item.is-new { animation: pl-flash 1.4s ease-out; }
.pl-thumb { display: block; width: 100%; aspect-ratio: 1; margin-bottom: 6px; }
.pl-thumb .t-off { fill: var(--pl-line); }
.pl-thumb .t-on { fill: var(--pl-ink); }
.pl-thumb .t-line { fill: none; stroke: var(--pl-ink); stroke-width: 14; stroke-linecap: round; stroke-linejoin: round; }
.pl-thumb .t-arrows { fill: none; stroke: var(--pl-surface); stroke-width: 7; stroke-linecap: round; stroke-linejoin: round; }
.pl-thumb .t-start { fill: none; stroke: var(--pl-start); stroke-width: 9; }
.pl-item-seq { font-weight: 650; font-size: .88rem; font-variant-numeric: tabular-nums; letter-spacing: .12em; }
.pl-item-date { color: var(--pl-muted); font-size: .78rem; }

.pl-empty { color: var(--pl-muted); margin: 8px 0 0; padding: 22px; border: 1px dashed var(--pl-line); border-radius: var(--pl-radius); text-align: center; }
.pl-empty[hidden] { display: none; }
.pl-more { display: block; margin: 18px auto 0; }

/* Toast */
.pl-toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  transform: translate(-50%, 20px);
  max-width: min(92vw, 420px);
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--pl-ink);
  color: var(--pl-surface);
  font-size: .92rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 99999;
}
.pl-toast.is-on { opacity: 1; transform: translate(-50%, 0); }

@keyframes pl-spin { to { transform: rotate(360deg); } }
@keyframes pl-flash { from { box-shadow: 0 0 0 3px var(--pl-new); } to { box-shadow: 0 0 0 0 transparent; } }

@media (max-width: 420px) {
  .pl-title h1 { font-size: 1.35rem; }
  .pl-count strong { font-size: 1.8rem; }
  .pl-screen { padding: 12px; border-radius: 24px; }
  .pl-list { grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 10px; }
  .pl-chips button { min-width: 36px; padding: 0 8px; }
}
@media (prefers-reduced-motion: reduce) {
  .plock *, .plock *::before, .plock *::after { transition: none !important; animation: none !important; }
}
