/* ==========================================================================
   JPYC ガス代トラッカー ウィジェットスタイルシート
   - 超軽量・自己完結型
   - コンテナクエリ対応（サイズに応じた自動レイアウト切替）
   ========================================================================== */

:root {
  --bg-color: #0b1120;
  --card-bg: #131d31;
  --card-bg-hover: #18243c;
  --border-color: #1e293b;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --accent-cyan: #22d3ee;
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-color);
  color: var(--text-main);
  font-family: var(--font-family);
  user-select: none;
}

/* ウィジェット全体枠（コンテナクエリ有効化） */
.widget-root {
  container-type: size;
  container-name: widget;
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  padding: 7px 10px;
  background: var(--bg-color);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  overflow: hidden;
}

/* ヘッダー（全レイアウト共通: 左にタイトル、右にPowered byリンク） */
.widget-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: clamp(6px, 1.2cqh, 12px);
  flex-shrink: 0;
  line-height: 1.2;
}

.widget-title {
  font-size: clamp(12px, 1cqw + 8.5px, 17px);
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.widget-brand-link {
  font-size: clamp(10px, 0.8cqw + 7.5px, 14px);
  color: var(--text-dim);
  text-decoration: none;
  white-space: nowrap;
  transition: color 0.15s ease;
}

.widget-brand-link:hover {
  color: var(--accent-cyan);
}

/* チェーンカードの共通項目 */
.chain-item {
  display: flex;
  align-items: center;
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 5px 8px;
  min-width: 0;
  overflow: hidden;
  transition: background-color 0.15s ease;
}

.chain-item:hover {
  background: var(--card-bg-hover);
}

.chain-icon-wrap {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  margin-right: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chain-icon-svg {
  width: 100%;
  height: 100%;
  display: block;
}

.chain-name-col {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
  overflow: hidden;
}

.chain-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}

.chain-price-col {
  text-align: right;
  flex-shrink: 0;
  margin-left: 8px;
}

.chain-price-jpy {
  font-size: 14px;
  font-weight: 800;
  color: var(--text-main);
  font-family: var(--font-mono);
  white-space: nowrap;
}

/* スケルトン表示アニメーション */
@keyframes pulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 0.8; }
}

.skeleton-box {
  background: rgba(30, 41, 59, 0.6);
  border-radius: 6px;
  animation: pulse 1.5s ease-in-out infinite;
}

/* ==========================================================================
   レイアウト別定義
   ========================================================================== */

/* 1. 横一列レイアウト (horizontal: 上段ヘッダー + 下段4チェーン横並び) */
.layout-horizontal .widget-chains {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  flex: 1;
  min-width: 0;
}

.layout-horizontal .chain-item {
  padding: 4px clamp(6px, 1cqw, 12px);
}

.layout-horizontal .chain-icon-wrap {
  width: clamp(18px, 1.2cqw + 12px, 26px);
  height: clamp(18px, 1.2cqw + 12px, 26px);
  margin-right: clamp(4px, 0.8cqw, 8px);
}

.layout-horizontal .chain-name {
  font-size: clamp(11px, 0.9cqw + 7.5px, 16px);
}

.layout-horizontal .chain-price-jpy {
  font-size: clamp(13px, 1.2cqw + 8px, 20px);
}

/* 横幅が狭い場合（480px未満など）の省スペース化 */
@container widget (max-width: 480px) {
  .layout-horizontal .chain-name {
    font-size: 11px;
  }
  .layout-horizontal .chain-price-jpy {
    font-size: 12px;
  }
  .layout-horizontal .chain-icon-wrap {
    width: 18px;
    height: 18px;
    margin-right: 4px;
  }
}

@container widget (max-width: 400px) {
  .layout-horizontal .widget-title {
    font-size: 10px;
  }
  .layout-horizontal .widget-brand-link {
    font-size: 8.5px;
  }
  .layout-horizontal .chain-name {
    display: none;
  }
  .layout-horizontal .chain-price-jpy {
    font-size: 11px;
  }
}

/* 2. 縦一列レイアウト (vertical: 上段ヘッダー + 縦4段カードを均等に拡大) */
.layout-vertical .widget-chains {
  display: grid;
  grid-template-rows: repeat(4, 1fr);
  gap: 8px;
  flex: 1;
}

.layout-vertical .chain-item {
  padding: clamp(10px, 2.5cqh, 24px) clamp(16px, 3.5cqw, 26px);
}

.layout-vertical .chain-icon-wrap {
  width: clamp(30px, 4.5cqw + 16px, 50px);
  height: clamp(30px, 4.5cqw + 16px, 50px);
  margin-right: clamp(12px, 2cqw, 18px);
}

.layout-vertical .chain-name {
  font-size: clamp(15px, 2.5cqw + 9px, 26px);
}

.layout-vertical .chain-price-jpy {
  font-size: clamp(18px, 3.8cqw + 10px, 36px);
}

/* 3. 2x2 グリッドレイアウト (grid: 上段ヘッダー + 2列2行) */
.layout-grid .widget-chains {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 8px;
  flex: 1;
}

.layout-grid .chain-item {
  padding: clamp(8px, 2.5cqh, 20px) clamp(10px, 2.2cqw, 20px);
}

.layout-grid .chain-icon-wrap {
  width: clamp(22px, 2.2cqw + 12px, 40px);
  height: clamp(22px, 2.2cqw + 12px, 40px);
  margin-right: clamp(6px, 1.2cqw, 14px);
}

.layout-grid .chain-name {
  font-size: clamp(12px, 1.4cqw + 7.5px, 22px);
}

.layout-grid .chain-price-jpy {
  font-size: clamp(14px, 2.2cqw + 8px, 28px);
}

/* ==========================================================================
   コンテナクエリによる自動レイアウト (layout-auto / パラメータなし時)
   ========================================================================== */

/* デフォルト（指定なし・横長中型）: 2x2 グリッド */
.layout-auto .widget-chains {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 8px;
  flex: 1;
}

/* ① 高さ <= 120px ➔ 横一列バナーに自動変化 */
@container widget (max-height: 120px) {
  .layout-auto .widget-chains {
    grid-template-columns: repeat(4, 1fr) !important;
    grid-template-rows: 1fr !important;
    gap: 6px !important;
  }
  .layout-auto .chain-item {
    padding: 4px clamp(6px, 1cqw, 12px);
  }
  .layout-auto .chain-icon-wrap {
    width: clamp(18px, 1.2cqw + 12px, 26px);
    height: clamp(18px, 1.2cqw + 12px, 26px);
    margin-right: clamp(4px, 0.8cqw, 8px);
  }
  .layout-auto .chain-name {
    font-size: clamp(11px, 0.9cqw + 7.5px, 16px);
  }
  .layout-auto .chain-price-jpy {
    font-size: clamp(13px, 1.2cqw + 8px, 20px);
  }
}

/* ② 縦横比で縦が長い（アスペクト比 <= 1/1 かつ 高さ > 120px） ➔ 縦一列サイドバーに自動変化 */
@container widget (aspect-ratio <= 1 / 1) and (min-height: 121px) {
  .layout-auto .widget-chains {
    display: grid !important;
    grid-template-columns: 1fr !important;
    grid-template-rows: repeat(4, 1fr) !important;
    gap: 8px !important;
  }
  .layout-auto .chain-item {
    padding: clamp(10px, 2.5cqh, 24px) clamp(16px, 3.5cqw, 26px);
  }
  .layout-auto .chain-icon-wrap {
    width: clamp(30px, 4.5cqw + 16px, 50px);
    height: clamp(30px, 4.5cqw + 16px, 50px);
    margin-right: clamp(12px, 2cqw, 18px);
  }
  .layout-auto .chain-name {
    font-size: clamp(15px, 2.5cqw + 9px, 26px);
  }
  .layout-auto .chain-price-jpy {
    font-size: clamp(18px, 3.8cqw + 10px, 36px);
  }
}
