/* ============================================================
   Pavlok Trigger Hub v2 — Multi-Device Control Console
   Design System (tokens + base + components)
   ============================================================ */

/* ============================================================
   1. Design Tokens
   ============================================================ */

:root {
  /* --- Surface (dark navy base、視認可能なコントラスト階段) --- */
  --surface-0: #050609;          /* bg deepest */
  --surface-1: #0C0E15;          /* sub bg, slightly elevated */
  --surface-2-top: #232735;      /* card gradient top（light from above 演出）*/
  --surface-2-bot: #161922;      /* card gradient bottom */
  --surface-2: #1C1F2A;          /* flat 用 mid-tone（modal / login card 等 gradient 不要場面）*/
  --surface-3: #2A2E3D;          /* hover state / nested element */
  --surface-4: #353A4B;          /* strongest elevated surface */
  --surface-input: #0A0D14;
  --surface-overlay: rgba(5, 6, 9, 0.78);

  /* --- Border --- */
  --border-subtle: rgba(255, 255, 255, 0.07);
  --border-default: rgba(255, 255, 255, 0.13);
  --border-strong: rgba(255, 255, 255, 0.22);
  --border-top-highlight: rgba(255, 255, 255, 0.10);   /* card 上辺ハイライト */
  --border-focus: rgba(255, 122, 41, 0.56);

  /* --- Text --- */
  --text-primary: rgba(255, 255, 255, 0.96);
  --text-secondary: rgba(255, 255, 255, 0.68);
  --text-tertiary: rgba(255, 255, 255, 0.44);
  --text-disabled: rgba(255, 255, 255, 0.24);
  --text-inverse: #0A0C12;

  /* --- Accent (fixus.studio orange) --- */
  --accent: #FF7A29;
  --accent-hover: #FF9450;
  --accent-active: #E36410;
  --accent-bg: rgba(255, 122, 41, 0.08);
  --accent-bg-strong: rgba(255, 122, 41, 0.16);
  --accent-glow: rgba(255, 122, 41, 0.32);
  --accent-glow-strong: rgba(255, 122, 41, 0.48);

  /* --- Semantic --- */
  --firing: #FF7A29;
  --firing-bg: rgba(255, 122, 41, 0.08);
  --idle: #5B8CC9;
  --idle-bg: rgba(91, 140, 201, 0.10);
  --success: #34C759;
  --success-bg: rgba(52, 199, 89, 0.10);
  --error: #FF4D4D;
  --error-bg: rgba(255, 77, 77, 0.10);
  --warning: #FFB938;
  --warning-bg: rgba(255, 185, 56, 0.10);

  /* --- Spacing scale (4px grid) --- */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 20px;
  --s-6: 24px;
  --s-7: 32px;
  --s-8: 40px;
  --s-9: 56px;
  --s-10: 72px;

  /* --- Radius --- */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-xl: 20px;
  --r-2xl: 28px;
  --r-full: 9999px;

  /* --- Typography --- */
  --font-sans: 'Inter', -apple-system, 'Segoe UI', 'Hiragino Kaku Gothic ProN', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', 'Cascadia Mono', Consolas, ui-monospace, monospace;

  --fs-display: 28px;
  --fs-h1: 22px;
  --fs-h2: 17px;
  --fs-h3: 14px;
  --fs-body: 14px;
  --fs-small: 12px;
  --fs-micro: 11px;

  --lh-tight: 1.18;
  --lh-snug: 1.32;
  --lh-base: 1.5;

  --fw-regular: 400;
  --fw-medium: 500;
  --fw-semibold: 600;
  --fw-bold: 700;

  /* --- Shadow (claymorphism + 光源上から的 lift 演出) --- */
  --shadow-card:
    inset 0 1px 0 rgba(255, 255, 255, 0.06),
    0 1px 2px rgba(0, 0, 0, 0.5),
    0 6px 16px rgba(0, 0, 0, 0.32),
    0 16px 40px rgba(0, 0, 0, 0.28);
  --shadow-card-hover:
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    0 2px 4px rgba(0, 0, 0, 0.5),
    0 12px 28px rgba(0, 0, 0, 0.4),
    0 24px 56px rgba(0, 0, 0, 0.32);
  --shadow-elev: 0 4px 12px rgba(0, 0, 0, 0.5), 0 20px 48px rgba(0, 0, 0, 0.4);
  --shadow-modal: 0 32px 96px rgba(0, 0, 0, 0.72);
  --shadow-firing:
    inset 0 1px 0 rgba(255, 165, 100, 0.30),
    0 0 0 1px rgba(255, 122, 41, 0.5),
    0 0 32px rgba(255, 122, 41, 0.32),
    0 16px 40px rgba(0, 0, 0, 0.4);
  --shadow-btn:
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    0 1px 2px rgba(0, 0, 0, 0.4),
    0 2px 6px rgba(0, 0, 0, 0.24);

  /* --- Transitions --- */
  --t-fast: 120ms cubic-bezier(0.4, 0, 0.2, 1);
  --t-base: 200ms cubic-bezier(0.4, 0, 0.2, 1);
  --t-slow: 320ms cubic-bezier(0.4, 0, 0.2, 1);
  --t-spring: 480ms cubic-bezier(0.34, 1.56, 0.64, 1);

  /* --- Layout --- */
  --max-width: 1320px;
  --header-height: 60px;
  --gutter: var(--s-6);
}

@media (max-width: 768px) {
  :root {
    --gutter: var(--s-4);
    --fs-display: 24px;
    --fs-h1: 19px;
    --fs-h2: 15px;
    --header-height: 56px;
  }
}

/* ============================================================
   2. Reset / Base
   ============================================================ */

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

html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  font-size: var(--fs-body);
  line-height: var(--lh-base);
  color: var(--text-primary);
  background: var(--surface-0);
  background-image:
    radial-gradient(ellipse 1200px 800px at 80% -10%, rgba(255, 122, 41, 0.075), transparent 55%),
    radial-gradient(ellipse 900px 700px at -10% 100%, rgba(91, 140, 201, 0.06), transparent 55%),
    radial-gradient(ellipse 700px 500px at 50% 50%, rgba(255, 255, 255, 0.012), transparent 70%);
  background-attachment: fixed;
  min-height: 100vh;
  font-feature-settings: 'cv02', 'cv03', 'cv04', 'cv11';
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overscroll-behavior-y: none;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  background: none;
  border: none;
  outline: none;
}

input, textarea, select {
  background: none;
  border: none;
  outline: none;
}

a {
  color: var(--accent);
  text-decoration: none;
}

ul, ol {
  list-style: none;
}

img, svg {
  display: block;
  max-width: 100%;
}

::selection {
  background: var(--accent-bg-strong);
  color: var(--text-primary);
}

/* ============================================================
   3. Layout
   ============================================================ */

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.screen { display: none; }
.screen[data-active] { display: flex; flex-direction: column; flex: 1; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--gutter);
  background: rgba(7, 8, 13, 0.78);
  backdrop-filter: saturate(140%) blur(20px);
  -webkit-backdrop-filter: saturate(140%) blur(20px);
  border-bottom: 1px solid var(--border-subtle);
}

.app-header__brand {
  display: flex;
  align-items: center;
  gap: var(--s-3);
}

.app-header__logo {
  width: 28px;
  height: 28px;
  border-radius: var(--r-sm);
}

.app-header__title {
  font-size: var(--fs-h2);
  font-weight: var(--fw-semibold);
  letter-spacing: -0.01em;
  color: var(--text-primary);
}

.app-header__title-sub {
  font-size: var(--fs-micro);
  font-weight: var(--fw-medium);
  color: var(--text-tertiary);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-top: 2px;
}

.app-header__nav {
  display: flex;
  align-items: center;
  gap: var(--s-2);
}

@media (max-width: 768px) {
  .app-header__title-sub { display: none; }
  .app-header__nav .btn__label { display: none; }
}

.app-main {
  flex: 1;
  width: 100%;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: var(--s-7) var(--gutter) var(--s-9);
  display: flex;
  flex-direction: column;
  gap: var(--s-8);
}

@media (max-width: 768px) {
  .app-main {
    padding: var(--s-5) var(--gutter) var(--s-9);
    gap: var(--s-6);
  }
}

.section {
  display: flex;
  flex-direction: column;
  gap: var(--s-4);
}

.section__head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--s-4);
}

.section__heading {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.section__title {
  font-size: var(--fs-h1);
  font-weight: var(--fw-semibold);
  letter-spacing: -0.015em;
  display: flex;
  align-items: baseline;
  gap: var(--s-3);
  line-height: var(--lh-tight);
}

.section__count {
  font-size: var(--fs-small);
  font-weight: var(--fw-medium);
  color: var(--text-tertiary);
  font-feature-settings: 'tnum';
}

.section__sub {
  font-size: var(--fs-micro);
  color: var(--text-tertiary);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: var(--fw-medium);
}

.section__actions {
  display: flex;
  gap: var(--s-2);
}

/* デバイス section = 主役、視覚比重最大 */
.section--primary .section__title {
  font-size: var(--fs-display);
  letter-spacing: -0.022em;
  font-weight: var(--fw-bold);
}

.section--primary .section__sub {
  color: var(--accent);
  opacity: 0.7;
}

/* プリセット section = 副、視覚比重控えめ */
.section--secondary .section__title {
  font-size: var(--fs-h2);
  color: var(--text-secondary);
  font-weight: var(--fw-semibold);
}

.section--secondary .section__count {
  color: var(--text-disabled);
}

/* ============================================================
   4. Login Screen
   ============================================================ */

#screen-login {
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  padding: var(--gutter);
}

.login-card {
  width: 100%;
  max-width: 400px;
  padding: var(--s-8) var(--s-7);
  background: var(--surface-2);
  border: 1px solid var(--border-default);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-elev);
  display: flex;
  flex-direction: column;
  gap: var(--s-5);
}

.login-card__brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s-3);
  text-align: center;
  margin-bottom: var(--s-2);
}

.login-card__logo {
  width: 48px;
  height: 48px;
  border-radius: var(--r-md);
}

.login-card__title {
  font-size: var(--fs-display);
  font-weight: var(--fw-bold);
  letter-spacing: -0.02em;
}

.login-card__subtitle {
  font-size: var(--fs-small);
  color: var(--text-tertiary);
  font-feature-settings: 'tnum';
  letter-spacing: 0.04em;
}

.login-card form {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
}

.login-card__error {
  font-size: var(--fs-small);
  color: var(--error);
  padding: var(--s-3) var(--s-4);
  background: var(--error-bg);
  border: 1px solid rgba(255, 77, 77, 0.22);
  border-radius: var(--r-md);
  display: none;
}

.login-card__error[data-shown] { display: block; }

/* ============================================================
   5. Buttons
   ============================================================ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  height: 40px;
  padding: 0 var(--s-4);
  border-radius: var(--r-md);
  font-size: var(--fs-body);
  font-weight: var(--fw-medium);
  letter-spacing: -0.005em;
  color: var(--text-primary);
  background: var(--surface-3);
  border: 1px solid var(--border-default);
  box-shadow: var(--shadow-btn);
  transition: transform var(--t-fast), background var(--t-fast), border-color var(--t-fast), color var(--t-fast), box-shadow var(--t-fast);
  white-space: nowrap;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.btn:hover {
  background: var(--surface-4);
  border-color: var(--border-strong);
}

.btn:active { transform: translateY(1px); }

.btn:focus-visible {
  border-color: var(--border-focus);
  box-shadow: var(--shadow-btn), 0 0 0 3px var(--accent-bg);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

/* solid orange — login commit / modal save / 「今 commit する」専用 */
.btn--primary {
  background: linear-gradient(180deg, #FF9450 0%, #FF7A29 100%);
  border-color: #E66510;
  color: var(--text-inverse);
  font-weight: var(--fw-semibold);
  box-shadow:
    inset 0 1px 0 rgba(255, 220, 180, 0.4),
    0 1px 2px rgba(180, 60, 10, 0.4),
    0 2px 8px rgba(255, 122, 41, 0.25);
}

.btn--primary:hover {
  background: linear-gradient(180deg, #FFA365 0%, #FF8B3F 100%);
  border-color: #FF7A29;
}

.btn--primary:active {
  background: linear-gradient(180deg, #FF7A29 0%, #E66510 100%);
  border-color: #C85608;
  box-shadow:
    inset 0 1px 2px rgba(180, 60, 10, 0.3),
    0 1px 2px rgba(180, 60, 10, 0.2);
}

/* substantial — context-primary action（dark filled、accent icon）device idle 起動用 */
.btn--substantial {
  background: linear-gradient(180deg, var(--surface-3) 0%, #1F222D 100%);
  border-color: rgba(255, 255, 255, 0.14);
  color: var(--text-primary);
  font-weight: var(--fw-semibold);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.10),
    0 1px 2px rgba(0, 0, 0, 0.5),
    0 4px 12px rgba(0, 0, 0, 0.3);
}

.btn--substantial .btn__icon { color: var(--accent); }

.btn--substantial:hover {
  background: linear-gradient(180deg, var(--surface-4) 0%, #2A2E3D 100%);
  border-color: rgba(255, 255, 255, 0.22);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.14),
    0 1px 2px rgba(0, 0, 0, 0.5),
    0 6px 16px rgba(0, 0, 0, 0.4),
    0 0 32px rgba(255, 122, 41, 0.12);
}

.btn--substantial:active {
  background: linear-gradient(180deg, #1F222D 0%, var(--surface-3) 100%);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.4);
}

/* outline accent — sub-CTA、library / picker 用 */
.btn--accent {
  background: transparent;
  border-color: rgba(255, 122, 41, 0.35);
  color: var(--accent);
  font-weight: var(--fw-semibold);
  box-shadow: none;
}

.btn--accent:hover {
  background: var(--accent-bg-strong);
  border-color: var(--accent);
  color: var(--accent-hover);
  box-shadow: 0 0 24px rgba(255, 122, 41, 0.15);
}

.btn--accent:active {
  background: var(--accent-bg);
}

.btn--accent:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-bg);
}

.btn--ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-secondary);
  box-shadow: none;
}

.btn--ghost:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--border-subtle);
  color: var(--text-primary);
}

.btn--danger {
  background: transparent;
  border-color: rgba(255, 77, 77, 0.28);
  color: var(--error);
  box-shadow: none;
}

.btn--danger:hover {
  background: var(--error-bg);
  border-color: rgba(255, 77, 77, 0.5);
  color: var(--error);
}

.btn--solid-danger {
  background: linear-gradient(180deg, #FF6B6B 0%, #E53E3E 100%);
  border-color: #C53030;
  color: white;
  font-weight: var(--fw-semibold);
  box-shadow:
    inset 0 1px 0 rgba(255, 200, 200, 0.4),
    0 1px 2px rgba(120, 20, 20, 0.4),
    0 4px 16px rgba(255, 77, 77, 0.3);
}

.btn--solid-danger:hover {
  background: linear-gradient(180deg, #FF7A7A 0%, #EF4444 100%);
  border-color: #DC2626;
  box-shadow:
    inset 0 1px 0 rgba(255, 220, 220, 0.4),
    0 2px 4px rgba(120, 20, 20, 0.4),
    0 8px 24px rgba(255, 77, 77, 0.4);
}

.btn--solid-danger:active {
  background: linear-gradient(180deg, #E53E3E 0%, #C53030 100%);
  box-shadow: inset 0 2px 4px rgba(120, 20, 20, 0.4);
}

.btn--sm {
  height: 32px;
  padding: 0 var(--s-3);
  font-size: var(--fs-small);
  border-radius: var(--r-sm);
}

.btn--lg {
  height: 48px;
  padding: 0 var(--s-5);
  font-size: var(--fs-h2);
  border-radius: var(--r-md);
}

.btn--xl {
  height: 56px;
  padding: 0 var(--s-6);
  font-size: var(--fs-h2);
  border-radius: var(--r-lg);
  font-weight: var(--fw-semibold);
}

.btn--block { width: 100%; }

.btn--icon {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: var(--r-sm);
}

.btn__icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.btn--xl .btn__icon { width: 20px; height: 20px; }

/* ============================================================
   6. Input / Form
   ============================================================ */

.field {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
}

.field__label {
  font-size: var(--fs-small);
  font-weight: var(--fw-medium);
  color: var(--text-secondary);
  letter-spacing: 0.01em;
}

.field__hint {
  font-size: var(--fs-micro);
  color: var(--text-tertiary);
}

.input,
.select,
.textarea {
  height: 40px;
  padding: 0 var(--s-3);
  background: var(--surface-input);
  border: 1px solid var(--border-default);
  border-radius: var(--r-md);
  color: var(--text-primary);
  font-size: var(--fs-body);
  font-family: var(--font-sans);
  transition: border-color var(--t-fast), background var(--t-fast), box-shadow var(--t-fast);
  width: 100%;
}

.textarea {
  height: auto;
  min-height: 80px;
  padding: var(--s-3);
  resize: vertical;
  line-height: var(--lh-base);
}

.input:focus,
.select:focus,
.textarea:focus {
  border-color: var(--border-focus);
  background: var(--surface-1);
  box-shadow: 0 0 0 3px var(--accent-bg);
}

.input--mono { font-family: var(--font-mono); font-size: 13px; }

.input::placeholder, .textarea::placeholder { color: var(--text-tertiary); }

.select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='rgba(255,255,255,0.5)' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'><path d='M4 6l4 4 4-4'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 32px;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s-3);
}

.field-row--three { grid-template-columns: 1fr 1fr 1fr; }

@media (max-width: 600px) {
  .field-row { grid-template-columns: 1fr; }
  .field-row--three { grid-template-columns: 1fr 1fr; }
}

/* Segmented toggle */
.segmented {
  display: inline-flex;
  background: var(--surface-input);
  border: 1px solid var(--border-default);
  border-radius: var(--r-md);
  padding: 3px;
  gap: 2px;
}

.segmented__option {
  height: 32px;
  padding: 0 var(--s-3);
  border-radius: 7px;
  font-size: var(--fs-small);
  font-weight: var(--fw-medium);
  color: var(--text-secondary);
  background: transparent;
  border: none;
  transition: background var(--t-fast), color var(--t-fast);
}

.segmented__option[data-selected] {
  background: var(--surface-3);
  color: var(--text-primary);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

/* ============================================================
   7. Device Cards
   ============================================================ */

.device-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
  gap: var(--s-4);
}

@media (min-width: 1100px) {
  .device-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 600px) {
  .device-grid { grid-template-columns: 1fr; gap: var(--s-3); }
}

.device-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: var(--s-4);
  padding: var(--s-6);
  min-height: 200px;
  background: linear-gradient(180deg, var(--surface-2-top) 0%, var(--surface-2-bot) 100%);
  border: 1px solid var(--border-default);
  border-top-color: var(--border-top-highlight);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-card);
  transition: transform var(--t-base), box-shadow var(--t-base), border-color var(--t-base);
  overflow: hidden;
}

.device-card--idle:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-card-hover);
  border-color: var(--border-strong);
  border-top-color: rgba(255, 255, 255, 0.18);
}

@media (max-width: 600px) {
  .device-card { padding: var(--s-5); min-height: 180px; }
}

.device-card--idle:hover {
  border-color: var(--border-strong);
}

.device-card--running {
  background:
    linear-gradient(180deg, rgba(255, 122, 41, 0.18) 0%, rgba(255, 122, 41, 0.04) 35%, var(--surface-2-top) 60%, var(--surface-2-bot) 100%);
  border-color: rgba(255, 122, 41, 0.5);
  border-top-color: rgba(255, 165, 100, 0.55);
  box-shadow: var(--shadow-firing);
}

.device-card--running::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: var(--r-lg);
  pointer-events: none;
  background: radial-gradient(circle at 50% 0%, var(--accent-glow), transparent 60%);
  opacity: 0;
  animation: pulse-bg 2.4s ease-in-out infinite;
}

@keyframes pulse-bg {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 0.85; }
}

.device-card__head {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  position: relative;
  z-index: 1;
}

.device-card__status-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--idle);
  box-shadow: 0 0 0 4px var(--idle-bg);
}

.device-card--running .device-card__status-dot {
  background: var(--firing);
  box-shadow: 0 0 0 4px var(--firing-bg), 0 0 16px var(--accent-glow);
  animation: pulse-dot 1.6s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { box-shadow: 0 0 0 4px var(--firing-bg), 0 0 12px var(--accent-glow); }
  50% { box-shadow: 0 0 0 6px var(--firing-bg), 0 0 28px var(--accent-glow-strong); }
}

.device-card__name {
  font-size: var(--fs-h1);
  font-weight: var(--fw-bold);
  letter-spacing: -0.018em;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.device-card__menu {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-sm);
  color: var(--text-tertiary);
  transition: background var(--t-fast), color var(--t-fast);
  margin: -4px;
}

.device-card__menu:hover {
  background: var(--surface-3);
  color: var(--text-primary);
}

.device-card__body {
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  position: relative;
  z-index: 1;
  flex: 1;
}

.device-card__preset {
  font-size: var(--fs-display);
  font-weight: var(--fw-semibold);
  color: var(--text-primary);
  letter-spacing: -0.018em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: var(--lh-tight);
}

.device-card__meta {
  display: flex;
  align-items: baseline;
  gap: var(--s-3);
  font-size: var(--fs-small);
  color: var(--text-tertiary);
  margin-top: var(--s-1);
}

.device-card__timer {
  font-family: var(--font-mono);
  font-size: 26px;
  font-weight: var(--fw-medium);
  color: var(--text-primary);
  font-feature-settings: 'tnum';
  letter-spacing: -0.01em;
  line-height: 1;
}

.device-card--running .device-card__timer { color: var(--firing); }

.device-card__exec-id {
  font-family: var(--font-mono);
  font-size: var(--fs-micro);
  color: var(--text-disabled);
  letter-spacing: 0.02em;
}

.device-card__idle-status {
  display: flex;
  flex-direction: column;
  gap: var(--s-1);
  flex: 1;
  justify-content: center;
}

.device-card__idle-label {
  align-self: flex-start;
  font-size: 10px;
  font-weight: var(--fw-bold);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--idle);
  padding: 3px 8px 3px 8px;
  background: rgba(91, 140, 201, 0.10);
  border: 1px solid rgba(91, 140, 201, 0.22);
  border-radius: var(--r-full);
  font-family: var(--font-mono);
  line-height: 1.4;
}

.device-card__idle-text {
  font-size: var(--fs-body);
  color: var(--text-secondary);
  font-style: normal;
  font-weight: var(--fw-medium);
  letter-spacing: -0.005em;
}

.device-card__actions {
  display: flex;
  gap: var(--s-2);
  position: relative;
  z-index: 1;
}

.device-card__actions .btn { flex: 1; }

.device-card__webhook {
  font-family: var(--font-mono);
  font-size: var(--fs-micro);
  color: var(--text-tertiary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ============================================================
   8. Preset Cards
   ============================================================ */

.preset-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: var(--s-3);
}

@media (max-width: 600px) {
  .preset-grid { grid-template-columns: 1fr; gap: var(--s-2); }
}

/* プリセットカード = ライブラリ item、card-as-button（カード全体がクリック対象 = 起動 picker 開く）*/
.preset-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  padding: var(--s-4) var(--s-4) var(--s-5);
  background: linear-gradient(180deg, #1A1D27 0%, #11131B 100%);
  border: 1px solid var(--border-subtle);
  border-top-color: rgba(255, 255, 255, 0.07);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-btn);
  transition: transform var(--t-base), box-shadow var(--t-base), border-color var(--t-base), background var(--t-base);
  cursor: pointer;
  min-height: 116px;
}

.preset-card:hover {
  background: linear-gradient(180deg, #252937 0%, #181B25 100%);
  border-color: rgba(255, 122, 41, 0.30);
  border-top-color: rgba(255, 165, 100, 0.35);
  transform: translateY(-2px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.10),
    0 4px 12px rgba(0, 0, 0, 0.4),
    0 12px 32px rgba(0, 0, 0, 0.3),
    0 0 24px rgba(255, 122, 41, 0.10);
}

.preset-card:active {
  transform: translateY(0);
  box-shadow: var(--shadow-btn);
}

.preset-card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  min-height: 28px;
}

.preset-card__name {
  font-size: 15px;
  font-weight: var(--fw-semibold);
  letter-spacing: -0.01em;
  color: var(--text-primary);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preset-card__play-icon {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-bg);
  color: var(--accent);
  flex-shrink: 0;
  transition: background var(--t-base), color var(--t-base), box-shadow var(--t-base), transform var(--t-base);
}

.preset-card__play-icon svg { width: 11px; height: 11px; margin-left: 1px; }

.preset-card:hover .preset-card__play-icon {
  background: var(--accent);
  color: var(--text-inverse);
  box-shadow:
    inset 0 1px 0 rgba(255, 220, 180, 0.4),
    0 0 0 4px rgba(255, 122, 41, 0.16),
    0 0 20px rgba(255, 122, 41, 0.4);
  transform: scale(1.06);
}

.preset-card__phases {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  min-height: 22px;
}

.preset-card__phase-chip {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-full);
  font-size: 10.5px;
  font-family: var(--font-mono);
  font-feature-settings: 'tnum';
  color: var(--text-secondary);
  letter-spacing: 0.01em;
  line-height: 18px;
  white-space: nowrap;
}

.preset-card__phase-chip--wait { color: var(--idle); border-color: rgba(91, 140, 201, 0.28); background: rgba(91, 140, 201, 0.06); }
.preset-card__phase-chip--zap { color: var(--firing); border-color: rgba(255, 122, 41, 0.32); background: rgba(255, 122, 41, 0.06); }
.preset-card__phase-chip--beep { color: var(--warning); border-color: rgba(255, 185, 56, 0.28); background: rgba(255, 185, 56, 0.06); }
.preset-card__phase-chip--vibe { color: var(--success); border-color: rgba(52, 199, 89, 0.28); background: rgba(52, 199, 89, 0.06); }

.preset-card__icon-actions {
  position: absolute;
  bottom: 8px;
  right: 8px;
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity var(--t-fast);
}

.preset-card:hover .preset-card__icon-actions,
.preset-card:focus-within .preset-card__icon-actions { opacity: 1; }

.preset-card__icon-btn {
  width: 26px;
  height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-sm);
  color: var(--text-tertiary);
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--border-subtle);
  transition: background var(--t-fast), color var(--t-fast), border-color var(--t-fast);
  backdrop-filter: blur(4px);
}

.preset-card__icon-btn:hover {
  background: var(--surface-3);
  color: var(--text-primary);
  border-color: var(--border-default);
}

.preset-card__icon-btn--danger:hover {
  color: var(--error);
  border-color: rgba(255, 77, 77, 0.4);
}

.preset-card__icon-btn .btn__icon { width: 12px; height: 12px; }

/* ============================================================
   9. Modal / Bottom Sheet
   ============================================================ */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: var(--surface-overlay);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 100;
  display: none;
  animation: fade-in var(--t-base);
}

.modal-backdrop[data-open] { display: flex; align-items: center; justify-content: center; padding: var(--gutter); }

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal {
  width: 100%;
  max-width: 560px;
  max-height: calc(100vh - var(--s-8));
  background: var(--surface-2);
  border: 1px solid var(--border-default);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-modal);
  display: flex;
  flex-direction: column;
  animation: scale-in var(--t-spring);
  overflow: hidden;
}

@keyframes scale-in {
  from { opacity: 0; transform: scale(0.94) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal--wide { max-width: 720px; }

.modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--s-5) var(--s-6) var(--s-4);
  gap: var(--s-4);
}

.modal__title {
  font-size: var(--fs-h1);
  font-weight: var(--fw-semibold);
  letter-spacing: -0.015em;
}

.modal__body {
  flex: 1;
  overflow-y: auto;
  padding: 0 var(--s-6) var(--s-5);
  display: flex;
  flex-direction: column;
  gap: var(--s-4);
}

.modal__foot {
  display: flex;
  gap: var(--s-2);
  padding: var(--s-4) var(--s-6) var(--s-6);
  border-top: 1px solid var(--border-subtle);
  background: linear-gradient(180deg, transparent, var(--surface-1));
}

.modal__foot .btn { flex: 1; }
.modal__foot .btn--primary { flex: 2; }

/* Bottom sheet (device picker, mobile-first) */
.sheet {
  width: 100%;
  max-width: 480px;
  background: var(--surface-2);
  border: 1px solid var(--border-default);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-modal);
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - var(--s-8));
  animation: slide-up var(--t-spring);
}

@media (max-width: 600px) {
  .modal-backdrop[data-open] {
    align-items: flex-end;
    padding: 0;
  }
  .sheet {
    border-radius: var(--r-xl) var(--r-xl) 0 0;
    max-height: 85vh;
    max-width: none;
  }
  .modal {
    border-radius: var(--r-xl) var(--r-xl) 0 0;
    max-height: 92vh;
    max-width: none;
  }
}

@keyframes slide-up {
  from { transform: translateY(40px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.sheet__head {
  padding: var(--s-5) var(--s-6) var(--s-3);
  display: flex;
  flex-direction: column;
  gap: var(--s-1);
}

.sheet__title {
  font-size: var(--fs-h1);
  font-weight: var(--fw-semibold);
}

.sheet__subtitle {
  font-size: var(--fs-small);
  color: var(--text-tertiary);
}

.sheet__body {
  flex: 1;
  overflow-y: auto;
  padding: 0 var(--s-3) var(--s-3);
}

.sheet__foot {
  padding: var(--s-3) var(--s-6) var(--s-5);
}

.sheet-item {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-3);
  border-radius: var(--r-md);
  background: transparent;
  border: 1px solid transparent;
  width: 100%;
  text-align: left;
  transition: background var(--t-fast), border-color var(--t-fast);
  color: var(--text-primary);
}

.sheet-item:hover {
  background: var(--surface-3);
  border-color: var(--border-default);
}

.sheet-item:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.sheet-item__status {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--idle);
  flex-shrink: 0;
}

.sheet-item--running .sheet-item__status { background: var(--firing); animation: pulse-dot 1.6s ease-in-out infinite; }

.sheet-item__info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sheet-item__name {
  font-size: var(--fs-body);
  font-weight: var(--fw-medium);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sheet-item__status-text {
  font-size: var(--fs-small);
  color: var(--text-tertiary);
}

.sheet-item--running .sheet-item__status-text { color: var(--firing); }

.sheet-item__chevron {
  color: var(--text-tertiary);
  flex-shrink: 0;
}

/* ============================================================
   10. Phase Editor (in modal)
   ============================================================ */

.phase-list {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
}

.phase-row {
  background: var(--surface-1);
  border: 1px solid var(--border-default);
  border-radius: var(--r-md);
  padding: var(--s-3);
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
}

.phase-row__head {
  display: flex;
  align-items: center;
  gap: var(--s-2);
}

.phase-row__num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: var(--r-sm);
  background: var(--surface-3);
  font-size: var(--fs-micro);
  font-weight: var(--fw-semibold);
  font-family: var(--font-mono);
  color: var(--text-secondary);
  font-feature-settings: 'tnum';
}

.phase-row__type-select {
  flex: 1;
  height: 32px;
  padding: 0 var(--s-3);
  background: var(--surface-input);
  border: 1px solid var(--border-default);
  border-radius: var(--r-sm);
  color: var(--text-primary);
  font-size: var(--fs-small);
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='rgba(255,255,255,0.5)' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'><path d='M4 6l4 4 4-4'/></svg>");
  background-repeat: no-repeat;
  background-position: right 8px center;
  padding-right: 28px;
}

.phase-row__controls {
  display: flex;
  gap: 2px;
}

.phase-row__control {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-sm);
  color: var(--text-tertiary);
  background: transparent;
  transition: background var(--t-fast), color var(--t-fast);
}

.phase-row__control:hover {
  background: var(--surface-3);
  color: var(--text-primary);
}

.phase-row__control--danger:hover {
  background: var(--error-bg);
  color: var(--error);
}

.phase-row__fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s-3);
}

.phase-row__fields--four { grid-template-columns: 1fr 1fr 1fr 1fr; }

@media (max-width: 600px) {
  .phase-row__fields,
  .phase-row__fields--four { grid-template-columns: 1fr 1fr; }
}

.phase-row__field {
  display: flex;
  flex-direction: column;
  gap: var(--s-1);
}

.phase-row__field--span2 { grid-column: span 2; }

.phase-row__field-label {
  font-size: var(--fs-micro);
  color: var(--text-tertiary);
  letter-spacing: 0.02em;
}

.phase-row__field-input {
  height: 32px;
  padding: 0 var(--s-2);
  background: var(--surface-input);
  border: 1px solid var(--border-default);
  border-radius: var(--r-sm);
  color: var(--text-primary);
  font-size: var(--fs-small);
  font-family: var(--font-mono);
  font-feature-settings: 'tnum';
  transition: border-color var(--t-fast);
}

.phase-row__field-input:focus {
  border-color: var(--border-focus);
  background: var(--surface-input);
  box-shadow: 0 0 0 2px var(--accent-bg);
  outline: none;
}

.phase-row__field-select {
  height: 32px;
  padding: 0 24px 0 var(--s-2);
  background: var(--surface-input);
  border: 1px solid var(--border-default);
  border-radius: var(--r-sm);
  color: var(--text-primary);
  font-size: var(--fs-small);
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='rgba(255,255,255,0.5)' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'><path d='M4 6l4 4 4-4'/></svg>");
  background-repeat: no-repeat;
  background-position: right 6px center;
}

.add-phase-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  width: 100%;
  height: 44px;
  background: transparent;
  border: 1px dashed var(--border-strong);
  border-radius: var(--r-md);
  color: var(--text-secondary);
  font-size: var(--fs-small);
  font-weight: var(--fw-medium);
  transition: color var(--t-fast), border-color var(--t-fast), background var(--t-fast);
}

.add-phase-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-bg);
}

/* ============================================================
   11. Misc / Utility
   ============================================================ */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--s-3);
  padding: var(--s-9) var(--s-5);
  background: var(--surface-1);
  border: 1px dashed var(--border-default);
  border-radius: var(--r-lg);
  text-align: center;
}

.empty-state__icon {
  width: 40px;
  height: 40px;
  color: var(--text-tertiary);
}

.empty-state__title {
  font-size: var(--fs-h2);
  font-weight: var(--fw-medium);
  color: var(--text-secondary);
}

.empty-state__desc {
  font-size: var(--fs-small);
  color: var(--text-tertiary);
  max-width: 360px;
  line-height: var(--lh-base);
}

.divider {
  height: 1px;
  background: var(--border-subtle);
  margin: var(--s-3) 0;
}

.toast-container {
  position: fixed;
  bottom: var(--s-5);
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  pointer-events: none;
}

.toast {
  padding: var(--s-3) var(--s-5);
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-elev);
  color: var(--text-primary);
  font-size: var(--fs-small);
  font-weight: var(--fw-medium);
  pointer-events: auto;
  animation: toast-in var(--t-spring);
  display: flex;
  align-items: center;
  gap: var(--s-2);
}

.toast--error { border-color: var(--error); }
.toast--success { border-color: var(--success); }
.toast__icon { width: 16px; height: 16px; flex-shrink: 0; }
.toast--error .toast__icon { color: var(--error); }
.toast--success .toast__icon { color: var(--success); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

.device-meta-row {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  background: var(--surface-1);
  border: 1px solid var(--border-default);
  border-radius: var(--r-md);
  margin-bottom: var(--s-2);
}

.device-meta-row__info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.device-meta-row__name {
  font-size: var(--fs-body);
  font-weight: var(--fw-medium);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.device-meta-row__url {
  font-family: var(--font-mono);
  font-size: var(--fs-micro);
  color: var(--text-tertiary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.device-meta-row__actions {
  display: flex;
  gap: var(--s-1);
  flex-shrink: 0;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

/* iOS Safari aspect-ratio + img bug 予防：img には height auto を明示 */
img { height: auto; }
