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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Noto Sans JP", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  color: #333;
  background: #f5f7fa;
}

/* ========== HEADER ========== */
header {
  background: linear-gradient(135deg, #1a237e 0%, #283593 100%);
  color: white;
  padding: 1.25rem 1rem;
  text-align: center;
}

header h1 {
  font-size: 1.2rem;
  font-weight: 700;
  line-height: 1.4;
}

.subtitle {
  font-size: 0.85rem;
  opacity: 0.85;
  margin-top: 0.3rem;
}

/* ========== MAIN ========== */
main {
  max-width: 1000px;
  margin: 0 auto;
  padding: 1rem;
}

/* ========== AD UNIT ========== */
.ad-unit {
  margin: 1.25rem 0;
}

/* ========== TOOL SECTION ========== */
.tool-section {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* ========== PANEL ========== */
.panel {
  background: #fff;
  border-radius: 10px;
  padding: 1.25rem;
  box-shadow: 0 1px 6px rgba(0,0,0,0.08);
}

.panel h2 {
  font-size: 1rem;
  font-weight: 700;
  color: #1a237e;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid #e8ecf0;
}

.panel h3 {
  font-size: 0.9rem;
  font-weight: 700;
  color: #444;
  margin: 1rem 0 0.5rem;
}

/* ========== PRESET SELECT ========== */
.preset-row {
  margin-bottom: 0.75rem;
}

.preset-row label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
  color: #555;
}

select {
  width: 100%;
  padding: 0.6rem 0.75rem;
  font-size: 0.95rem;
  border: 1px solid #ccc;
  border-radius: 6px;
  background: #fff;
  min-height: 44px;
}

/* ========== FUNCTION LIST ========== */
.function-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.func-entry {
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  padding: 0.75rem;
  background: #fafafa;
}

.func-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
}

.func-color-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
}

.func-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: #444;
  flex: 1;
}

.func-visible-toggle {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.8rem;
  color: #666;
  cursor: pointer;
  min-height: 44px;
  padding: 0 0.25rem;
}

.func-visible-toggle input {
  width: auto;
  margin: 0;
  cursor: pointer;
  min-height: auto;
}

.func-remove-btn {
  background: none;
  border: 1px solid #ccc;
  border-radius: 4px;
  padding: 0.25rem 0.6rem;
  font-size: 0.8rem;
  cursor: pointer;
  color: #888;
  min-height: 44px;
  transition: border-color 0.2s, color 0.2s;
}

.func-remove-btn:not([disabled]):hover {
  border-color: #e74c3c;
  color: #e74c3c;
}

.func-remove-btn[disabled] {
  opacity: 0.3;
  cursor: not-allowed;
}

.func-expr-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.func-expr-row label {
  font-size: 0.9rem;
  font-weight: 600;
  color: #555;
  white-space: nowrap;
  min-width: 2rem;
}

.func-expr {
  flex: 1;
  padding: 0.5rem 0.75rem;
  font-size: 0.95rem;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-family: "Courier New", monospace;
  min-height: 44px;
  min-width: 0;
}

.func-expr.error {
  border-color: #e74c3c;
  background: #fff5f5;
}

.func-error {
  font-size: 0.78rem;
  color: #e74c3c;
  width: 100%;
  padding-left: 2.5rem;
}

/* ========== BUTTONS ========== */
.btn-secondary {
  display: block;
  width: 100%;
  padding: 0.6rem 1rem;
  font-size: 0.9rem;
  font-weight: 600;
  background: #fff;
  color: #1a237e;
  border: 2px solid #1a237e;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
  min-height: 44px;
}

.btn-secondary:hover {
  background: #1a237e;
  color: #fff;
}

.btn-ghost {
  display: block;
  width: 100%;
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  font-weight: 600;
  background: #f0f2f8;
  color: #1a237e;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s;
  min-height: 44px;
  margin-top: 0.5rem;
}

.btn-ghost:hover {
  background: #dce0f0;
}

/* ========== SLIDER GROUP ========== */
.slider-group {
  margin-top: 1rem;
}

.slider-row {
  margin-bottom: 0.75rem;
}

.slider-row label {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  font-weight: 600;
  color: #555;
  margin-bottom: 0.25rem;
  font-family: "Courier New", monospace;
}

input[type="range"] {
  width: 100%;
  height: 6px;
  cursor: pointer;
  accent-color: #1a237e;
  min-height: 44px;
  padding: 0;
  border: none;
}

/* ========== RANGE GROUP ========== */
.range-group {
  margin-top: 1rem;
}

.range-row {
  display: grid;
  grid-template-columns: auto 1fr auto 1fr;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.5rem;
}

.range-row label {
  font-size: 0.85rem;
  font-weight: 600;
  color: #555;
  white-space: nowrap;
}

.range-row input[type="number"] {
  padding: 0.4rem 0.5rem;
  font-size: 0.9rem;
  border: 1px solid #ccc;
  border-radius: 6px;
  min-height: 44px;
  text-align: center;
  width: 100%;
  min-width: 0;
}

/* ========== CANVAS WRAPPER ========== */
.canvas-wrapper {
  background: #fff;
  border-radius: 10px;
  padding: 1rem;
  box-shadow: 0 1px 6px rgba(0,0,0,0.08);
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

#graph-canvas {
  width: 100%;
  max-width: 100%;
  height: auto;
  border-radius: 6px;
  border: 1px solid #e0e0e0;
  display: block;
  touch-action: none;
  cursor: crosshair;
}

.coord-display {
  font-size: 0.85rem;
  font-family: "Courier New", monospace;
  color: #555;
  background: #f0f2f8;
  padding: 0.3rem 0.75rem;
  border-radius: 4px;
  align-self: flex-end;
}

.btn-download {
  display: block;
  padding: 0.6rem 1.5rem;
  font-size: 0.9rem;
  font-weight: 700;
  background: #1a237e;
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s;
  min-height: 44px;
}

.btn-download:hover {
  background: #283593;
}

/* ========== HOWTO SECTION ========== */
.howto-section {
  margin-top: 1.5rem;
  background: #fff;
  border-radius: 10px;
  padding: 1.5rem;
  box-shadow: 0 1px 6px rgba(0,0,0,0.08);
}

.howto-section h2 {
  font-size: 1rem;
  font-weight: 700;
  color: #1a237e;
  margin-top: 1.5rem;
  margin-bottom: 0.75rem;
  padding-bottom: 0.4rem;
  border-bottom: 2px solid #e8ecf0;
}

.howto-section h2:first-child {
  margin-top: 0;
}

.howto-section ol {
  padding-left: 1.25rem;
  color: #555;
  font-size: 0.93rem;
}

.howto-section li {
  margin-bottom: 0.5rem;
  line-height: 1.7;
}

.howto-section p {
  font-size: 0.93rem;
  color: #555;
  line-height: 1.8;
}

.howto-section code {
  background: #f0f2f8;
  padding: 0.1em 0.4em;
  border-radius: 3px;
  font-family: "Courier New", monospace;
  font-size: 0.88em;
  color: #1a237e;
}

/* ========== SYNTAX TABLE ========== */
.syntax-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.syntax-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  color: #444;
}

.syntax-table th,
.syntax-table td {
  padding: 0.5rem 0.75rem;
  border: 1px solid #e0e0e0;
  text-align: left;
  vertical-align: top;
}

.syntax-table th {
  background: #f0f2f8;
  font-weight: 700;
  color: #1a237e;
}

.syntax-table td:first-child {
  font-family: "Courier New", monospace;
  white-space: nowrap;
}

.syntax-table tr:hover td {
  background: #fafbff;
}

/* ========== FOOTER ========== */
footer {
  text-align: center;
  padding: 2rem 1rem;
  font-size: 0.85rem;
  color: #888;
}

footer a {
  color: #666;
  text-decoration: none;
  margin: 0 0.25rem;
}

footer a:hover {
  text-decoration: underline;
}

footer p + p {
  margin-top: 0.5rem;
}

/* ========== DESKTOP LAYOUT ========== */
@media (min-width: 768px) {
  header h1 {
    font-size: 1.6rem;
  }

  .subtitle {
    font-size: 0.95rem;
  }

  main {
    padding: 1.5rem 2rem;
  }

  .tool-section {
    flex-direction: row;
    align-items: flex-start;
  }

  .function-panel {
    width: 340px;
    flex-shrink: 0;
  }

  .canvas-wrapper {
    flex: 1;
    min-width: 0;
  }

  .panel h2 {
    font-size: 1.05rem;
  }
}

@media (min-width: 1024px) {
  .function-panel {
    width: 380px;
  }
}
