:root {
  color-scheme: light;
  --page: #d8d9d6;
  --panel: #ffffff;
  --soft: #f3f4f5;
  --line: #747474;
  --line-soft: #d8dadd;
  --text: #111111;
  --muted: #62676d;
  --blue: #244ac7;
  --up: #087c2e;
  --down: #c51b1b;
  --market-up: #007aff;
  --market-down: #d32f2f;
}

* { box-sizing: border-box; }

html {
  font-family: Arial, "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;
  background: var(--page);
}

body {
  margin: 0;
  min-width: 320px;
  color: var(--text);
  background-color: var(--page);
  background-image:
    radial-gradient(circle at 1px 1px, rgba(0, 0, 0, .11) .7px, transparent .8px),
    linear-gradient(135deg, rgba(255,255,255,.3), rgba(255,255,255,0) 42%);
  background-size: 4px 4px, 100% 100%;
}

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

.topbar {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  min-height: 58px;
  padding: 10px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  background: transparent;
}

.site-name { color: #202020; font-size: clamp(1.05rem, 2.4vw, 1.4rem); font-weight: 900; letter-spacing: .075em; }
.site-name-link { text-decoration: none; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.test-link { padding: 7px 9px; color: var(--muted); border: 1px solid #888; background: rgba(255,255,255,.7); font-size: .75rem; font-weight: 800; text-decoration: none; }
.test-link:hover { color: var(--blue); border-color: var(--blue); }
body:has(#detailPage) .topbar { justify-content: flex-end; }

.eyebrow, .section-kicker {
  margin: 0 0 5px;
  color: var(--blue);
  font-size: .75rem;
  font-weight: 800;
  letter-spacing: .13em;
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(1.4rem, 4vw, 2rem); letter-spacing: -.035em; }
h2 { margin-bottom: 0; font-size: clamp(1.2rem, 3vw, 1.65rem); letter-spacing: -.025em; }

main { width: min(1180px, calc(100% - 32px)); margin: 0 auto; padding-bottom: 64px; }
.sentiment, .market-section, .diagnostics { padding-top: 22px; }
.market-section { margin-top: 34px; border-top: 1px solid #aaa; }
.market-section:first-child { margin-top: 0; padding-top: 8px; border-top: 0; }
.market-section > .section-heading { justify-content: flex-end; margin-bottom: 9px; }

.section-heading { display: flex; justify-content: space-between; align-items: end; gap: 24px; margin-bottom: 16px; }
.section-note { max-width: 380px; margin-bottom: 2px; color: var(--muted); font-size: .82rem; line-height: 1.55; text-align: right; }
.section-heading.compact { align-items: center; }

.sentiment-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.sentiment-card { padding: 13px; border: 1px solid #9b9b9b; border-radius: 0; background: #fff; }
.sentiment-card h3 { margin: 0 0 10px; font-size: .95rem; }
.vote-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.vote-button { min-height: 38px; border: 1px solid #969696; border-radius: 0; background: linear-gradient(#fff, #ececec); cursor: pointer; font-size: .82rem; font-weight: 800; box-shadow: 1px 2px 3px rgba(0,0,0,.22), inset 0 1px 0 rgba(255,255,255,.95); transition: transform .12s ease, box-shadow .12s ease, border-color .12s ease; }
.vote-button:hover { background: linear-gradient(#fff, #e3e8f3); border-color: var(--blue); transform: translateY(-1px); box-shadow: 1px 3px 5px rgba(0,0,0,.24), inset 0 1px 0 #fff; }
.vote-button:active { transform: translateY(1px); box-shadow: inset 1px 2px 3px rgba(0,0,0,.18); }
.vote-button.buy { color: var(--market-up); }
.vote-button.sell { color: var(--market-down); }
.vote-button:disabled { opacity: .55; cursor: not-allowed; }
.sentiment-bar { height: 7px; overflow: hidden; display: flex; margin-top: 11px; background: #ddd; }
.sentiment-bar span:first-child { background: var(--market-up); }
.sentiment-bar span:last-child { background: var(--market-down); }
.vote-counts { display: flex; justify-content: space-between; margin-top: 6px; color: var(--muted); font-size: .72rem; }

.stream-stats { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: .8rem; font-variant-numeric: tabular-nums; }

.market-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 7px; }
.market-card {
  position: relative;
  min-width: 0;
  aspect-ratio: 1.12 / 1;
  overflow: hidden;
  border: 1px solid #666;
  border-radius: 0;
  background: var(--panel);
  box-shadow:
    2px 3px 0 rgba(68, 68, 68, .42),
    4px 6px 9px rgba(0, 0, 0, .2),
    inset 0 1px 0 rgba(255,255,255,.95);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.market-card * { -webkit-user-select: none; user-select: none; }

.market-grid:not(.detail-grid) .market-card[role="link"] {
  cursor: pointer;
  transition: transform .14s ease, box-shadow .14s ease, border-color .14s ease;
}
.market-grid:not(.detail-grid) .market-card[role="link"]:hover,
.market-grid:not(.detail-grid) .market-card[role="link"]:focus-visible {
  z-index: 1;
  outline: none;
  border-color: #1d4fb8;
  transform: translateY(-2px);
  box-shadow: 3px 5px 0 rgba(36, 74, 199, .28), 5px 9px 14px rgba(0, 0, 0, .22);
}

.test-grid .market-card[role="link"] {
  touch-action: pan-y;
}
.test-grid.layout-dragging .market-card { transition: none; }
.test-grid .market-card.layout-drag-source { display: none; }
.layout-drop-placeholder {
  width: 100%;
  aspect-ratio: 1.12 / 1.06;
  display: grid;
  place-content: center;
  gap: 5px;
  border: 3px dashed var(--market-up);
  background: rgba(0, 122, 255, .09);
  color: var(--market-up);
  font-size: .78rem;
  font-weight: 900;
  text-align: center;
  animation: placeholderPulse .8s ease-in-out infinite alternate;
}
.layout-drop-placeholder::before { content: "+"; font-size: 2rem; line-height: 1; }
.layout-drop-placeholder::after { content: "ここに挿入"; }
.layout-drag-ghost { position: fixed; z-index: 100; margin: 0; pointer-events: none; opacity: .88; transform: translate(-50%, -50%) rotate(1.5deg) scale(.92); box-shadow: 5px 8px 20px rgba(0,0,0,.3); }
@keyframes placeholderPulse { to { background: rgba(0, 122, 255, .18); } }

.card-content {
  height: 100%;
  padding: 0 8px 7px;
  display: grid;
  grid-template-rows: auto auto minmax(70px, 1fr) auto auto;
}

.card-titlebar {
  margin: 0 -8px;
  min-height: 29px;
  padding: 5px 7px 4px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  border-bottom: 1px solid #b2b2b2;
  background: linear-gradient(#ffffff 0%, #ededed 52%, #d2d2d2 100%);
  box-shadow: inset 0 1px 0 #fff, inset 0 -1px 0 #bbb;
}

.card-name { margin: 0; font-size: 1.05rem; line-height: 1.2; font-weight: 900; letter-spacing: -.015em; }
.market-name-note { font-size: .67em; font-weight: 700; letter-spacing: 0; white-space: nowrap; }
.card-symbol { color: var(--muted); font-size: .67rem; font-weight: 700; letter-spacing: .04em; }
.card-change {
  padding: 4px 0 0;
  display: flex;
  justify-content: center;
  align-items: baseline;
  gap: .025em;
  text-align: center;
  font-size: clamp(2rem, 3.8vw, 3rem);
  line-height: .98;
  font-weight: 900;
  font-family: "Arial Black", Arial, "Helvetica Neue", sans-serif;
  letter-spacing: -.018em;
  font-variant-numeric: tabular-nums;
}
.change-sign { display: inline-block; font-family: Arial, "Helvetica Neue", sans-serif; font-weight: 800; transform: translateY(-.02em); }
.change-percent-mark { display: inline-block; margin-left: .035em; font-size: .58em; line-height: 1; vertical-align: .08em; letter-spacing: 0; }
.positive .card-change { color: var(--market-up); }
.negative .card-change { color: var(--market-down); }

.chart-wrap {
  min-height: 0;
  position: relative;
  margin: 2px -2px 0;
  overflow: hidden;
  border-top: 1px solid #ddd;
  border-bottom: 1px solid #aaa;
  background: #fff;
}
.chart { width: 100%; height: calc(100% - 17px); overflow: visible; }
.chart-grid { stroke: #e2e2e2; stroke-width: 1; vector-effect: non-scaling-stroke; }
.chart-percent-line { stroke: #72c9db; stroke-width: 1; vector-effect: non-scaling-stroke; }
.chart-percent-label {
  fill: #26829a;
  font-size: 10.5px;
  font-family: Arial, "Helvetica Neue", sans-serif;
  font-weight: 700;
  paint-order: stroke;
  stroke: rgba(255, 255, 255, .88);
  stroke-width: 2px;
  stroke-linejoin: round;
}
.chart-extreme text {
  font-size: 10.5px;
  font-family: Arial, "Helvetica Neue", sans-serif;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.chart-extreme-high .chart-extreme-tag { fill: #dff2ff; }
.chart-extreme-high text { fill: #164f7a; }
.chart-extreme-low .chart-extreme-tag { fill: #ffe2e2; }
.chart-extreme-low text { fill: #8f2424; }
.chart-baseline { stroke: #e12121; stroke-width: 1; vector-effect: non-scaling-stroke; }
.chart-line { fill: none; stroke: var(--blue); stroke-width: 1.65; vector-effect: non-scaling-stroke; stroke-linecap: round; stroke-linejoin: round; }
.chart-current-halo { fill: #fff; stroke: #111; stroke-width: 1.7; vector-effect: non-scaling-stroke; }
.chart-current-dot { fill: #111; stroke: none; }
.chart-area { opacity: .7; }
.axis-labels { position: absolute; inset: auto 3px 1px; z-index: 2; display: flex; justify-content: space-between; color: #656565; font-size: .62rem; font-variant-numeric: tabular-nums; pointer-events: none; }

.card-quote { display: flex; justify-content: center; align-items: baseline; gap: 7px; padding-top: 3px; white-space: nowrap; }
.card-price { font-size: clamp(1.35rem, 2.55vw, 1.9rem); font-weight: 900; letter-spacing: -.025em; font-variant-numeric: tabular-nums; }
.card-unit { margin-left: 3px; color: var(--muted); font-size: .65rem; letter-spacing: 0; }
.point-change { font-size: .76rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.positive .point-change { color: var(--market-up); }
.negative .point-change { color: var(--market-down); }
.card-footer { display: flex; justify-content: flex-start; align-items: baseline; gap: 8px; color: var(--muted); font-size: .63rem; }
.card-footer strong { color: var(--text); font-weight: 750; }
.market-status { margin-left: auto; display: inline-flex; align-items: center; gap: 4px; font-weight: 800; letter-spacing: .035em; }
.market-status.live { color: #258842; }
.market-status-dot { width: 7px; height: 7px; border-radius: 50%; background: #34c759; box-shadow: 0 0 0 1px rgba(17, 124, 61, .16); animation: marketLivePulse 1.5s ease-in-out infinite; }
.market-status.closed { color: var(--muted); }
.market-status.delayed { color: #a66a00; }
@keyframes marketLivePulse { 50% { opacity: .28; transform: scale(.72); } }

.empty-chart { position: absolute; inset: 0 0 17px; z-index: 2; display: grid; place-items: center; color: var(--muted); font-size: .76rem; text-align: center; }
.empty-chart.history-unavailable { color: #8f2424; font-weight: 700; }
.skeleton { background: linear-gradient(90deg, #eee, #fafafa, #eee); background-size: 200% 100%; animation: shimmer 1.7s infinite; }

.test-heading { display: flex; justify-content: space-between; align-items: baseline; gap: 18px; padding: 13px 0 12px; color: var(--muted); font-size: .78rem; }
.test-heading strong { color: var(--text); font-size: 1rem; }
.test-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.test-grid .market-card,
.test-grid > .add-chart-card { width: 100%; aspect-ratio: 1.12 / 1.06; }
.test-grid .card-content { grid-template-rows: auto auto minmax(70px, 1fr) auto auto auto; }
.test-source { display: flex; justify-content: space-between; gap: 8px; padding-top: 3px; color: var(--muted); font-size: .58rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.add-chart-card {
  align-self: start;
  min-height: 0;
  aspect-ratio: 1.12 / 1.06;
  display: grid;
  place-content: center;
  gap: 8px;
  border: 1px dashed #6f747a;
  border-radius: 0;
  background: rgba(255,255,255,.42);
  box-shadow:
    2px 3px 0 rgba(68, 68, 68, .42),
    4px 6px 9px rgba(0, 0, 0, .2),
    inset 0 1px 0 rgba(255,255,255,.95);
  color: #40454b;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  transition: background .14s ease, border-color .14s ease, color .14s ease, transform .14s ease;
}
.add-chart-card:hover, .add-chart-card:focus-visible { outline: none; border-color: var(--blue); background: #fff; color: var(--blue); transform: translateY(-2px); }
.add-chart-icon { font-size: 2.2rem; line-height: .8; font-weight: 400; }
.chart-picker { width: min(680px, calc(100% - 28px)); max-height: min(680px, calc(100% - 28px)); padding: 0; border: 1px solid #52565a; border-radius: 0; box-shadow: 0 18px 58px rgba(0,0,0,.26); background: #fff; color: var(--text); }
.chart-picker::backdrop { background: rgba(25, 30, 36, .28); }
.chart-picker-head { display: flex; align-items: center; justify-content: space-between; padding: 15px 17px 11px; border-bottom: 1px solid var(--line-soft); }
.chart-picker h2 { margin: 0; font-size: 1.1rem; }
.chart-picker > p { margin: 13px 17px 10px; color: var(--muted); font-size: .82rem; }
.picker-close { width: 31px; height: 31px; border: 1px solid #8a8e93; border-radius: 0; background: #fff; color: var(--text); font-size: 1.3rem; cursor: pointer; }
.picker-categories { display: flex; flex-wrap: wrap; gap: 5px; padding: 0 17px 13px; border-bottom: 1px solid var(--line-soft); }
.picker-category { border: 1px solid #9ca0a4; border-radius: 0; background: #fff; color: #444; padding: 6px 9px; font: inherit; font-size: .78rem; font-weight: 700; cursor: pointer; }
.picker-category.active { border-color: var(--blue); background: var(--blue); color: #fff; }
.picker-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; padding: 14px 17px 18px; }
.picker-symbol { min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 8px; align-items: baseline; padding: 11px; border: 1px solid #969a9e; border-radius: 0; background: #fff; color: var(--text); text-align: left; font: inherit; cursor: pointer; }
.picker-symbol span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 800; }
.picker-symbol small { grid-column: 1; color: var(--muted); font-size: .68rem; }
.picker-symbol b { grid-column: 2; grid-row: 1 / span 2; color: var(--blue); font-size: .75rem; }
.picker-symbol:not(:disabled):hover, .picker-symbol:not(:disabled):focus-visible { outline: none; border-color: var(--blue); background: #f3f8ff; }
.picker-symbol:disabled { opacity: .48; cursor: default; }

.detail-layout {
  display: grid;
  grid-template-columns: minmax(0, 760px) minmax(210px, 1fr);
  gap: 26px;
  align-items: start;
  padding-top: 24px;
}
.detail-grid { display: block; }
.detail-grid .market-card { width: 100%; aspect-ratio: 1.45 / 1; }
.detail-grid .card-content { padding: 0 14px 10px; grid-template-rows: auto auto minmax(170px, 1fr) auto auto; }
.detail-grid .card-titlebar { margin: 0 -14px; min-height: 40px; padding: 7px 12px 6px; }
.detail-grid .card-name { font-size: clamp(1.2rem, 3vw, 1.7rem); }
.detail-grid .card-symbol { font-size: .78rem; }
.detail-grid .card-change { padding-top: 7px; font-size: clamp(3.2rem, 8vw, 5rem); }
.detail-grid .card-price { font-size: clamp(1.7rem, 4vw, 2.5rem); }
.detail-grid .point-change { font-size: .92rem; }
.detail-grid .card-footer { font-size: .76rem; }
.detail-grid .chart-percent-label,
.detail-grid .chart-extreme text { font-size: 9px; }
.detail-grid .axis-labels { font-size: .72rem; }
.detail-sentiment { padding-top: 18px; }
.detail-sentiment-grid { display: block; }
.detail-sentiment .sentiment-card { padding: 16px; }
.detail-sentiment .sentiment-card h3 { display: none; }
.detail-sentiment .vote-actions { display: flex; justify-content: space-between; gap: 0; }
.detail-sentiment .vote-button { width: auto; min-height: 46px; padding-inline: .65em; font-size: .95rem; }
.detail-sentiment .sentiment-bar { height: 10px; }
.detail-actions {
  position: sticky;
  top: 20px;
  display: grid;
  gap: 10px;
  padding: 16px;
  border: 1px solid #858585;
  background: rgba(255, 255, 255, .9);
  box-shadow: 2px 3px 0 rgba(68, 68, 68, .3), 4px 7px 12px rgba(0, 0, 0, .16);
}
.detail-action {
  width: 100%;
  min-height: 62px;
  padding: 12px 20px;
  border: 1px solid #777;
  border-radius: 0;
  background: linear-gradient(#fff, #e7e7e7);
  box-shadow: 1px 2px 3px rgba(0,0,0,.2), inset 0 1px 0 #fff;
  cursor: pointer;
  font-size: 1.05rem;
  font-weight: 800;
}
.detail-action:not(:disabled):hover { border-color: var(--blue); background: #eef3ff; }
.detail-action.primary { background: #252525; color: #fff; border-color: #111; box-shadow: 1px 3px 5px rgba(0,0,0,.28); }
.detail-action.danger { color: var(--market-down); }
.detail-action:disabled { opacity: .46; cursor: not-allowed; box-shadow: none; }

.diagnostics { margin-top: 34px; padding-top: 18px; border-top: 1px solid #aaa; color: var(--muted); }
.diagnostics summary { color: var(--text); cursor: pointer; font-weight: 800; }
.diagnostic-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; margin-top: 14px; overflow: hidden; border: 1px solid #999; border-radius: 0; background: #999; }
.diagnostic-grid div { padding: 11px; display: flex; flex-direction: column; gap: 5px; background: #fff; }
.diagnostic-grid span { font-size: .72rem; }
.diagnostic-grid strong { color: var(--text); font-size: .88rem; font-variant-numeric: tabular-nums; }
.diagnostics p { margin: 12px 0 0; max-width: 760px; font-size: .8rem; line-height: 1.65; }

.toast { position: fixed; left: 50%; bottom: 24px; z-index: 20; max-width: calc(100% - 32px); padding: 10px 15px; border: 1px solid #555; border-radius: 0; background: #fff; box-shadow: 0 8px 28px rgba(0,0,0,.2); opacity: 0; transform: translate(-50%, 20px); pointer-events: none; transition: .25s; font-size: .84rem; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Keep each chart close to its familiar size, then add a column on wider screens. */
@media (min-width: 1440px) {
  body:not(:has(#detailPage)) .topbar,
  body:not(:has(#detailPage)) main {
    width: min(1480px, calc(100% - 48px));
  }

  .market-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .test-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (min-width: 1720px) {
  body:not(:has(#detailPage)) .topbar,
  body:not(:has(#detailPage)) main {
    width: min(1840px, calc(100% - 56px));
  }

  .market-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .test-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
}

@keyframes pulse { 50% { opacity: .4; } }
@keyframes shimmer { to { background-position: -200% 0; } }

@media (max-width: 850px) {
  .sentiment-grid, .market-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .diagnostic-grid { grid-template-columns: repeat(2, 1fr); }
  .card-change { font-size: clamp(2.2rem, 8vw, 3.2rem); }
  .detail-layout { grid-template-columns: 1fr; gap: 18px; }
  .detail-grid { grid-template-columns: 1fr; }
  .detail-grid .card-change { font-size: clamp(3rem, 11vw, 4.5rem); }
  .detail-actions { position: static; }
  .test-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .picker-list { grid-template-columns: 1fr; }
}

@media (max-width: 540px) {
  .topbar { width: min(100% - 18px, 1180px); padding-top: 16px; align-items: center; }
  main { width: min(100% - 18px, 1180px); }
  h1 { font-size: 1.3rem; }
  .section-heading { display: block; }
  .section-note { margin-top: 9px; text-align: left; }
  .sentiment-grid, .market-grid { gap: 4px; }
  .sentiment-card { padding: 10px; }
  .market-card { aspect-ratio: 1.12 / 1; box-shadow: 1px 2px 0 rgba(68,68,68,.4), 3px 5px 7px rgba(0,0,0,.18); }
  .card-content { padding: 0 5px 5px; grid-template-rows: auto auto minmax(50px, 1fr) auto auto; }
  .card-titlebar { margin: 0 -5px; padding: 4px 5px; }
  .card-name { font-size: .94rem; }
  .card-symbol { font-size: .58rem; }
  .card-change { font-size: clamp(1.8rem, 10vw, 2.7rem); }
  .card-price { font-size: clamp(1.2rem, 6.2vw, 1.6rem); }
  .point-change { font-size: .65rem; }
  .card-footer { font-size: .57rem; }
  .axis-labels { font-size: .55rem; }
  .stream-stats { margin-top: 10px; }
  .test-heading { display: block; }
  .test-heading span { display: block; margin-top: 4px; }
  .detail-layout { padding-top: 14px; }
  .detail-grid .market-card { aspect-ratio: 1.12 / 1; }
  .detail-grid .card-content { padding: 0 7px 7px; grid-template-rows: auto auto minmax(90px, 1fr) auto auto; }
  .detail-grid .card-titlebar { margin: 0 -7px; min-height: 34px; padding: 5px 7px; }
  .detail-grid .card-name { font-size: 1.08rem; }
  .detail-grid .card-change { font-size: clamp(2.6rem, 16vw, 4rem); }
  .detail-grid .card-price { font-size: clamp(1.45rem, 8vw, 2rem); }
  .detail-sentiment .vote-button { width: auto; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
